summaryrefslogtreecommitdiff
path: root/src/examples/evas
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-11-23 22:01:25 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2017-12-04 15:47:51 -0300
commit41c073b2e61e8c0562cbdf25bdad8a3133275f81 (patch)
treee53a7d237b1eb840457b8ce1c5e056eaceb6f51e /src/examples/evas
parent8b1a72e972a3396c51a16654bc05c3a23ad6afc0 (diff)
efl_mono: Add examples code.
Buildsystem support will be enabled in a future commit
Diffstat (limited to 'src/examples/evas')
-rw-r--r--src/examples/evas/evas_mono_box.cs73
-rw-r--r--src/examples/evas/evas_mono_image.cs93
-rw-r--r--src/examples/evas/evas_mono_image2.cs83
-rw-r--r--src/examples/evas/evas_mono_rectangle.cs47
-rw-r--r--src/examples/evas/evas_mono_table.cs77
-rw-r--r--src/examples/evas/evas_mono_text.cs126
6 files changed, 499 insertions, 0 deletions
diff --git a/src/examples/evas/evas_mono_box.cs b/src/examples/evas/evas_mono_box.cs
new file mode 100644
index 0000000000..cdc4b8b150
--- /dev/null
+++ b/src/examples/evas/evas_mono_box.cs
@@ -0,0 +1,73 @@
1using System;
2using System.Runtime.InteropServices;
3using System.Runtime.CompilerServices;
4
5public class MyBox : evas.BoxInherit
6{
7 public MyBox(efl.Object parent) : base(parent) {}
8
9 [DllImport("evas")] static extern void evas_obj_box_layout_vertical(IntPtr obj, IntPtr data, IntPtr privdata);
10 [DllImport("evas")] static extern void evas_obj_box_layout_horizontal(IntPtr obj, IntPtr data, IntPtr privdata);
11 [DllImport("evas")] static extern void evas_object_box_layout_horizontal(IntPtr obj, IntPtr data, IntPtr privdata);
12 [DllImport("evas")] static extern IntPtr evas_object_evas_get(IntPtr obj);
13 [DllImport("evas")] static extern void evas_event_freeze(IntPtr obj);
14 [DllImport("evas")] static extern void evas_event_thaw(IntPtr obj);
15
16 override public void CalculateGroup()
17 {
18 IntPtr evas = evas_object_evas_get(raw_handle);
19 evas_event_freeze(evas);
20 Console.WriteLine("called group_calculate");
21 /* layouting_set(true); */
22 evas_obj_box_layout_vertical(raw_handle, IntPtr.Zero, IntPtr.Zero);
23 /* layouting_set(false); */
24 /* children_changed_set(false); */
25 evas_event_thaw(evas);
26 }
27}
28
29class TestMain
30{
31 static void Main(string[] args)
32 {
33 efl.All.Init();
34
35 efl.Loop loop = new efl.LoopConcrete();
36
37
38 EcoreEvas ecore_evas = new EcoreEvas();
39
40 efl.canvas.Object canvas = ecore_evas.canvas;
41 canvas.SetVisible(true);
42
43 efl.Object parent = canvas.GetParent();
44 System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero);
45
46 evas.Box box = new MyBox(canvas);
47 eina.Size2D size = new eina.Size2D();
48
49 size.W = 320;
50 size.H = 240;
51
52 box.SetSize(size);
53 box.SetVisible(true);
54
55 efl.canvas.Rectangle rect = new efl.canvas.RectangleConcrete(canvas);
56 rect.SetColor(0, 0, 255, 255);
57 size.W = 320;
58 size.H = 120;
59 rect.SetSize(size);
60 rect.SetVisible(true);
61 box.Append(rect);
62
63 efl.canvas.Rectangle rect2 = new efl.canvas.RectangleConcrete(canvas);
64 rect2.SetColor(0, 255, 0, 255);
65 rect2.SetSize(size);
66 rect2.SetVisible(true);
67 box.Append(rect2);
68
69 loop.Begin();
70
71 efl.All.Shutdown();
72 }
73}
diff --git a/src/examples/evas/evas_mono_image.cs b/src/examples/evas/evas_mono_image.cs
new file mode 100644
index 0000000000..ff84db5d9a
--- /dev/null
+++ b/src/examples/evas/evas_mono_image.cs
@@ -0,0 +1,93 @@
1using System;
2using System.Runtime.CompilerServices;
3
4class TestMain
5{
6 static int WIDTH = 320;
7 static int HEIGHT = 240;
8
9 evas.Image image;
10
11
12 static string ImagePath([CallerFilePath] string folder="")
13 {
14 return System.IO.Path.GetDirectoryName(folder);
15 }
16
17 public TestMain(evas.Image image)
18 {
19 this.image = image;
20 }
21
22 static void Main(string[] args)
23 {
24 efl.All.Init();
25
26 efl.Loop loop = new efl.LoopConcrete();
27
28 EcoreEvas ecore_evas = new EcoreEvas();
29 eina.Size2D size = new eina.Size2D();
30
31 efl.canvas.Object canvas = ecore_evas.canvas;
32 canvas.SetVisible(true);
33
34 efl.Object parent = canvas.GetParent();
35 System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero);
36
37 efl.canvas.Rectangle bg = new efl.canvas.RectangleConcrete(canvas);
38 bg.SetColor(255, 255, 255, 255);
39 size.W = WIDTH;
40 size.H = HEIGHT;
41 bg.SetSize(size);
42 bg.SetVisible(true);
43
44 string valid_path = args[0];
45 evas.Image image = new evas.ImageConcrete(canvas);
46 image.SetFile(valid_path, null);
47
48 /* FIXME evas-image uses error handling code from
49 * evas_object_image_load_error_get, which seems to be not available
50 * efl.image.load.State state = image.load_error_get(); */
51
52 // FIXME missing move
53 eina.Rect rect = new eina.Rect();
54
55 rect.X = 0;
56 rect.Y = 0;
57 rect.W = WIDTH / 2;
58 rect.H = HEIGHT / 2;
59 image.SetFill(rect);
60
61 size.W = WIDTH / 2;
62 size.H = HEIGHT / 2;
63 image.SetSize(size);
64 image.SetVisible(true);
65
66 rect = image.GetFill();
67 rect.Y -= 50;
68 rect.W += 100;
69 image.SetFill(rect);
70
71 TestMain listener = new TestMain(image);
72
73 // TODO handle key events in order to alter the image like the C
74 // example. Meanwhile, just set some w fill
75 /* EventListener callback = new EventListener(); */
76
77 /* bg.key_focus_set(true); */
78 /* bg.event_callback_priority_add(evas.Callback_Type.Key_down, */
79 /* efl.Callback_Priority.Default, */
80 /* callback, null); */
81
82 loop.Begin();
83
84 efl.All.Shutdown();
85 }
86
87 public void on_key_down(object sender, EventArgs e)
88 {
89 Console.WriteLine("on_key_down called");
90 }
91}
92
93
diff --git a/src/examples/evas/evas_mono_image2.cs b/src/examples/evas/evas_mono_image2.cs
new file mode 100644
index 0000000000..e2ae49f092
--- /dev/null
+++ b/src/examples/evas/evas_mono_image2.cs
@@ -0,0 +1,83 @@
1using System;
2using System.Runtime.InteropServices;
3using System.Runtime.CompilerServices;
4
5class TestMain
6{
7 static int WIDTH = 320;
8 static int HEIGHT = 240;
9
10
11 static void Main(string[] args)
12 {
13 efl.All.Init();
14
15 efl.Loop loop = new efl.LoopConcrete();
16
17 EcoreEvas ecore_evas = new EcoreEvas();
18
19 eina.Size2D size = new eina.Size2D();
20 eina.Position2D pos = new eina.Position2D();
21
22 efl.canvas.Object canvas = ecore_evas.canvas;
23 canvas.SetVisible(true);
24
25 efl.canvas.Rectangle bg = new efl.canvas.RectangleConcrete(canvas);
26 bg.SetColor(255, 255, 255, 255);
27 pos.X = 0;
28 pos.Y = 0;
29 bg.SetPosition(pos);
30 size.W = WIDTH;
31 size.H = HEIGHT;
32 bg.SetSize(size);
33 bg.SetVisible(true);
34
35 string path = args[0];
36 evas.Image logo = new evas.ImageConcrete(canvas);
37 logo.SetFillAuto(true);
38
39 // TODO add preloaded support (depends on events)
40
41 logo.SetFile(path, null);
42 size.W = WIDTH / 2;
43 size.H = HEIGHT / 2;
44 logo.SetSize(size);
45
46 // TODO add a bunch of key/mouse handlers
47
48 logo.SetVisible(true);
49
50 int[] pixels = new int[(WIDTH/4) * (HEIGHT / 4)];
51 System.Random generator = new System.Random();
52 for (int i = 0; i < pixels.Length; i++) {
53 pixels[i] = generator.Next();
54 }
55
56 evas.Image noise_img = new evas.ImageConcrete(canvas);
57 size.W = WIDTH / 4;
58 size.H = HEIGHT / 4;
59 noise_img.SetSize(size);
60 // FIXME Add a way to set the pixels.
61 // noise_img.data_set(pixels);
62 noise_img.SetFillAuto(true);
63 pos.X = WIDTH * 5 / 8;
64 pos.Y = HEIGHT / 8;
65 noise_img.SetPosition(pos);
66 noise_img.SetVisible(true);
67 Console.WriteLine("Creating noise image with sizez %d, %d", WIDTH/4, HEIGHT/4);
68
69 efl.canvas.Proxy proxy_img = new efl.canvas.ProxyConcrete(canvas);
70 proxy_img.SetSource(noise_img);
71 pos.X = WIDTH / 2;
72 pos.Y = HEIGHT / 2;
73 proxy_img.SetPosition(pos);
74 size.W = WIDTH / 2;
75 size.H = HEIGHT / 2;
76 proxy_img.SetSize(size);
77 proxy_img.SetVisible(true);
78
79 loop.Begin();
80 }
81}
82
83
diff --git a/src/examples/evas/evas_mono_rectangle.cs b/src/examples/evas/evas_mono_rectangle.cs
new file mode 100644
index 0000000000..de686b0609
--- /dev/null
+++ b/src/examples/evas/evas_mono_rectangle.cs
@@ -0,0 +1,47 @@
1using System;
2
3class TestMain
4{
5 private static int[,] colors = new int[,] {
6 {255, 0, 0},
7 {0, 255, 0},
8 {0, 0, 255}
9 };
10
11 static void Main(string[] args)
12 {
13 int color_index = 0;
14
15 efl.All.Init();
16
17 efl.Loop loop = new efl.LoopConcrete();
18 EcoreEvas ecore_evas = new EcoreEvas();
19 efl.canvas.Object canvas = ecore_evas.canvas;
20 canvas.SetVisible(true);
21
22 efl.Object parent = canvas.GetParent();
23 System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero);
24
25 efl.canvas.Rectangle rect = new efl.canvas.RectangleConcrete(canvas);
26 rect.SetColor(colors[0, 0], colors[0, 1], colors[0, 2], 255);
27 eina.Size2D size = new eina.Size2D();
28 size.W = 640;
29 size.H = 480;
30 rect.SetSize(size);
31 rect.SetVisible(true);
32
33 canvas.KEY_DOWN += (object sender, efl.input.KEY_DOWN_Args e) => {
34 color_index = (color_index + 1) % 3;
35 Console.WriteLine("Key Down");
36 Console.WriteLine("Got key obj at {0}", e.arg.raw_handle.ToString("X"));
37 Console.WriteLine("Got key_get() == [{0}]", e.arg.GetKey());
38 rect.SetColor(colors[color_index, 0],
39 colors[color_index, 1],
40 colors[color_index, 2], 255);
41 };
42
43 loop.Begin();
44
45 efl.All.Shutdown();
46 }
47}
diff --git a/src/examples/evas/evas_mono_table.cs b/src/examples/evas/evas_mono_table.cs
new file mode 100644
index 0000000000..e79ad7c956
--- /dev/null
+++ b/src/examples/evas/evas_mono_table.cs
@@ -0,0 +1,77 @@
1using System;
2using System.Runtime.InteropServices;
3using System.Runtime.CompilerServices;
4
5class TestMain
6{
7 static int WIDTH = 100;
8 static int HEIGHT = 150;
9
10 static void Main(string[] args)
11 {
12 efl.All.Init();
13
14 efl.Loop loop = new efl.LoopConcrete();
15
16 EcoreEvas ecore_evas = new EcoreEvas();
17
18 eina.Size2D size = new eina.Size2D();
19 size.W = WIDTH;
20 size.H = HEIGHT;
21
22 eina.Size2D hint = new eina.Size2D();
23
24 efl.canvas.Object canvas = ecore_evas.canvas;
25 canvas.SetVisible(true);
26
27 efl.Object parent = canvas.GetParent();
28 System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero);
29
30 efl.canvas.Rectangle bg = new efl.canvas.RectangleConcrete(canvas);
31 bg.SetColor(255, 255, 255, 255);
32 bg.SetSize(size);
33 bg.SetVisible(true);
34
35
36 evas.Table table = new evas.TableConcrete(canvas);
37 table.SetHomogeneous(evas.object_table.Homogeneous_Mode.None);
38 table.SetPadding(0, 0);
39 table.SetSize(size);
40 table.SetVisible(true);
41
42 efl.canvas.Rectangle rect = new efl.canvas.RectangleConcrete(canvas);
43 rect.SetColor(255, 0, 0, 255);
44 hint.W = 100;
45 hint.H = 50;
46 rect.SetHintMin(hint);
47 rect.SetVisible(true);
48 table.Pack(rect, 1, 1, 2, 1);
49
50 rect = new efl.canvas.RectangleConcrete(canvas);
51 rect.SetColor(0, 255, 0, 255);
52 hint.W = 50;
53 hint.H = 100;
54 rect.SetHintMin(hint);
55 rect.SetVisible(true);
56 table.Pack(rect, 1, 2, 1, 2);
57
58 rect = new efl.canvas.RectangleConcrete(canvas);
59 rect.SetColor(0, 0, 255, 255);
60 hint.W = 50;
61 hint.H = 50;
62 rect.SetHintMin(hint);
63 rect.SetVisible(true);
64 table.Pack(rect, 2, 2, 1, 1);
65
66 rect = new efl.canvas.RectangleConcrete(canvas);
67 rect.SetColor(255, 255, 0, 255);
68 rect.SetHintMin(hint);
69 rect.SetVisible(true);
70 table.Pack(rect, 2, 3, 1, 1);
71
72 loop.Begin();
73
74 efl.All.Shutdown();
75 }
76}
77
diff --git a/src/examples/evas/evas_mono_text.cs b/src/examples/evas/evas_mono_text.cs
new file mode 100644
index 0000000000..071cba218b
--- /dev/null
+++ b/src/examples/evas/evas_mono_text.cs
@@ -0,0 +1,126 @@
1using System;
2using System.Linq;
3using System.Collections.Generic;
4
5static class Extensions
6{
7 public static IEnumerable<T> Circle<T>(this IEnumerable<T> list, int index=0)
8 {
9 var count = list.Count();
10 index = index % count;
11
12 while (true) {
13 yield return list.ElementAt(index);
14 index = (index + 1) % count;
15 }
16 }
17}
18
19class TestMain
20{
21 static int WIDTH = 320;
22 static int HEIGHT = 240;
23
24 private EcoreEvas ecore_evas;
25 private efl.canvas.Object canvas;
26 private efl.canvas.Rectangle bg;
27 private evas.Text text;
28 private evas.Image border;
29
30 public TestMain(String border_file) {
31 ecore_evas = new EcoreEvas();
32 eina.Size2D size = new eina.Size2D();
33 eina.Position2D position = new eina.Position2D();
34 canvas = ecore_evas.canvas;
35 canvas.SetVisible(true);
36
37 bg = new efl.canvas.RectangleConcrete(canvas);
38 bg.SetColor(255, 255, 255, 255);
39 position.X = 0;
40 position.Y = 0;
41 bg.SetPosition(position);
42 size.W = WIDTH;
43 size.H = HEIGHT;
44 bg.SetSize(size);
45 bg.SetVisible(true);
46 bg.SetKeyFocus(true);
47
48 bg.KEY_DOWN += On_KeyDown;
49
50 text = new evas.TextConcrete(canvas);
51 text.SetStyle(evas.Text_Style_Type.OutlineSoftShadow);
52
53 text.SetColor(0, 0, 0, 255);
54 text.SetGlowColor(255, 0, 0, 255);
55 text.SetOutlineColor(0, 0, 255, 255);
56 text.SetShadowColor(0, 255,255, 255);
57 text.SetFont("Courier", 30);
58
59 text.SetText("sample text");
60 size.W = 3*WIDTH / 4;
61 size.H = HEIGHT / 4;
62 text.SetSize(size);
63 position.X = WIDTH / 8;
64 position.Y = 3 * HEIGHT / 8;
65 text.SetPosition(position);
66 text.SetVisible(true);
67
68 efl.font.Size font_size = 0;
69 String font = String.Empty;
70 text.GetFont(out font, out font_size);
71 Console.WriteLine("Adding text object with font {0} and size {1}", font, size);
72
73 // setup border
74 border = new evas.ImageConcrete(canvas);
75 border.SetFile(border_file, null);
76 border.SetBorder(3, 3, 3, 3);
77 border.SetBorderCenterFill(0);
78
79 size.W = 3 * WIDTH / 4 + 3;
80 size.H = HEIGHT / 4 + 3;
81 border.SetSize(size);
82 position.X = WIDTH / 8 - 3;
83 position.Y = 3 * HEIGHT / 8 - 3;
84 border.SetPosition(position);
85 border.SetVisible(true);
86
87
88 }
89
90 private void On_KeyDown(object sender, efl.input.KEY_DOWN_Args e)
91 {
92 var key = e.arg.GetKey();
93
94 if (key == "h") {
95 Console.WriteLine(commands);
96 } else if (key == "t") {
97 evas.Text_Style_Type type = text.GetStyle();
98 type = (evas.Text_Style_Type)(((int)type + 1) % 10); // 10 hardcoded from C example
99 text.SetStyle(type);
100 }
101 }
102
103 static string commands = @"commands are:
104 t - change text's current style
105 h - print help";
106
107
108 static void Main(string[] args)
109 {
110 efl.All.Init();
111
112 String border_path = "./src/examples/evas/resources/images/red.png";
113
114 if (args.Length >= 1)
115 border_path = args[0];
116
117 efl.Loop loop = new efl.LoopConcrete();
118 TestMain t = new TestMain(border_path);
119
120 loop.Begin();
121
122 efl.All.Shutdown();
123 }
124}
125
126