summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-11-23 22:01:25 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-11-29 23:05:59 -0200
commit1da192290f5785a7b2aabdb81842e970cb62f115 (patch)
tree1737dfd6c43cf9124a57aa9a4eac03671de8ec2a
parent99be2104a36980fd32e84da39c056f5d546dec69 (diff)
efl_mono: Add examples code.
Buildsystem support will be enabled in a future commit
-rw-r--r--src/Makefile.am1
-rw-r--r--src/examples/ecore/efl_loop_callback_add_event.cs43
-rw-r--r--src/examples/ecore/efl_loop_timer_example.cs52
-rw-r--r--src/examples/efl_mono/.gitignore1
-rw-r--r--src/examples/efl_mono/EoInherit01.cs64
-rw-r--r--src/examples/efl_mono/FunctionPointer01.cs45
-rw-r--r--src/examples/efl_mono/Makefile.am123
-rw-r--r--src/examples/efl_mono/example_numberwrapper.c87
-rw-r--r--src/examples/efl_mono/example_numberwrapper.eo30
-rw-r--r--src/examples/eina/EinaArray01.cs41
-rw-r--r--src/examples/eina/EinaBinbuf01.cs65
-rw-r--r--src/examples/eina/EinaError01.cs75
-rw-r--r--src/examples/eina/EinaHash01.cs66
-rw-r--r--src/examples/elementary/efl_ui_slider_mono.cs63
-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
20 files changed, 1255 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2651fd89ab..74ec6cdb2b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -125,6 +125,7 @@ examples/emotion \
125examples/emile \ 125examples/emile \
126examples/elocation \ 126examples/elocation \
127examples/ethumb_client \ 127examples/ethumb_client \
128examples/efl_mono \
128examples/elementary 129examples/elementary
129 130
130if HAVE_ELUA 131if HAVE_ELUA
diff --git a/src/examples/ecore/efl_loop_callback_add_event.cs b/src/examples/ecore/efl_loop_callback_add_event.cs
new file mode 100644
index 0000000000..fe81bfd9ad
--- /dev/null
+++ b/src/examples/ecore/efl_loop_callback_add_event.cs
@@ -0,0 +1,43 @@
1using System;
2using System.Runtime.InteropServices;
3using System.Runtime.CompilerServices;
4
5class TestMain
6{
7 /* private efl.Loop loop; */
8
9 public TestMain(efl.Loop loop)
10 {
11 /* this.loop = loop; */
12 }
13
14 static void Main(string[] args)
15 {
16 efl.All.Init();
17
18 efl.Loop loop = new efl.LoopConcrete();
19
20 TestMain listener = new TestMain(loop);
21
22 loop.CALLBACK_ADD += listener.callback_added_cb;
23
24 loop.CALLBACK_ADD += listener.on_idle_enter;
25 loop.CALLBACK_ADD -= listener.on_idle_enter;
26
27 loop.IDLE += listener.on_idle_enter; // Will trigger CALLBACK_ADD
28
29 efl.All.Shutdown();
30 }
31
32 public void on_idle_enter(object sender, EventArgs e)
33 {
34 Console.WriteLine("I should not be called while the loop is not running...");
35 }
36
37 public void callback_added_cb(object sender, EventArgs e)
38 {
39 Console.WriteLine("Looks like we added a new callback.");
40 }
41}
42
43
diff --git a/src/examples/ecore/efl_loop_timer_example.cs b/src/examples/ecore/efl_loop_timer_example.cs
new file mode 100644
index 0000000000..dd6b2b8606
--- /dev/null
+++ b/src/examples/ecore/efl_loop_timer_example.cs
@@ -0,0 +1,52 @@
1using System;
2using System.Runtime.InteropServices;
3using System.Runtime.CompilerServices;
4
5class TestMain
6{
7 private efl.Loop loop;
8 private int count;
9
10 public TestMain(efl.Loop loop)
11 {
12 this.loop = loop;
13 this.count = 0;
14 }
15
16 static void Main(string[] args)
17 {
18 efl.All.Init();
19
20 efl.Loop loop = new efl.LoopConcrete();
21 efl.loop.Timer timer = new efl.loop.TimerConcrete(loop);
22
23 TestMain listener = new TestMain(loop);
24
25 Console.WriteLine("Starting MainLoop");
26
27 timer.interval_set(1.0);
28
29 timer.TICK += listener.on_tick;
30 timer.TICK += listener.another_callback;
31 timer.TICK -= listener.another_callback;
32
33 loop.begin();
34
35 efl.All.Shutdown();
36 }
37
38 public void on_tick(object sender, EventArgs e)
39 {
40 Console.WriteLine("on_tick called on listener");
41
42 if (count++ == 5)
43 loop.quit(0);
44 }
45
46 public void another_callback(object sender, EventArgs e)
47 {
48 Console.WriteLine("Ooops. Should not have been called...");
49 }
50}
51
52
diff --git a/src/examples/efl_mono/.gitignore b/src/examples/efl_mono/.gitignore
new file mode 100644
index 0000000000..7a426d39c3
--- /dev/null
+++ b/src/examples/efl_mono/.gitignore
@@ -0,0 +1 @@
/example_numberwrapper.out
diff --git a/src/examples/efl_mono/EoInherit01.cs b/src/examples/efl_mono/EoInherit01.cs
new file mode 100644
index 0000000000..6b899aeca1
--- /dev/null
+++ b/src/examples/efl_mono/EoInherit01.cs
@@ -0,0 +1,64 @@
1using static System.Console;
2
3class PlusTenNumberWrapper : example.NumberwrapperInherit
4{
5 public PlusTenNumberWrapper(efl.Object parent = null)
6 : base(parent)
7 {}
8
9 public bool derivedCalled = false;
10
11 override public void SetNumber(int n)
12 {
13 // Call native EFL method
14 base.SetNumber(n + 10);
15 derivedCalled = true;
16 }
17}
18
19public class ExampleEoInherit01
20{
21 public static void Main()
22 {
23 eina.Config.Init();
24 efl.eo.Config.Init();
25
26 var inheritObj = new PlusTenNumberWrapper();
27
28 WriteLine("## Using inherit object ##\n");
29
30 int given = 111;
31
32 // Call the C# override from the C method
33 example.NumberwrapperConcrete.example_numberwrapper_number_set(inheritObj.raw_handle, given);
34
35 WriteLine($"Override successfully called? {inheritObj.derivedCalled}!\n");
36
37 // Call C function from C# object
38 int stored = inheritObj.GetNumber();
39
40 WriteLine($"Given value: {given}");
41 WriteLine($"Stored value: {stored}\n");
42
43 // Call C# override directly
44 given = 333;
45 inheritObj.SetNumber(given);
46
47 stored = inheritObj.GetNumber();
48
49 WriteLine($"Given value: {given}");
50 WriteLine($"Stored value: {stored}\n");
51
52 WriteLine("## Using original object ##\n");
53
54 // Check original EFL object
55 var origObj = new example.NumberwrapperConcrete();
56 given = 111;
57 origObj.SetNumber(given);
58 stored = origObj.GetNumber();
59
60 WriteLine($"Given value: {given}");
61 WriteLine($"Stored value: {stored}\n");
62 }
63}
64
diff --git a/src/examples/efl_mono/FunctionPointer01.cs b/src/examples/efl_mono/FunctionPointer01.cs
new file mode 100644
index 0000000000..2954473a27
--- /dev/null
+++ b/src/examples/efl_mono/FunctionPointer01.cs
@@ -0,0 +1,45 @@
1using static System.Console;
2
3public class ExampleFunctionPointer01
4{
5 private static bool static_called = false;
6
7 private static int twiceCb(int n)
8 {
9 static_called = true;
10 return n * 2;
11 }
12
13 public static void Main()
14 {
15 eina.Config.Init();
16 efl.eo.Config.Init();
17
18 var obj = new example.NumberwrapperConcrete();
19
20 // Set internal value
21 obj.SetNumber(12);
22
23 // With static method
24 obj.SetNumberCallback(twiceCb);
25
26 var ret = obj.CallCallback();
27
28 WriteLine($"Callback called? {static_called}.");
29 WriteLine($"Returned value: {ret}.\n");
30
31 // With lambda
32 bool lamda_called = false;
33
34 obj.SetNumberCallback(n => {
35 lamda_called = true;
36 return n * 3;
37 });
38
39 ret = obj.CallCallback();
40
41 WriteLine($"Lambda called? {lamda_called}.");
42 WriteLine($"Returned value: {ret}.\n");
43 }
44}
45
diff --git a/src/examples/efl_mono/Makefile.am b/src/examples/efl_mono/Makefile.am
new file mode 100644
index 0000000000..6bae1d9ee2
--- /dev/null
+++ b/src/examples/efl_mono/Makefile.am
@@ -0,0 +1,123 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3if HAVE_CSHARP
4
5include $(top_srcdir)/src/Makefile_Eolian_Helper.am
6include $(top_srcdir)/src/Makefile_Eolian_Mono_Helper.am
7include $(top_srcdir)/src/Makefile_Efl_Mono_MSBuild_Gen_Helper.am
8
9SRCS =
10EXTRA_FILES =
11EXTRA_PROGRAMS =
12GENERATED =
13CLEANFILES =
14
15# Simple object used by the examples
16
17EOLIAN_FLAGS := $(EOLIAN_FLAGS)
18EOLIAN_FLAGS += \
19-I$(srcdir) \
20-I$(top_srcdir)/src/lib/eo \
21-I$(top_srcdir)/src/lib/efl
22
23COMMON_FLAGS = \
24@EINA_CFLAGS@ @EINA_LDFLAGS@ \
25-L$(top_builddir)/src/lib/eina/.libs -leina \
26@EO_CFLAGS@ @EO_LDFLAGS@ \
27-L$(top_builddir)/src/lib/eo/.libs -leo \
28@EFL_CFLAGS@ @EFL_LDFLAGS@ \
29-L$(top_builddir)/src/lib/efl/.libs -lefl
30
31if HAVE_WIN32
32COMMON_FLAGS += \
33@EVIL_CFLAGS@ @EVIL_LDFLAGS@ \
34@EFL_WINDOWS_VERSION_CFLAGS@ \
35-L$(top_builddir)/src/lib/evil/.libs -levil
36else
37COMMON_FLAGS += \
38-fPIC -DPIC
39endif
40
41
42%.eo.c: %.eo
43 $(AM_V_EOL)$(EOLIAN_GEN) $(EOLIAN_FLAGS) -gc -o c:$@ $<
44
45%.eo.h: %.eo
46 $(AM_V_EOL)$(EOLIAN_GEN) $(EOLIAN_FLAGS) -gh -o h:$@ $<
47
48example_numberwrapper.c: example_numberwrapper.eo.h example_numberwrapper.eo.c
49
50numberwrapper_lib_name = example_numberwrapper.out
51
52$(numberwrapper_lib_name): example_numberwrapper.c
53 $(CC) -shared -o $@ $< -DEFL_BETA_API_SUPPORT -I. $(COMMON_FLAGS)
54
55SRCS += example_numberwrapper.c
56EXTRA_FILES += example_numberwrapper.eo
57GENERATED += example_numberwrapper.eo.h example_numberwrapper.eo.c $(numberwrapper_lib_name)
58
59# CSharp examples
60
61SRCS += \
62EoInherit01.cs \
63FunctionPointer01.cs
64
65EXTRA_PROGRAMS += \
66EoInherit01.exe \
67FunctionPointer01.exe
68
69example_numberwrapper.eo.cs: example_numberwrapper.eo
70 $(AM_V_EOLMONO) \
71 $(EOLIAN_MONO) $(EOLIAN_FLAGS) $(EOLIAN_MONO_FLAGS) --dllimport $(numberwrapper_lib_name) -o $@ -r $(top_builddir)/src/bindings/mono/efl_mono/efl_libs.csv $<
72
73EoInherit01_exe_SOURCES = EoInherit01.cs
74EoInherit01_srcs = $(EoInherit01_exe_SOURCES) example_numberwrapper.eo.cs
75EoInherit01.exe$(EXEEXT): $(EoInherit01_srcs) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) $(numberwrapper_lib_name)
76 @rm -f $@
77 $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) -out:$@ $(filter %.cs, $(^))
78
79$(abs_top_builddir)/EoInherit01.csproj: $(EoInherit01_srcs) $(am_dirstamp) $(numberwrapper_lib_name)
80 @rm -f $@
81 $(EFL_MONO_MSBUILD_GEN) $(MSBUILD_GEN_FLAGS) -o $@ -a EoInherit01.exe -r libefl_mono.dll -t exe $(patsubst %.cs,src/examples/efl_mono/%.cs,$(filter %.cs, $(^)))
82
83
84FunctionPointer01_exe_SOURCES = FunctionPointer01.cs
85FunctionPointer01_srcs = $(FunctionPointer01_exe_SOURCES) example_numberwrapper.eo.cs
86FunctionPointer01.exe$(EXEEXT): $(FunctionPointer01_srcs) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) $(numberwrapper_lib_name)
87 @rm -f $@
88 $(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) -out:$@ $(filter %.cs, $(^))
89
90$(abs_top_builddir)/FunctionPointer01.csproj: $(FunctionPointer01_srcs) $(am_dirstamp) $(numberwrapper_lib_name)
91 @rm -f $@
92 $(EFL_MONO_MSBUILD_GEN) $(MSBUILD_GEN_FLAGS) -o $@ -a FunctionPointer01.exe -r libefl_mono.dll -t exe $(patsubst %.cs,src/examples/efl_mono/%.cs,$(filter %.cs, $(^)))
93
94msbuildcsprojs: $(abs_top_builddir)/EoInherit01.csproj $(abs_top_builddir)/FunctionPointer01.csproj
95
96GENERATED += example_numberwrapper.eo.cs
97
98
99# Finishing
100
101EXTRA_DIST = $(EXTRA_FILES)
102
103CLEANFILES += $(GENERATED)
104
105examples: $(EXTRA_PROGRAMS)
106
107clean-local:
108 rm -f $(EXTRA_PROGRAMS) $(GENERATED)
109
110install-examples:
111 $(MKDIR_P) $(DESTDIR)$(datadir)/efl_mono/examples
112 cd $(srcdir) && $(install_sh_DATA) -c $(SRCS) $(EXTRA_FILES) $(DESTDIR)$(datadir)/efl_mono/examples
113
114uninstall-local:
115 for f in $(SRCS) $(EXTRA_FILES); do \
116 rm -f $(DESTDIR)$(datadir)/efl_mono/examples/$$f ; \
117 done
118
119if ALWAYS_BUILD_EXAMPLES
120noinst_PROGRAMS = $(EXTRA_PROGRAMS)
121endif
122
123endif
diff --git a/src/examples/efl_mono/example_numberwrapper.c b/src/examples/efl_mono/example_numberwrapper.c
new file mode 100644
index 0000000000..f80dee616a
--- /dev/null
+++ b/src/examples/efl_mono/example_numberwrapper.c
@@ -0,0 +1,87 @@
1
2#ifdef HAVE_CONFIG_H
3#include "config.h"
4#endif
5
6#include <Eo.h>
7
8#undef EOAPI
9#undef EAPI
10#define EOAPI EAPI EAPI_WEAK
11
12#ifdef _WIN32
13# ifdef EFL_EO_BUILD
14# ifdef DLL_EXPORT
15# define EAPI __declspec(dllexport)
16# else
17# define EAPI
18# endif /* ! DLL_EXPORT */
19# else
20# define EAPI __declspec(dllimport)
21# endif /* ! EFL_EO_BUILD */
22#else
23# ifdef __GNUC__
24# if __GNUC__ >= 4
25# define EAPI __attribute__ ((visibility("default")))
26# else
27# define EAPI
28# endif
29# else
30# define EAPI
31# endif
32#endif /* ! _WIN32 */
33
34#include "example_numberwrapper.eo.h"
35
36
37typedef struct Example_Numberwrapper_Data
38{
39 int number;
40 NumberCb cb;
41 void *cb_data;
42 Eina_Free_Cb free_cb;
43} Example_Numberwrapper_Data;
44
45// ##################### //
46// Example.Numberwrapper //
47// ##################### //
48
49
50void _example_numberwrapper_number_set(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd, int n)
51{
52 pd->number = n;
53}
54
55int _example_numberwrapper_number_get(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd)
56{
57 return pd->number;
58}
59
60
61void _example_numberwrapper_number_callback_set(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd, void *cb_data, NumberCb cb, Eina_Free_Cb cb_free_cb)
62{
63 if (pd->free_cb)
64 pd->free_cb(pd->cb_data);
65
66 pd->cb = cb;
67 pd->cb_data = cb_data;
68 pd->free_cb = cb_free_cb;
69}
70
71
72int _example_numberwrapper_callback_call(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd)
73{
74 if (!pd->cb)
75 {
76 static Eina_Error no_cb_err = 0;
77 if (!no_cb_err)
78 no_cb_err = eina_error_msg_static_register("Trying to call with no callback set");
79 eina_error_set(no_cb_err);
80 return -1;
81 }
82
83 return pd->cb(pd->cb_data, pd->number);
84}
85
86#include "example_numberwrapper.eo.c"
87
diff --git a/src/examples/efl_mono/example_numberwrapper.eo b/src/examples/efl_mono/example_numberwrapper.eo
new file mode 100644
index 0000000000..85f2ce4a4d
--- /dev/null
+++ b/src/examples/efl_mono/example_numberwrapper.eo
@@ -0,0 +1,30 @@
1function NumberCb {
2 params {
3 n: int;
4 }
5 return: int;
6};
7
8class Example.Numberwrapper (Efl.Object) {
9 methods {
10 @property number {
11 get {
12 }
13 set {
14 }
15 values {
16 n: int;
17 }
18 }
19
20 number_callback_set {
21 params {
22 cb: NumberCb;
23 }
24 }
25
26 callback_call {
27 return: int;
28 }
29 }
30}
diff --git a/src/examples/eina/EinaArray01.cs b/src/examples/eina/EinaArray01.cs
new file mode 100644
index 0000000000..4ac4a77812
--- /dev/null
+++ b/src/examples/eina/EinaArray01.cs
@@ -0,0 +1,41 @@
1using static System.Console;
2
3public class ExampleEinaArray01
4{
5 public static void Main()
6 {
7 eina.Config.Init();
8
9 var strings = new string[]{
10 "helo", "hera", "starbuck", "kat", "boomer",
11 "hotdog", "longshot", "jammer", "crashdown", "hardball",
12 "duck", "racetrack", "apolo", "husker", "freaker",
13 "skulls", "bulldog", "flat top", "hammerhead", "gonzo"
14 };
15
16 var array = new eina.Array<string>(20U);
17
18 // Push new elements
19 foreach (string s in strings)
20 {
21 WriteLine("push: " + s);
22 array.Push(s);
23 }
24
25 // Check count
26 WriteLine("array count: " + array.Count());
27
28 // Iterate over the array
29 int idx = 0;
30 foreach (string s in array)
31 {
32 WriteLine($"at[{idx}]: {s}");
33 ++idx;
34 }
35
36 // Remove one by one
37 while (array.Length != 0)
38 WriteLine("pop: " + array.Pop());
39 }
40}
41
diff --git a/src/examples/eina/EinaBinbuf01.cs b/src/examples/eina/EinaBinbuf01.cs
new file mode 100644
index 0000000000..395616879d
--- /dev/null
+++ b/src/examples/eina/EinaBinbuf01.cs
@@ -0,0 +1,65 @@
1using static System.Console;
2
3public class ExampleEinaBinbuf01
4{
5 public static void Main()
6 {
7 eina.Config.Init();
8
9 var bytes = new byte[]{0, 1, 2, 3, 4, 5, 6};
10
11 var bb = new eina.Binbuf();
12
13 // Append initial bytes
14 bb.Append(bytes);
15
16 WriteLine("Printing each byte.");
17
18 int idx = 0;
19 foreach (byte b in bb.GetBytes())
20 {
21 WriteLine($"byte at[{idx}]: {b}");
22 ++idx;
23 }
24
25 // Append more byte by byte
26 bb.Append((byte) 7);
27 bb.Append((byte) 8);
28 bb.Append((byte) 9);
29 bb.Append((byte) 0);
30
31 WriteLine("\nPrinting each byte.");
32
33 idx = 0;
34 foreach (byte b in bb.GetBytes())
35 {
36 WriteLine($"byte at[{idx}]: {b}");
37 ++idx;
38 }
39
40 // Remove some
41 bb.Remove(2, 5);
42
43 WriteLine("\nPrinting each byte.");
44
45 idx = 0;
46 foreach (byte b in bb.GetBytes())
47 {
48 WriteLine($"byte at[{idx}]: {b}");
49 ++idx;
50 }
51
52 // Insert new bytes in the middle
53 bb.Insert(new byte[]{22, 33, 44}, 2);
54
55 WriteLine("\nPrinting each byte.");
56
57 idx = 0;
58 foreach (byte b in bb.GetBytes())
59 {
60 WriteLine($"byte at[{idx}]: {b}");
61 ++idx;
62 }
63 }
64}
65
diff --git a/src/examples/eina/EinaError01.cs b/src/examples/eina/EinaError01.cs
new file mode 100644
index 0000000000..61af99508b
--- /dev/null
+++ b/src/examples/eina/EinaError01.cs
@@ -0,0 +1,75 @@
1using static System.Console;
2
3public class ExampleEinaError01
4{
5 private static bool RegisteredErrors = false;
6 private static eina.Error MyErrorNegative;
7 private static eina.Error MyErrorNull;
8
9 private static void testFunc(int n, string s)
10 {
11 if (!RegisteredErrors)
12 {
13 MyErrorNegative = eina.Error.Register("Negative number");
14 MyErrorNull = eina.Error.Register("NULL pointer");
15 RegisteredErrors = true;
16 }
17
18 if (n < 0)
19 {
20 eina.Error.Set(MyErrorNegative);
21 return;
22 }
23
24 if (s == null)
25 {
26 eina.Error.Set(MyErrorNull);
27 return;
28 }
29 }
30
31 public static void Main()
32 {
33 eina.Config.Init();
34 efl.eo.Config.Init();
35
36 // Handling Eina_Error with exception
37 try
38 {
39 testFunc(-1, "abc");
40 eina.Error.RaiseIfOccurred();
41 }
42 catch(efl.EflException e)
43 {
44 WriteLine($"Caught error: {e.Message}");
45 }
46
47 // Handling Eina_Error directly
48 testFunc(42, null);
49 eina.Error err = eina.Error.Get();
50 if (err != 0)
51 {
52 WriteLine($"Error set: {err.Message}");
53 }
54 eina.Error.Clear();
55
56 // No error set
57 try
58 {
59 testFunc(42, "abc");
60
61 eina.Error.RaiseIfOccurred();
62
63 err = eina.Error.Get();
64 WriteLine($"Really no error? {err == eina.Error.NO_ERROR}.");
65 }
66 catch
67 {
68 WriteLine("Unspected error!!!");
69 }
70
71 WriteLine("No error message is empty string: \"{0}\"", eina.Error.NO_ERROR.Message);
72 WriteLine("No error message is empty string: \"{0}\"", eina.Error.MsgGet(0));
73 }
74}
75
diff --git a/src/examples/eina/EinaHash01.cs b/src/examples/eina/EinaHash01.cs
new file mode 100644
index 0000000000..a645dde1ab
--- /dev/null
+++ b/src/examples/eina/EinaHash01.cs
@@ -0,0 +1,66 @@
1using static System.Console;
2
3public class ExampleEinaHash01
4{
5 public static void Main()
6 {
7 eina.Config.Init();
8
9 var phone_book = new eina.Hash<string, string>();
10
11 // Add initial entries to our hash
12 phone_book.Add("Wolfgang Amadeus Mozart", "+01 23 456-78910");
13 phone_book.Add("Ludwig van Beethoven", "+12 34 567-89101");
14 phone_book.Add("Richard Georg Strauss", "+23 45 678-91012");
15 phone_book.Add("Heitor Villa-Lobos", "+34 56 789-10123");
16
17 // Look for a specific entry and get its phone number
18 var entry_name = "Heitor Villa-Lobos";
19 var phone = phone_book.Find(entry_name);
20
21 WriteLine("Printing entry.");
22 WriteLine($"Name: {entry_name}");
23 WriteLine($"Number: {phone}\n");
24
25 // Delete this entry
26 var r = phone_book.DelByKey(entry_name);
27 WriteLine($"Hash entry successfully deleted? {r}!\n");
28
29 // Modify the pointer data of an entry and free the old one
30 phone_book.Modify("Richard Georg Strauss", "+23 45 111-11111");
31
32 // Modify or add an entry to the hash
33 // Let's first add a new entry
34 entry_name = "Raul Seixas";
35 phone_book[entry_name] = "+55 01 234-56789";
36 WriteLine("Printing entry.");
37 WriteLine($"Name: {entry_name}");
38 WriteLine($"Number: {phone_book[entry_name]}\n");
39
40 // Now change the phone number
41 phone_book["Raul Seixas"] = "+55 02 222-22222";
42 WriteLine("Printing entry.");
43 WriteLine($"Name: {entry_name}");
44 WriteLine($"Number: {phone_book[entry_name]}\n");
45
46 // Check how many items are in the phone book
47 WriteLine("There are {0} items in the hash.\n", phone_book.Count);
48
49 // Change the name (key) on an entry
50 phone_book.Move("Raul Seixas", "Alceu Valenca");
51 entry_name = "Alceu Valenca";
52 WriteLine("Printing entry.");
53 WriteLine($"Name: {entry_name}");
54 WriteLine($"Number: {phone_book[entry_name]}\n");
55
56 // Empty the phone book, but don't destroy it
57 phone_book.FreeBuckets();
58 WriteLine("There are {0} items in the hash.\n", phone_book.Count);
59
60 // Phone book could still be used, but we are freeing it since we are
61 // done for now
62 phone_book.Dispose();
63 }
64}
65
66
diff --git a/src/examples/elementary/efl_ui_slider_mono.cs b/src/examples/elementary/efl_ui_slider_mono.cs
new file mode 100644
index 0000000000..a5aff11547
--- /dev/null
+++ b/src/examples/elementary/efl_ui_slider_mono.cs
@@ -0,0 +1,63 @@
1using System;
2
3public class Example
4{
5 public static efl.ui.Button CreateButton(efl.Object parent,
6 string text,
7 int w, int h,
8 EventHandler callback) {
9 efl.ui.Button button = new efl.ui.ButtonConcrete(parent);
10 button.SetText(text);
11 button.SetSize(w, h);
12
13 button.CLICKED += callback;
14
15 return button;
16 }
17
18#if WIN32 // Passed to the C# compiler with -define:WIN32
19 // Mono on Windows by default uses multi-thread apartments for COM stuff while
20 // OLE - used by ecore win32 DnD requires single threading for COM.
21 [STAThreadAttribute()]
22#endif
23 public static void Main() {
24 efl.All.Init(efl.Components.Ui);
25
26 efl.ui.Win win = new efl.ui.WinConcrete(null);
27 win.SetText("Hello, C#!!");
28 win.SetAutohide(true);
29
30 efl.ui.Box_Flow box = new efl.ui.Box_FlowConcrete(win);
31
32 efl.ui.Button button = CreateButton(box, "Click to exit", 120, 30,
33 (object sender, EventArgs e) => {
34 efl.ui.Config.Exit();
35 });
36
37 box.Pack(button);
38
39 efl.ui.Progressbar bar = new efl.ui.ProgressbarConcrete(box);
40 bar.SetSize(120, 30);
41
42 efl.ui.Slider slider = new efl.ui.SliderConcrete(box);
43 slider.SetSize(120, 30);
44
45 slider.CHANGED += (object sender, EventArgs e) => {
46 bar.SetRangeValue(slider.GetRangeValue());
47 };
48
49 box.Pack(bar);
50 box.Pack(slider);
51
52 button.SetVisible(true);
53 box.SetVisible(true);
54
55 win.SetSize(120, 90);
56 win.SetVisible(true);
57
58 efl.ui.Config.Run();
59
60 efl.All.Shutdown();
61 }
62
63}
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