summaryrefslogtreecommitdiff
path: root/unsorted/evas/evas_mono_text.cs
blob: 54bd3fde03bd0c5917839a23bf365bd32d9d764f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Linq;
using System.Collections.Generic;

static class Extensions
{
    public static IEnumerable<T> Circle<T>(this IEnumerable<T> list, int index=0)
    {
        var count = list.Count();
        index = index % count;

        while (true) {
            yield return list.ElementAt(index);
            index = (index + 1) % count;
        }
    }
}

class TestMain
{
    static int WIDTH = 320;
    static int HEIGHT = 240;

    private EcoreEvas ecore_evas;
    private Efl.Canvas.Object canvas;
    private Efl.Canvas.Rectangle bg;
    private evas.Text text;
    private evas.Image border;

    public TestMain(String border_file) {
        ecore_evas = new EcoreEvas();
        Eina.Size2D size = new Eina.Size2D();
        Eina.Position2D position = new Eina.Position2D();
        canvas = ecore_evas.canvas;
        canvas.SetVisible(true);

        bg = new Efl.Canvas.Rectangle(canvas);
        bg.SetColor(255, 255, 255, 255);
        position.X = 0;
        position.Y = 0;
        bg.SetPosition(position);
        size.W = WIDTH;
        size.H = HEIGHT;
        bg.SetSize(size);
        bg.SetVisible(true);
        bg.SetKeyFocus(true);

        bg.KeyDownEvent += On_KeyDown;

        text = new evas.Text(canvas);
        text.SetStyle(evas.Text_Style_Type.OutlineSoftShadow);

        text.SetColor(0, 0, 0, 255);
        text.SetGlowColor(255, 0, 0, 255);
        text.SetOutlineColor(0, 0, 255, 255);
        text.SetShadowColor(0, 255,255, 255);
        text.SetFont("Courier", 30);

        text.SetText("sample text");
        size.W = 3*WIDTH / 4;
        size.H = HEIGHT / 4;
        text.SetSize(size);
        position.X = WIDTH / 8;
        position.Y = 3 * HEIGHT / 8;
        text.SetPosition(position);
        text.SetVisible(true);

        Efl.font.Size font_size = 0;
        String font = String.Empty;
        text.GetFont(out font, out font_size);
        Console.WriteLine("Adding text object with font {0} and size {1}", font, size);

        // setup border
        border = new evas.Image(canvas);
        border.SetFile(border_file, null);
        border.SetBorder(3, 3, 3, 3);
        border.SetBorderCenterFill(0);

        size.W = 3 * WIDTH / 4 + 3;
        size.H = HEIGHT / 4 + 3;
        border.SetSize(size);
        position.X = WIDTH / 8 - 3;
        position.Y = 3 * HEIGHT / 8 - 3;
        border.SetPosition(position);
        border.SetVisible(true);


    }

    private void On_KeyDown(object sender, Efl.Input.Interface.KeyDownEventArgs e)
    {
        var key = e.arg.GetKey();

        if (key == "h") {
            Console.WriteLine(commands);
        } else if (key == "t") {
            evas.Text_Style_Type type = text.GetStyle();
            type = (evas.Text_Style_Type)(((int)type + 1) % 10); // 10 hardcoded from C example
            text.SetStyle(type);
        }
    }

    static string commands = @"commands are:
          t - change text's current style
          h - print help";


    static void Main(string[] args)
    {
        Efl.All.Init();

        String border_path = "./src/examples/evas/resources/images/red.png";

        if (args.Length >= 1)
            border_path = args[0];

        Efl.Loop loop = new Efl.Loop();
        TestMain t = new TestMain(border_path);

        loop.Begin();

        Efl.All.Shutdown();
    }
}