summaryrefslogtreecommitdiff
path: root/src/examples/eolian_cxx
diff options
context:
space:
mode:
authorSavio Sena <savio@expertisesolutions.com.br>2014-07-16 16:32:56 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-07-18 18:57:09 -0300
commit88f12935278c9d3547da96b74e525402e2efd3f0 (patch)
treea8f88a8050a2936d28d5ce7d3ee6217816aad953 /src/examples/eolian_cxx
parentac8975a73f90c07dfa6f9587b72cfde1e6014bdb (diff)
eolian-cxx: Added examples.
Added complex types, callbacks and events examples.
Diffstat (limited to 'src/examples/eolian_cxx')
-rw-r--r--src/examples/eolian_cxx/Makefile.am29
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_callbacks_01.cc58
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_complex_types_01.cc119
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_eo_events_01.cc103
4 files changed, 301 insertions, 8 deletions
diff --git a/src/examples/eolian_cxx/Makefile.am b/src/examples/eolian_cxx/Makefile.am
index c5ad78a..a163522 100644
--- a/src/examples/eolian_cxx/Makefile.am
+++ b/src/examples/eolian_cxx/Makefile.am
@@ -27,6 +27,8 @@ AM_CXXFLAGS = \
27 -I$(top_builddir)/src/bindings/eo_cxx \ 27 -I$(top_builddir)/src/bindings/eo_cxx \
28 -I$(top_srcdir)/src/bindings/eina_cxx \ 28 -I$(top_srcdir)/src/bindings/eina_cxx \
29 -I$(top_builddir)/src/bindings/eina_cxx \ 29 -I$(top_builddir)/src/bindings/eina_cxx \
30 -I$(top_srcdir)/src/bindings/ecore_cxx \
31 -I$(top_builddir)/src/bindings/ecore_cxx \
30 -I$(top_srcdir)/src/lib/evas/ \ 32 -I$(top_srcdir)/src/lib/evas/ \
31 -I$(top_builddir)/src/lib/evas/ \ 33 -I$(top_builddir)/src/lib/evas/ \
32 -I$(top_srcdir)/src/lib/evas/common \ 34 -I$(top_srcdir)/src/lib/evas/common \
@@ -77,11 +79,17 @@ IMPL = \
77SRCS = \ 79SRCS = \
78 eolian_cxx_simple_01.cc \ 80 eolian_cxx_simple_01.cc \
79 eolian_cxx_inherit_01.cc \ 81 eolian_cxx_inherit_01.cc \
82 eolian_cxx_callbacks_01.cc \
83 eolian_cxx_eo_events_01.cc \
84 eolian_cxx_complex_types_01.cc \
80 $(IMPL) 85 $(IMPL)
81 86
82EXTRA_PROGRAMS = \ 87EXTRA_PROGRAMS = \
83 eolian_cxx_simple_01 #\ 88 eolian_cxx_simple_01 \
84 eolian_cxx_inherit_01 89 eolian_cxx_inherit_01 \
90 eolian_cxx_callbacks_01 \
91 eolian_cxx_eo_events_01 \
92 eolian_cxx_complex_types_01
85 93
86DATA_FILES = Makefile.examples $(EOS) 94DATA_FILES = Makefile.examples $(EOS)
87 95
@@ -89,15 +97,19 @@ eolian_cxx_simple_01_SOURCES = \
89 eolian_cxx_simple_01.cc \ 97 eolian_cxx_simple_01.cc \
90 colourable.c \ 98 colourable.c \
91 colourablesquare.c 99 colourablesquare.c
92
93eolian_cxx_simple_01.$(OBJEXT): $(GENERATED) 100eolian_cxx_simple_01.$(OBJEXT): $(GENERATED)
94 101
95# eolian_cxx_inherit_01_SOURCES = \ 102eolian_cxx_inherit_01_SOURCES = \
96# eolian_cxx_inherit_01.cc \ 103 eolian_cxx_inherit_01.cc \
97# colourable.c \ 104 colourable.c \
98# colourablesquare.c 105 colourablesquare.c
106eolian_cxx_inherit_01.$(OBJEXT): $(GENERATED)
99 107
100# eolian_cxx_inherit_01.$(OBJEXT): $(GENERATED) 108eolian_cxx_callbacks_01_SOURCES = eolian_cxx_callbacks_01.cc
109
110eolian_cxx_eo_events_01_SOURCES = eolian_cxx_eo_events_01.cc
111
112eolian_cxx_complex_types_01_SOURCES = eolian_cxx_complex_types_01.cc
101 113
102%.eo.hh: %.eo 114%.eo.hh: %.eo
103 $(AM_V_EOLCXX)$(EOLIAN_CXX) $(EOLIAN_FLAGS) -I${abs_srcdir} -o $@ $< 115 $(AM_V_EOLCXX)$(EOLIAN_CXX) $(EOLIAN_FLAGS) -I${abs_srcdir} -o $@ $<
@@ -125,3 +137,4 @@ uninstall-local:
125if ALWAYS_BUILD_EXAMPLES 137if ALWAYS_BUILD_EXAMPLES
126noinst_PROGRAMS = $(EXTRA_PROGRAMS) 138noinst_PROGRAMS = $(EXTRA_PROGRAMS)
127endif 139endif
140
diff --git a/src/examples/eolian_cxx/eolian_cxx_callbacks_01.cc b/src/examples/eolian_cxx/eolian_cxx_callbacks_01.cc
new file mode 100644
index 0000000..4efff00
--- /dev/null
+++ b/src/examples/eolian_cxx/eolian_cxx_callbacks_01.cc
@@ -0,0 +1,58 @@
1#include <iostream>
2#include <thread>
3#include <cassert>
4#include <sstream>
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9
10#include <Eo.h>
11#include <Ecore.h>
12#include <Evas.h>
13#include <Ecore_Evas.h>
14
15#include <Eina.hh>
16#include <Eo.hh>
17#include <Ecore.hh>
18#include <Evas.hh>
19
20#include <ecore_poll.eo.hh>
21
22namespace efl { namespace ecore {
23using ::ecore_poller;
24} }
25
26void
27example_callbacks()
28{
29 int count = 0;
30 efl::ecore::ecore_poller poller
31 (ECORE_POLLER_CORE, 1,
32 [&count, &poller]
33 {
34 if (++count == 5)
35 {
36 std::cout << std::endl;
37 ecore_main_loop_quit();
38 return false;
39 }
40 poller.interval_set(2*poller.interval_get());
41 std::cout << "."<< std::flush;
42 return true;
43 });
44 ::ecore_main_loop_begin();
45}
46
47int main()
48{
49 efl::eina::eina_init eina_;
50 efl::eo::eo_init eo_;
51 efl::ecore::ecore_init ecore_;
52
53 std::cerr << "[+] Running EFL++ example: Callbacks" << std::endl;
54 example_callbacks();
55
56 return 0;
57}
58
diff --git a/src/examples/eolian_cxx/eolian_cxx_complex_types_01.cc b/src/examples/eolian_cxx/eolian_cxx_complex_types_01.cc
new file mode 100644
index 0000000..cc2c760
--- /dev/null
+++ b/src/examples/eolian_cxx/eolian_cxx_complex_types_01.cc
@@ -0,0 +1,119 @@
1#include <iostream>
2#include <thread>
3#include <cassert>
4#include <sstream>
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9
10#include <Eo.h>
11#include <Ecore.h>
12#include <Evas.h>
13#include <Ecore_Evas.h>
14
15#include <Eina.hh>
16#include <Eo.hh>
17#include <Ecore.hh>
18#include <Evas.hh>
19
20#include <canvas/evas.eo.hh>
21#include <canvas/evas_text.eo.hh>
22#include <canvas/evas_rectangle.eo.hh>
23#include <canvas/evas_zoomable_interface.eo.hh>
24
25namespace efl { namespace evas { // XXX only while we don't have namespaces in EFL
26using evas_base = ::evas;
27using ::evas_object;
28using ::evas_text;
29using ::evas_grid;
30using ::evas_rectangle;
31using ::evas_common_interface;
32using ::evas_zoomable_interface;
33} }
34
35namespace {
36
37// EFL Ecore-Evas doesn't have C++ bindings yet.
38Ecore_Evas *ee;
39void
40_ecore_evas_init()
41{
42 if (!ee)
43 {
44 ::ecore_evas_init();
45 ::evas_init();
46 ee = ::ecore_evas_new(NULL, 0, 0, 500, 380, NULL);
47 ::ecore_evas_show(ee);
48 }
49}
50void
51_ecore_evas_shutdown()
52{
53 if (ee)
54 {
55 ::ecore_evas_free(ee);
56 ::ecore_evas_shutdown();
57 ee = NULL;
58 }
59}
60
61}
62
63void
64example_complex_types()
65{
66 _ecore_evas_init();
67 efl::evas::evas_base canvas(::eo_ref(::ecore_evas_get(ee)));
68
69 ::evas_rectangle bg(efl::eo::parent = canvas);
70 bg.color_set(255, 255, 255, 255);
71 bg.position_set(0, 0);
72 bg.size_set(500, 250);
73 bg.visibility_set(true);
74
75 efl::evas::evas_grid grid(efl::eo::parent = canvas);
76 grid.position_set(0, 0);
77 grid.color_set(0, 0, 0, 255);
78 grid.size_set(5, 5);
79 grid.visibility_set(true);
80
81 efl::evas::evas_text text1(efl::eo::parent = canvas);
82 text1.style_set(EVAS_TEXT_STYLE_OUTLINE);
83 text1.color_set(255, 0, 0, 255);
84 text1.font_set("DejaVu", 32);
85 text1.text_set("EFL++ Examples");
86 text1.visibility_set(true);
87 int t1w, t1h;
88 text1.size_get(&t1w, &t1h);
89 grid.pack(text1, 1, 1, t1w, t1h);
90
91 efl::evas::evas_text text2(efl::eo::parent = canvas);
92 text2.style_set(EVAS_TEXT_STYLE_PLAIN);
93 text2.color_set(0, 120, 0, 255);
94 text2.position_set(t1w+50, t1h+50);
95 text2.font_set("Courier", 16);
96 std::stringstream ss;
97 ss << "version " << EFL_VERSION_MAJOR << "." << EFL_VERSION_MINOR;
98 text2.text_set(ss.str().c_str());
99 text2.visibility_set(true);
100 int t2w, t2h;
101 text2.size_get(&t2w, &t2h);
102
103 canvas.render();
104 ::ecore_main_loop_begin();
105 _ecore_evas_shutdown();
106}
107
108int main()
109{
110 efl::eina::eina_init eina_;
111 efl::eo::eo_init eo_;
112 efl::ecore::ecore_init ecore_;
113
114 std::cerr << "[+] Running ELF++ example: Complex Types" << std::endl;
115 example_complex_types();
116
117 return 0;
118}
119
diff --git a/src/examples/eolian_cxx/eolian_cxx_eo_events_01.cc b/src/examples/eolian_cxx/eolian_cxx_eo_events_01.cc
new file mode 100644
index 0000000..e3563ce
--- /dev/null
+++ b/src/examples/eolian_cxx/eolian_cxx_eo_events_01.cc
@@ -0,0 +1,103 @@
1#include <iostream>
2#include <thread>
3#include <cassert>
4#include <sstream>
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9
10#include <Eo.h>
11#include <Ecore.h>
12#include <Evas.h>
13#include <Ecore_Evas.h>
14
15#include <Eina.hh>
16#include <Eo.hh>
17#include <Ecore.hh>
18#include <Evas.hh>
19
20#include <canvas/evas.eo.hh>
21#include <canvas/evas_text.eo.hh>
22#include <canvas/evas_image.eo.hh>
23#include <canvas/evas_box.eo.hh>
24
25
26namespace efl { namespace evas {
27using evas_base = ::evas;
28using ::evas_object;
29using ::evas_text;
30using ::evas_grid;
31using ::evas_rectangle;
32using ::evas_common_interface;
33using ::evas_zoomable_interface;
34} }
35
36namespace {
37
38// XXX Ecore-Evas is not binded yet.
39Ecore_Evas *ee;
40void
41_ecore_evas_init()
42{
43 if (!ee)
44 {
45 ::ecore_evas_init();
46 ::evas_init();
47 ee = ::ecore_evas_new(NULL, 0, 0, 500, 380, NULL);
48 ::ecore_evas_show(ee);
49 }
50}
51void
52_ecore_evas_shutdown()
53{
54 if (ee)
55 {
56 ::ecore_evas_free(ee);
57 ::ecore_evas_shutdown();
58 ee = NULL;
59 }
60}
61
62}
63
64void
65example_complex_types()
66{
67 _ecore_evas_init();
68
69 {
70 efl::evas::evas_base canvas(::eo_ref(::ecore_evas_get(ee)));
71
72 ::evas_rectangle bg(efl::eo::parent = canvas);
73 bg.color_set(255, 255, 255, 255);
74 bg.position_set(0, 0);
75 bg.size_set(500, 250);
76 bg.visibility_set(true);
77
78 efl::eo::signal_connection conn =
79 bg.event_mouse_down_callback_add
80 ([] (::evas_object obj, Eo_Event_Description const& desc, void* info)
81 {
82 std::cout << "evas_box::mouse_down" << std::endl;
83 return EO_CALLBACK_CONTINUE;
84 });
85
86 canvas.render();
87 }
88
89 ::ecore_main_loop_begin();
90 _ecore_evas_shutdown();
91}
92
93int main()
94{
95 efl::eina::eina_init eina_;
96 efl::eo::eo_init eo_;
97 efl::ecore::ecore_init ecore_;
98
99 std::cerr << "[+] Running ELF++ example: Eo Events" << std::endl;
100 example_complex_types();
101
102 return 0;
103}