eolian-cxx: Added examples.

Added complex types, callbacks and events examples.
This commit is contained in:
Savio Sena 2014-07-16 16:32:56 -03:00 committed by Felipe Magno de Almeida
parent ac8975a73f
commit 88f1293527
4 changed files with 301 additions and 8 deletions

View File

@ -27,6 +27,8 @@ AM_CXXFLAGS = \
-I$(top_builddir)/src/bindings/eo_cxx \
-I$(top_srcdir)/src/bindings/eina_cxx \
-I$(top_builddir)/src/bindings/eina_cxx \
-I$(top_srcdir)/src/bindings/ecore_cxx \
-I$(top_builddir)/src/bindings/ecore_cxx \
-I$(top_srcdir)/src/lib/evas/ \
-I$(top_builddir)/src/lib/evas/ \
-I$(top_srcdir)/src/lib/evas/common \
@ -77,11 +79,17 @@ IMPL = \
SRCS = \
eolian_cxx_simple_01.cc \
eolian_cxx_inherit_01.cc \
eolian_cxx_callbacks_01.cc \
eolian_cxx_eo_events_01.cc \
eolian_cxx_complex_types_01.cc \
$(IMPL)
EXTRA_PROGRAMS = \
eolian_cxx_simple_01 #\
eolian_cxx_inherit_01
eolian_cxx_simple_01 \
eolian_cxx_inherit_01 \
eolian_cxx_callbacks_01 \
eolian_cxx_eo_events_01 \
eolian_cxx_complex_types_01
DATA_FILES = Makefile.examples $(EOS)
@ -89,15 +97,19 @@ eolian_cxx_simple_01_SOURCES = \
eolian_cxx_simple_01.cc \
colourable.c \
colourablesquare.c
eolian_cxx_simple_01.$(OBJEXT): $(GENERATED)
# eolian_cxx_inherit_01_SOURCES = \
# eolian_cxx_inherit_01.cc \
# colourable.c \
# colourablesquare.c
eolian_cxx_inherit_01_SOURCES = \
eolian_cxx_inherit_01.cc \
colourable.c \
colourablesquare.c
eolian_cxx_inherit_01.$(OBJEXT): $(GENERATED)
# eolian_cxx_inherit_01.$(OBJEXT): $(GENERATED)
eolian_cxx_callbacks_01_SOURCES = eolian_cxx_callbacks_01.cc
eolian_cxx_eo_events_01_SOURCES = eolian_cxx_eo_events_01.cc
eolian_cxx_complex_types_01_SOURCES = eolian_cxx_complex_types_01.cc
%.eo.hh: %.eo
$(AM_V_EOLCXX)$(EOLIAN_CXX) $(EOLIAN_FLAGS) -I${abs_srcdir} -o $@ $<
@ -125,3 +137,4 @@ uninstall-local:
if ALWAYS_BUILD_EXAMPLES
noinst_PROGRAMS = $(EXTRA_PROGRAMS)
endif

View File

@ -0,0 +1,58 @@
#include <iostream>
#include <thread>
#include <cassert>
#include <sstream>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <Eo.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <Eina.hh>
#include <Eo.hh>
#include <Ecore.hh>
#include <Evas.hh>
#include <ecore_poll.eo.hh>
namespace efl { namespace ecore {
using ::ecore_poller;
} }
void
example_callbacks()
{
int count = 0;
efl::ecore::ecore_poller poller
(ECORE_POLLER_CORE, 1,
[&count, &poller]
{
if (++count == 5)
{
std::cout << std::endl;
ecore_main_loop_quit();
return false;
}
poller.interval_set(2*poller.interval_get());
std::cout << "."<< std::flush;
return true;
});
::ecore_main_loop_begin();
}
int main()
{
efl::eina::eina_init eina_;
efl::eo::eo_init eo_;
efl::ecore::ecore_init ecore_;
std::cerr << "[+] Running EFL++ example: Callbacks" << std::endl;
example_callbacks();
return 0;
}

View File

@ -0,0 +1,119 @@
#include <iostream>
#include <thread>
#include <cassert>
#include <sstream>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <Eo.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <Eina.hh>
#include <Eo.hh>
#include <Ecore.hh>
#include <Evas.hh>
#include <canvas/evas.eo.hh>
#include <canvas/evas_text.eo.hh>
#include <canvas/evas_rectangle.eo.hh>
#include <canvas/evas_zoomable_interface.eo.hh>
namespace efl { namespace evas { // XXX only while we don't have namespaces in EFL
using evas_base = ::evas;
using ::evas_object;
using ::evas_text;
using ::evas_grid;
using ::evas_rectangle;
using ::evas_common_interface;
using ::evas_zoomable_interface;
} }
namespace {
// EFL Ecore-Evas doesn't have C++ bindings yet.
Ecore_Evas *ee;
void
_ecore_evas_init()
{
if (!ee)
{
::ecore_evas_init();
::evas_init();
ee = ::ecore_evas_new(NULL, 0, 0, 500, 380, NULL);
::ecore_evas_show(ee);
}
}
void
_ecore_evas_shutdown()
{
if (ee)
{
::ecore_evas_free(ee);
::ecore_evas_shutdown();
ee = NULL;
}
}
}
void
example_complex_types()
{
_ecore_evas_init();
efl::evas::evas_base canvas(::eo_ref(::ecore_evas_get(ee)));
::evas_rectangle bg(efl::eo::parent = canvas);
bg.color_set(255, 255, 255, 255);
bg.position_set(0, 0);
bg.size_set(500, 250);
bg.visibility_set(true);
efl::evas::evas_grid grid(efl::eo::parent = canvas);
grid.position_set(0, 0);
grid.color_set(0, 0, 0, 255);
grid.size_set(5, 5);
grid.visibility_set(true);
efl::evas::evas_text text1(efl::eo::parent = canvas);
text1.style_set(EVAS_TEXT_STYLE_OUTLINE);
text1.color_set(255, 0, 0, 255);
text1.font_set("DejaVu", 32);
text1.text_set("EFL++ Examples");
text1.visibility_set(true);
int t1w, t1h;
text1.size_get(&t1w, &t1h);
grid.pack(text1, 1, 1, t1w, t1h);
efl::evas::evas_text text2(efl::eo::parent = canvas);
text2.style_set(EVAS_TEXT_STYLE_PLAIN);
text2.color_set(0, 120, 0, 255);
text2.position_set(t1w+50, t1h+50);
text2.font_set("Courier", 16);
std::stringstream ss;
ss << "version " << EFL_VERSION_MAJOR << "." << EFL_VERSION_MINOR;
text2.text_set(ss.str().c_str());
text2.visibility_set(true);
int t2w, t2h;
text2.size_get(&t2w, &t2h);
canvas.render();
::ecore_main_loop_begin();
_ecore_evas_shutdown();
}
int main()
{
efl::eina::eina_init eina_;
efl::eo::eo_init eo_;
efl::ecore::ecore_init ecore_;
std::cerr << "[+] Running ELF++ example: Complex Types" << std::endl;
example_complex_types();
return 0;
}

View File

@ -0,0 +1,103 @@
#include <iostream>
#include <thread>
#include <cassert>
#include <sstream>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <Eo.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <Eina.hh>
#include <Eo.hh>
#include <Ecore.hh>
#include <Evas.hh>
#include <canvas/evas.eo.hh>
#include <canvas/evas_text.eo.hh>
#include <canvas/evas_image.eo.hh>
#include <canvas/evas_box.eo.hh>
namespace efl { namespace evas {
using evas_base = ::evas;
using ::evas_object;
using ::evas_text;
using ::evas_grid;
using ::evas_rectangle;
using ::evas_common_interface;
using ::evas_zoomable_interface;
} }
namespace {
// XXX Ecore-Evas is not binded yet.
Ecore_Evas *ee;
void
_ecore_evas_init()
{
if (!ee)
{
::ecore_evas_init();
::evas_init();
ee = ::ecore_evas_new(NULL, 0, 0, 500, 380, NULL);
::ecore_evas_show(ee);
}
}
void
_ecore_evas_shutdown()
{
if (ee)
{
::ecore_evas_free(ee);
::ecore_evas_shutdown();
ee = NULL;
}
}
}
void
example_complex_types()
{
_ecore_evas_init();
{
efl::evas::evas_base canvas(::eo_ref(::ecore_evas_get(ee)));
::evas_rectangle bg(efl::eo::parent = canvas);
bg.color_set(255, 255, 255, 255);
bg.position_set(0, 0);
bg.size_set(500, 250);
bg.visibility_set(true);
efl::eo::signal_connection conn =
bg.event_mouse_down_callback_add
([] (::evas_object obj, Eo_Event_Description const& desc, void* info)
{
std::cout << "evas_box::mouse_down" << std::endl;
return EO_CALLBACK_CONTINUE;
});
canvas.render();
}
::ecore_main_loop_begin();
_ecore_evas_shutdown();
}
int main()
{
efl::eina::eina_init eina_;
efl::eo::eo_init eo_;
efl::ecore::ecore_init ecore_;
std::cerr << "[+] Running ELF++ example: Eo Events" << std::endl;
example_complex_types();
return 0;
}