summaryrefslogtreecommitdiff
path: root/reference/csharp/core
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2018-08-30 21:41:01 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-08-31 12:23:35 -0300
commit6559459bc7ccdc25719c66a08822a317c1c0a41b (patch)
tree711d684a484fa7d816638af3fe62fb11332ed5bf /reference/csharp/core
parentad936668758288eb54c6acfe3e3226972558ccff (diff)
csharp: Add Events tutorial
Reviewers: vitor.sousa, lauromoura Reviewed By: vitor.sousa Differential Revision: https://phab.enlightenment.org/D6953
Diffstat (limited to 'reference/csharp/core')
-rw-r--r--reference/csharp/core/meson.build10
-rw-r--r--reference/csharp/core/src/core_event.cs73
-rw-r--r--reference/csharp/core/src/meson.build8
3 files changed, 91 insertions, 0 deletions
diff --git a/reference/csharp/core/meson.build b/reference/csharp/core/meson.build
new file mode 100644
index 0000000..e546f6b
--- /dev/null
+++ b/reference/csharp/core/meson.build
@@ -0,0 +1,10 @@
1project(
2 'efl-reference-core', 'cs',
3 version : '0.0.1',
4 meson_version : '>= 0.38.0')
5
6efl_mono = dependency('efl-mono', version : '>=1.20.99')
7efl_mono_libs = efl_mono.get_pkgconfig_variable('mono_libs')
8
9subdir('src')
10
diff --git a/reference/csharp/core/src/core_event.cs b/reference/csharp/core/src/core_event.cs
new file mode 100644
index 0000000..40bbb65
--- /dev/null
+++ b/reference/csharp/core/src/core_event.cs
@@ -0,0 +1,73 @@
1/*
2 * Efl Core Event examples.
3 *
4 * This example shows the various ways of adding callbacks for standard events.
5 * It also demonstrates how to freeze and thaw events on an object.
6 */
7
8using System;
9
10public class Example
11{
12 // Polling callback
13 private static void PollCb(object sender, EventArgs e)
14 {
15 Console.WriteLine(" Poll from {0}", ((efl.IObject)sender).GetName());
16 }
17
18#if WIN32
19 [STAThreadAttribute()]
20#endif
21 public static void Main()
22 {
23 // Initialize EFL and all UI components
24 efl.All.Init();
25
26 // Retrieve the application's main loop
27 var mainloop = efl.App.GetLoopMain();
28 mainloop.SetName("Mainloop");
29
30 // This event gets triggered continuously
31 mainloop.PollHighEvt += PollCb;
32
33 // This timer will control events fired by the main loop
34 new efl.Loop_Timer(mainloop, (efl.ILoop_Timer etimer) => {
35 etimer.SetName("Timer");
36 // Trigger every 100ms
37 etimer.SetInterval(0.1);
38 // To count number of timer triggers
39 int tick_count = 0;
40 etimer.TickEvt += (object sender, EventArgs e) => {
41 string message = "Tick {0} from {1}: ";
42 // Depending on the number of timer ticks, it does a different thing
43 switch (tick_count) {
44 case 0:
45 message += "Freezing Mainloop events";
46 mainloop.FreezeEvent();
47 break;
48 case 1:
49 message += "Thawing Mainloop events";
50 mainloop.ThawEvent();
51 break;
52 default:
53 message += "Quitting";
54 mainloop.Quit(new eina.Value(0));
55 break;
56 }
57 Console.WriteLine(message, tick_count, ((efl.IObject)sender).GetName());
58 tick_count++;
59 };
60 });
61
62 Console.WriteLine("Waiting for Timer to call back...");
63
64 // Start the EFL main loop (and the experiment)
65 mainloop.Begin();
66
67 // Shutdown EFL
68 efl.All.Shutdown();
69
70 Console.WriteLine("Application is over");
71 }
72}
73
diff --git a/reference/csharp/core/src/meson.build b/reference/csharp/core/src/meson.build
new file mode 100644
index 0000000..d5162e8
--- /dev/null
+++ b/reference/csharp/core/src/meson.build
@@ -0,0 +1,8 @@
1deps = [efl_mono]
2
3executable('efl_reference_core_event',
4 files(['core_event.cs']),
5 dependencies : deps,
6 cs_args : efl_mono_libs,
7 install : true
8)