merge: add evas tests and examples

SVN revision: 79300
devs/devilhorns/wayland_egl
Vincent Torri 10 years ago
parent 52e0d54174
commit 80910393d6
  1. 1
      Makefile.am
  2. 2
      configure.ac
  3. 4
      src/Makefile.am
  4. 4
      src/examples/Makefile.am
  5. 7
      src/examples/eet/Makefile.am
  6. 6
      src/examples/eina/Makefile.am
  7. 18
      src/examples/eo/Makefile.am
  8. BIN
      src/examples/evas/Makefile.am
  9. 17
      src/examples/evas/aspect.edc
  10. BIN
      src/examples/evas/cube1.png
  11. BIN
      src/examples/evas/enlightenment.png
  12. 249
      src/examples/evas/evas-aspect-hints.c
  13. 382
      src/examples/evas/evas-box.c
  14. 228
      src/examples/evas/evas-buffer-simple.c
  15. 413
      src/examples/evas/evas-events.c
  16. 378
      src/examples/evas/evas-hints.c
  17. 353
      src/examples/evas/evas-images.c
  18. 311
      src/examples/evas/evas-images2.c
  19. 196
      src/examples/evas/evas-images3.c
  20. 56
      src/examples/evas/evas-init-shutdown.c
  21. 321
      src/examples/evas/evas-map-utils.c
  22. 235
      src/examples/evas/evas-object-manipulation.c
  23. 790
      src/examples/evas/evas-smart-interface.c
  24. 756
      src/examples/evas/evas-smart-object.c
  25. 329
      src/examples/evas/evas-stacking.c
  26. 120
      src/examples/evas/evas-table.c
  27. 411
      src/examples/evas/evas-text.c
  28. BIN
      src/examples/evas/im1.png
  29. 0
      src/examples/evas/red.png
  30. 2
      src/tests/Makefile.am
  31. 27
      src/tests/evas/Makefile.am
  32. 25
      src/tests/evas/evas_suite.c
  33. 12
      src/tests/evas/evas_suite.h
  34. 135
      src/tests/evas/evas_test_callbacks.c
  35. 19
      src/tests/evas/evas_test_init.c
  36. 493
      src/tests/evas/evas_test_text.c
  37. 2219
      src/tests/evas/evas_test_textblock.c
  38. 40
      src/tests/evas/evas_tests_helpers.h

@ -168,6 +168,7 @@ if EFL_ENABLE_COVERAGE
endif
@./src/tests/eet/eet_suite$(EXEEXT)
@./src/tests/eo/eo_suite$(EXEEXT)
@./src/tests/evas/evas_suite$(EXEEXT)
if EFL_ENABLE_COVERAGE
@$(MAKE) $(AM_MAKEFLAGS) lcov-report
endif

@ -1827,11 +1827,13 @@ src/examples/Makefile
src/examples/eina/Makefile
src/examples/eet/Makefile
src/examples/eo/Makefile
src/examples/evas/Makefile
src/lib/eina/eina_config.h
src/tests/Makefile
src/tests/eina/Makefile
src/tests/eet/Makefile
src/tests/eo/Makefile
src/tests/evas/Makefile
spec/efl.spec
pc/evil.pc
pc/eina.pc

@ -21,11 +21,11 @@ include Makefile_Embryo.am
.PHONY: benchmark examples
benchmark:
@$(MAKE) $(AM_MAKEFLAGS) -C lib
@$(MAKE) $(AM_MAKEFLAGS)
@$(MAKE) $(AM_MAKEFLAGS) -C benchmarks benchmark
examples:
@make -C lib
@make
@$(MAKE) $(AM_MAKEFLAGS) -C examples examples
install-examples:

@ -1,13 +1,15 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = eina eo eet
SUBDIRS = eina eo eet evas
examples:
@$(MAKE) $(AM_MAKEFLAGS) -C eina examples
@$(MAKE) $(AM_MAKEFLAGS) -C eo examples
@$(MAKE) $(AM_MAKEFLAGS) -C eet examples
@$(MAKE) $(AM_MAKEFLAGS) -C evas examples
install-examples:
@$(MAKE) $(AM_MAKEFLAGS) -C eina install-examples
@$(MAKE) $(AM_MAKEFLAGS) -C eo install-examples
@$(MAKE) $(AM_MAKEFLAGS) -C eet install-examples
@$(MAKE) $(AM_MAKEFLAGS) -C evas install-examples

@ -1,4 +1,5 @@
MAINTAINERCLEANFILES = Makefile.in
AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib/eina \
-I$(top_srcdir)/src/lib/eet \
@ -44,10 +45,10 @@ clean-local:
rm -f $(EXTRA_PROGRAMS)
install-examples:
mkdir -p $(pkgdatadir)/examples/eet
$(install_sh_DATA) -c $(SRCS) $(pkgdatadir)/examples/eet
mkdir -p $(datadir)/eet/examples
$(install_sh_DATA) -c $(SRCS) $(datadir)/eet/examples
uninstall-local:
for f in $(SRCS) ; do \
rm -f $(pkgdatadir)/examples/eet/$$f ; \
rm -f $(datadir)/eet/examples/$$f ; \
done

@ -112,12 +112,12 @@ clean-local:
rm -f $(EXTRA_PROGRAMS)
install-examples:
mkdir -p $(pkgdatadir)/examples/eina
$(install_sh_DATA) -c $(SRCS) $(pkgdatadir)/examples/eina
mkdir -p $(datadir)/eina/examples
$(install_sh_DATA) -c $(SRCS) $(datadir)/eina/examples
uninstall-local:
for f in $(SRCS) ; do \
rm -f $(pkgdatadir)/examples/eina/$$f ; \
rm -f $(datadir)/eina/examples/$$f ; \
done
EXTRA_DIST = addr_book.txt chat.xml

@ -67,20 +67,20 @@ clean-local:
rm -f $(EXTRA_PROGRAMS)
install-examples:
mkdir -p $(pkgdatadir)/examples/eo/isa
$(install_sh_DATA) -c $(eo_isa_SOURCES) $(pkgdatadir)/examples/eo/isa
mkdir -p $(pkgdatadir)/examples/eo/evas
$(install_sh_DATA) -c $(evas_SOURCES) $(pkgdatadir)/examples/eo/evas
mkdir -p $(pkgdatadir)/examples/eo/simple
$(install_sh_DATA) -c $(simple_SOURCES) $(pkgdatadir)/examples/eo/simple
mkdir -p $(datadir)/eo/examples/isa
$(install_sh_DATA) -c $(eo_isa_SOURCES) $(datadir)/eo/examples/isa
mkdir -p $(datadir)/eo/examples/evas
$(install_sh_DATA) -c $(evas_SOURCES) $(datadir)/eo/examples/evas
mkdir -p $(datadir)/eo/examples/simple
$(install_sh_DATA) -c $(simple_SOURCES) $(datadir)/eo/examples/simple
uninstall-local:
for f in $(eo_isa_SOURCES) ; do \
rm -f $(pkgdatadir)/examples/eo/isa/$$f ; \
rm -f $(datadir)/eo/examples/isa/$$f ; \
done
for f in $(evas_SOURCES) ; do \
rm -f $(pkgdatadir)/examples/eo/evas/$$f ; \
rm -f $(datadir)/eo/examples/evas/$$f ; \
done
for f in $(simple_SOURCES) ; do \
rm -f $(pkgdatadir)/examples/eo/simple/$$f ; \
rm -f $(datadir)/eo/examples/simple/$$f ; \
done

Binary file not shown.

@ -0,0 +1,17 @@
collections {
group {
name: "main";
parts {
part {
name: "content";
mouse_events: 0;
type: SWALLOW;
description {
state: "default" 0.0;
visible: 1;
}
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

@ -0,0 +1,249 @@
/**
* Simple Evas example illustrating aspect control hints on objects.
*
* You'll need at least one engine built for it (excluding the buffer
* one) and the png image loader also built. See stdout/stderr for
* output.
*
* You'll also need @b Edje for this one, as it has the only smart
* object implementing aspect control for children.
*
* @verbatim
* gcc -o evas-events evas-events.c `pkg-config --libs --cflags ecore-evas edje`
* @endverbatim
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Edje.h>
#include <stdio.h>
#include <errno.h>
#define WIDTH 320
#define HEIGHT 480
static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/aspect.edj";
struct test_data
{
Ecore_Evas *ee;
Evas *canvas;
Evas_Object *bg, *rect, *container, *border;
};
static struct test_data d = {0};
/* here just to keep our example's window size and background image's
* size in synchrony */
static void
_canvas_resize_cb(Ecore_Evas *ee)
{
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
evas_object_resize(d.bg, w, h);
}
static const char *
_get_aspect_name(Evas_Aspect_Control aspect)
{
switch (aspect)
{
case 0:
return "NONE";
case 1:
return "NEITHER";
case 2:
return "HORIZONTAL";
case 3:
return "VERTICAL";
case 4:
return "BOTH";
default:
return "INVALID";
}
}
static void
_on_keydown(void *data __UNUSED__,
Evas *evas __UNUSED__,
Evas_Object *o,
void *einfo)
{
const Evas_Modifier *mods;
Evas_Event_Key_Down *ev = einfo;
mods = evas_key_modifier_get(evas_object_evas_get(o));
if (evas_key_modifier_is_set(mods, "Shift") &&
strcmp(ev->keyname, "h") == 0) /* print help */
{
fprintf(stdout, "commands are:\n"
"\tc - cycle aspect control on object\n"
"\th - change horizontal aspect component\n"
"\tv - change vertical aspect component\n"
"\ts - print current object's status\n"
"\tH - print help\n");
return;
}
if (strcmp(ev->keyname, "s") == 0) /* get aspect status of the obj */
{
Evas_Coord w, h;
Evas_Aspect_Control aspect;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
fprintf(stdout, "Object has aspect %s, with horizontal compontent %d"
" and vertical compontent %d\n",
_get_aspect_name(aspect), w, h);
return;
}
if (strcmp(ev->keyname, "c") == 0) /* cycle aspect control on obj */
{
Evas_Coord w, h;
Evas_Aspect_Control aspect;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
aspect = (aspect + 1) % 5;
evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
fprintf(stdout, "Changing aspect control to %s\n",
_get_aspect_name(aspect));
return;
}
if (strcmp(ev->keyname, "h") == 0) /* change horizontal aspect component */
{
Evas_Coord w, h;
Evas_Aspect_Control aspect;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
w = (w + 1) % 3;
evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
fprintf(stdout, "Changing horizontal aspect component to %d\n", w);
return;
}
if (strcmp(ev->keyname, "v") == 0) /* change vertical aspect component */
{
Evas_Coord w, h;
Evas_Aspect_Control aspect;
evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
h = (h + 1) % 3;
evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
fprintf(stdout, "Changing vertical aspect component to %d\n", h);
return;
}
}
int
main(void)
{
Eina_Bool ret;
if (!ecore_evas_init())
return EXIT_FAILURE;
if (!edje_init())
return EXIT_FAILURE;
/* this will give you a window with an Evas canvas under the first
* engine available */
d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
if (!d.ee)
goto error;
ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
ecore_evas_show(d.ee);
/* the canvas pointer, de facto */
d.canvas = ecore_evas_get(d.ee);
d.bg = evas_object_rectangle_add(d.canvas);
evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
evas_object_move(d.bg, 0, 0); /* at canvas' origin */
evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
evas_object_show(d.bg);
evas_object_focus_set(d.bg, EINA_TRUE);
evas_object_event_callback_add(
d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
d.container = edje_object_add(d.canvas);
ret = edje_object_file_set(d.container, edje_file_path, "main");
if (!ret)
{
Edje_Load_Error err = edje_object_load_error_get(d.container);
const char *msg = edje_load_error_str(err);
fprintf(stderr, "could not load 'main' from %s: %s",
edje_file_path, msg);
goto panic;
}
evas_object_move(d.container, (WIDTH / 4), (HEIGHT / 4));
evas_object_resize(d.container, (WIDTH / 2), (HEIGHT / 2));
evas_object_show(d.container);
d.rect = evas_object_rectangle_add(d.canvas);
evas_object_color_set(d.rect, 0, 0, 255, 255);
evas_object_size_hint_aspect_set(d.rect, EVAS_ASPECT_CONTROL_NONE, 1, 1);
evas_object_show(d.rect);
edje_object_part_swallow(d.container, "content", d.rect);
evas_object_smart_changed(d.container);
/* this is a border around the edje object, container of the
* rectangle we are going to experiment with (change its aspect
* hints). this way you can see how their sizes relate */
d.border = evas_object_image_filled_add(d.canvas);
evas_object_image_file_set(d.border, border_img_path, NULL);
evas_object_image_border_set(d.border, 3, 3, 3, 3);
evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
evas_object_move(d.border, (WIDTH / 4) - 3, (HEIGHT / 4) - 3);
evas_object_resize(d.border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
evas_object_show(d.border);
ecore_main_loop_begin();
ecore_evas_free(d.ee);
ecore_evas_shutdown();
edje_shutdown();
return 0;
error:
fprintf(stderr, "you got to have at least one evas engine built and linked"
" up to ecore-evas for this example to run properly.\n");
panic:
ecore_evas_free(d.ee);
ecore_evas_shutdown();
edje_shutdown();
return -1;
}

@ -0,0 +1,382 @@
/**
* Simple Evas example illustrating a custom Evas box object
*
* You'll need at least one engine built for it (excluding the buffer
* one). See stdout/stderr for output.
*
* @verbatim
* gcc -o evas-box evas-box.c `pkg-config --libs --cflags evas ecore ecore-evas eina`
* @endverbatim
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#define __UNUSED__
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define WIDTH (640)
#define HEIGHT (480)
static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
static const char *commands = \
"commands are:\n"
"\ta - change the box's alignment values\n"
"\tp - change the box's padding values\n"
"\t1 - change the box's layout to horizontal\n"
"\t2 - change the box's layout to vertical\n"
"\t3 - change the box's layout to horizontal homogeneous\n"
"\t4 - change the box's layout to vertical homogeneous\n"
"\t5 - change the box's layout to horizontal maximum size homogeneous\n"
"\t6 - change the box's layout to vertical maximum size homogeneous\n"
"\t7 - change the box's layout to horizontal flow\n"
"\t8 - change the box's layout to vertical flow\n"
"\t9 - change the box's layout to stack\n"
"\t0 - change the box's layout to a custom-made one\n"
"\tCtrl + NUMBER - insert a new child object at that position in the box\n"
"\tShift + NUMBER - remove the child object at that position in the box\n"
"\th - print help\n";
struct exemple_data
{
Ecore_Evas *ee;
Evas *evas;
Evas_Object *bg, *box, *border;
};
static struct exemple_data d;
static void /* custom 'diagonal' layout */
_custom_layout(Evas_Object *o,
Evas_Object_Box_Data *p,
void *data __UNUSED__)
{
int x, y, w, h;
int xx, yy, ww, hh;
int count;
Eina_List *l;
Evas_Object_Box_Option *opt;
evas_object_geometry_get(o, &x, &y, &w, &h);
count = eina_list_count(p->children);
ww = w / (count ? : 1);
hh = h / (count ? : 1);
if (ww < 1) ww = 1;
if (hh < 1) hh = 1;
xx = x;
yy = y;
EINA_LIST_FOREACH(p->children, l, opt)
{
evas_object_move(opt->obj, xx, yy);
xx += ww;
yy += hh;
}
}
static Evas_Object * /* new rectangle to be put in the box */
_new_rectangle_add(Evas *e)
{
Evas_Object *o;
o = evas_object_rectangle_add(e);
evas_object_resize(o, 10, 10);
evas_object_color_set(o, 0, 255, 0, 255);
evas_object_show(o);
return o;
}
/* use the following commands to interact with this example - 'h' is
* the key for help */
static void
_on_keydown(void *data __UNUSED__,
Evas *evas __UNUSED__,
Evas_Object *o __UNUSED__,
void *einfo)
{
Evas_Event_Key_Down *ev = einfo;
const Evas_Modifier *mods = evas_key_modifier_get(evas);
if (strcmp(ev->keyname, "h") == 0) /* print help */
{
fprintf(stdout, commands);
return;
}
if (evas_key_modifier_is_set(mods, "Shift"))
{
int pos;
Eina_Bool ret;
Evas_Object *obj;
Eina_List *children;
pos = atoi(ev->keyname);
children = evas_object_box_children_get(d.box);
obj = eina_list_nth(children, pos);
if (!obj) goto list_free;
ret = evas_object_box_remove_at(d.box, pos);
if (ret) evas_object_del(obj);
list_free:
eina_list_free(children);
return;
}
if (evas_key_modifier_is_set(mods, "Control"))
{
Evas_Object *o;
int pos;
pos = atoi(ev->keyname);
o = _new_rectangle_add(d.evas);
if (!evas_object_box_insert_at(d.box, o, pos))
evas_object_box_append(d.box, o);
return;
}
if (strcmp(ev->keyname, "a") == 0)
{
double h, v;
evas_object_box_align_get(d.box, &h, &v);
if (h == 0.5)
h = v = 1.0;
else if (h == 1.0)
h = v = -1.0;
else if (h == -1.0)
h = v = 0.0;
else if (h == 0.0)
h = v = 0.5;
evas_object_box_align_set(d.box, h, v);
fprintf(stdout, "Applying new alignment values (%.1f, %.1f)"
" on the box\n", h, v);
return;
}
if (strcmp(ev->keyname, "p") == 0)
{
int h, v;
evas_object_box_padding_get(d.box, &h, &v);
if (h == 0)
h = v = 50;
else
h = v = 0;
evas_object_box_padding_set(d.box, h, v);
fprintf(stdout, "Applying new padding values (%d, %d)"
" on the box\n", h, v);
return;
}
if (strcmp(ev->keyname, "1") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_horizontal, NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n", "horizontal");
return;
}
if (strcmp(ev->keyname, "2") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_vertical, NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n", "vertical");
return;
}
if (strcmp(ev->keyname, "3") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_homogeneous_horizontal, NULL,
NULL);
fprintf(stdout, "Applying '%s' layout on the box\n",
"horizontal homogeneous");
return;
}
if (strcmp(ev->keyname, "4") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_homogeneous_vertical, NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n",
"vertical homogeneous");
return;
}
if (strcmp(ev->keyname, "5") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_homogeneous_max_size_horizontal,
NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n",
"horizontal maximum size homogeneous");
return;
}
if (strcmp(ev->keyname, "6") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_homogeneous_max_size_vertical,
NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n",
"vertical maximum size homogeneous");
return;
}
if (strcmp(ev->keyname, "7") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_flow_horizontal, NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n", "horizontal flow");
return;
}
if (strcmp(ev->keyname, "8") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_flow_vertical, NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n", "vertical flow");
return;
}
if (strcmp(ev->keyname, "9") == 0)
{
evas_object_box_layout_set(
d.box, evas_object_box_layout_stack, NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n", "stack");
return;
}
if (strcmp(ev->keyname, "0") == 0)
{
evas_object_box_layout_set(d.box, _custom_layout, NULL, NULL);
fprintf(stdout, "Applying '%s' layout on the box\n", "CUSTOM");
return;
}
}
static void
_on_delete(Ecore_Evas *ee __UNUSED__)
{
ecore_main_loop_quit();
}
static void /* adjust canvas' contents on resizes */
_canvas_resize_cb(Ecore_Evas *ee)
{
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
evas_object_resize(d.bg, w, h);
evas_object_move(d.box, (w / 4), (h / 4));
evas_object_resize(d.box, (w / 2), (h / 2));
evas_object_move(d.border, (w / 4) - 2, (h / 4) - 2);
evas_object_resize(d.border, (w / 2) + 4, (h / 2) + 4);
}
int
main(void)
{
Evas_Object *last, *o;
int i;
srand(time(NULL));
if (!ecore_evas_init())
return EXIT_FAILURE;
/* this will give you a window with an Evas canvas under the first
* engine available */
d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
if (!d.ee)
goto panic;
ecore_evas_callback_delete_request_set(d.ee, _on_delete);
ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
ecore_evas_show(d.ee);
d.evas = ecore_evas_get(d.ee);
d.bg = evas_object_rectangle_add(d.evas);
evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
evas_object_show(d.bg);
evas_object_focus_set(d.bg, EINA_TRUE);
evas_object_event_callback_add(
d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
d.box = evas_object_box_add(d.evas);
evas_object_show(d.box);
for (i = 1; i <= 5; i++)
{
o = last = evas_object_rectangle_add(d.evas);
evas_object_size_hint_min_set(o, 50, 50);
evas_object_color_set(
o, rand() % 256, rand() % 256, rand() % 256, 255);
evas_object_show(o);
if (!evas_object_box_append(d.box, o))
{
fprintf(stderr, "Error appending child object on the box!\n");
goto error;
}
}
/* this is a border around the box, container of the rectangles we
* are going to experiment with. this way you can see how the
* container relates to the children */
d.border = evas_object_image_filled_add(d.evas);
evas_object_image_file_set(d.border, border_img_path, NULL);
evas_object_image_border_set(d.border, 2, 2, 2, 2);
evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
evas_object_show(d.border);
fprintf(stdout, commands);
_canvas_resize_cb(d.ee);
ecore_main_loop_begin();
ecore_evas_shutdown();
return 0;
error:
ecore_evas_shutdown();
return -1;
panic:
fprintf(stderr, "You got to have at least one evas engine built and linked"
" up to ecore-evas for this example to run properly.\n");
return -2;
}

@ -0,0 +1,228 @@
/**
* Simple Evas example using the Buffer engine.
*
* You must have Evas compiled with the buffer engine, and have the
* evas-software-buffer pkg-config files installed.
*
* Compile with:
*
* @verbatim
* gcc -o evas-buffer-simple evas-buffer-simple.c `pkg-config --libs --cflags evas evas-software-buffer`
* @endverbatim
*
*/
#include <Evas.h>
#include <Evas_Engine_Buffer.h>
#include <stdio.h>
#include <errno.h>
#define WIDTH (320)
#define HEIGHT (240)
/*
* create_canvas(), destroy_canvas() and draw_scene() are support functions.
*
* They are only required to use raw Evas, but for real world usage,
* it is recommended to use ecore and its ecore-evas submodule, that
* provide convenience canvas creators, integration with main loop and
* automatic render of updates (draw_scene()) when system goes back to
* main loop.
*/
static Evas *create_canvas(int width, int height);
static void destroy_canvas(Evas *canvas);
static void draw_scene(Evas *canvas);
// support function to save scene as PPM image
static void save_scene(Evas *canvas, const char *dest);
int main(void)
{
Evas *canvas;
Evas_Object *bg, *r1, *r2, *r3;
evas_init();
// create your canvas
// NOTE: consider using ecore_evas_buffer_new() instead!
canvas = create_canvas(WIDTH, HEIGHT);
if (!canvas)
return -1;
bg = evas_object_rectangle_add(canvas);
evas_object_color_set(bg, 255, 255, 255, 255); // white bg
evas_object_move(bg, 0, 0); // at origin
evas_object_resize(bg, WIDTH, HEIGHT); // covers full canvas
evas_object_show(bg);
puts("initial scene, with just background:");
draw_scene(canvas);
r1 = evas_object_rectangle_add(canvas);
evas_object_color_set(r1, 255, 0, 0, 255); // 100% opaque red
evas_object_move(r1, 10, 10);
evas_object_resize(r1, 100, 100);
evas_object_show(r1);
// pay attention to transparency! Evas color values are pre-multiplied by
// alpha, so 50% opaque green is:
// non-premul: r=0, g=255, b=0 a=128 (50% alpha)
// premul:
// r_premul = r * a / 255 = 0 * 128 / 255 = 0
// g_premul = g * a / 255 = 255 * 128 / 255 = 128
// b_premul = b * a / 255 = 0 * 128 / 255 = 0
//
// this 50% green is over a red background, so it will show in the
// final output as yellow (green + red = yellow)
r2 = evas_object_rectangle_add(canvas);
evas_object_color_set(r2, 0, 128, 0, 128); // 50% opaque green
evas_object_move(r2, 10, 10);
evas_object_resize(r2, 50, 50);
evas_object_show(r2);
r3 = evas_object_rectangle_add(canvas);
evas_object_color_set(r3, 0, 128, 0, 255); // 100% opaque dark green
evas_object_move(r3, 60, 60);
evas_object_resize(r3, 50, 50);
evas_object_show(r3);
puts("final scene (note updates):");
draw_scene(canvas);
save_scene(canvas, "/tmp/evas-buffer-simple-render.ppm");
// NOTE: use ecore_evas_buffer_new() and here ecore_evas_free()
destroy_canvas(canvas);
evas_shutdown();
return 0;
}
static Evas *create_canvas(int width, int height)
{
Evas *canvas;
Evas_Engine_Info_Buffer *einfo;
int method;
void *pixels;
method = evas_render_method_lookup("buffer");
if (method <= 0)
{
fputs("ERROR: evas was not compiled with 'buffer' engine!\n", stderr);
return NULL;
}
canvas = evas_new();
if (!canvas)
{
fputs("ERROR: could not instantiate new evas canvas.\n", stderr);
return NULL;
}
evas_output_method_set(canvas, method);
evas_output_size_set(canvas, width, height);
evas_output_viewport_set(canvas, 0, 0, width, height);
einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas);
if (!einfo)
{
fputs("ERROR: could not get evas engine info!\n", stderr);
evas_free(canvas);
return NULL;
}
// ARGB32 is sizeof(int), that is 4 bytes, per pixel
pixels = malloc(width * height * sizeof(int));
if (!pixels)
{
fputs("ERROR: could not allocate canvas pixels!\n", stderr);
evas_free(canvas);
return NULL;
}
einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
einfo->info.dest_buffer = pixels;
einfo->info.dest_buffer_row_bytes = width * sizeof(int);
einfo->info.use_color_key = 0;
einfo->info.alpha_threshold = 0;
einfo->info.func.new_update_region = NULL;
einfo->info.func.free_update_region = NULL;
evas_engine_info_set(canvas, (Evas_Engine_Info *)einfo);
return canvas;
}
static void destroy_canvas(Evas *canvas)
{
Evas_Engine_Info_Buffer *einfo;
einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas);
if (!einfo)
{
fputs("ERROR: could not get evas engine info!\n", stderr);
evas_free(canvas);
return;
}
free(einfo->info.dest_buffer);
evas_free(canvas);
}
static void draw_scene(Evas *canvas)
{
Eina_List *updates, *n;
Eina_Rectangle *update;
// render and get the updated rectangles:
updates = evas_render_updates(canvas);
// informative only here, just print the updated areas:
EINA_LIST_FOREACH(updates, n, update)
printf("UPDATED REGION: pos: %3d, %3d size: %3dx%3d\n",
update->x, update->y, update->w, update->h);
// free list of updates
evas_render_updates_free(updates);
}
static void save_scene(Evas *canvas, const char *dest)
{
Evas_Engine_Info_Buffer *einfo;
const unsigned int *pixels, *pixels_end;
int width, height;
FILE *f;
einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas);
if (!einfo)
{
fputs("ERROR: could not get evas engine info!\n", stderr);
return;
}
evas_output_size_get(canvas, &width, &height);
f = fopen(dest, "wb+");
if (!f)
{
fprintf(stderr, "ERROR: could not open for writing '%s': %s\n",
dest, strerror(errno));
return;
}
pixels = einfo->info.dest_buffer;
pixels_end = pixels + (width * height);
// PPM P6 format is dead simple to write:
fprintf(f, "P6\n%d %d\n255\n", width, height);
for (; pixels < pixels_end; pixels++)
{
int r, g, b;
r = ((*pixels) & 0xff0000) >> 16;
g = ((*pixels) & 0x00ff00) >> 8;
b = (*pixels) & 0x0000ff;
fprintf(f, "%c%c%c", r, g, b);
}
fclose(f);
printf("saved scene as '%s'\n", dest);
}

@ -0,0 +1,413 @@
/**
* Simple Evas example illustrating how to interact with canvas' (and
* its objects') events and other canvas operations.
*
* You'll need at least one engine built for it (excluding the buffer
* one) and the png image loader also built. See stdout/stderr for
* output.
*
* @verbatim
* gcc -o evas-events evas-events.c `pkg-config --libs --cflags evas ecore ecore-evas`
* @endverbatim
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#define __UNUSED__
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <stdio.h>
#include <errno.h>
#define WIDTH (320)
#define HEIGHT (240)
static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
static const char *commands = \
"commands are:\n"
"\ta - toggle animation timer\n"
"\tc - cycle between focus and key grabs for key input\n"
"\td - delete canvas callbacks\n"
"\tf - freeze input for 3 seconds\n"
"\tp - toggle precise point collision detection on image\n"
"\tControl + o - add an obscured rectangle\n"
"\th - print help\n";
struct test_data
{
Ecore_Evas *ee;
Evas *canvas;
Evas_Object *img, *bg;
Ecore_Timer *resize_timer, *freeze_timer;
Eina_Bool obscured, focus;
};
static struct test_data d = {0};
/* here to keep our example's window size and background image's
* size in synchrony */
static void
_canvas_resize_cb(Ecore_Evas *ee)
{
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
evas_object_resize(d.bg, w, h);
}
/* called when our rectangle gets focus */
static void
_object_focus_in_cb(void *data __UNUSED__,
Evas *e,
void *event_info)
{
fprintf(stdout, "An object got focused: %s\n",
evas_object_name_get(event_info));
fprintf(stdout, "Let's recheck it: %s\n",
evas_object_name_get(evas_focus_get(e)));
fprintf(stdout, "And again: %s\n", evas_object_focus_get(event_info) ?
"OK!" : "Oops, something is bad.");
}
/* render flush callback */
static void
_render_flush_cb(void *data __UNUSED__,
Evas *e __UNUSED__,
void *event_info __UNUSED__)
{
fprintf(stdout, "Canvas is about to flush its rendering pipeline!\n");
}
/* put some action in the canvas */
static Eina_Bool
_resize_cb(void *data __UNUSED__)
{
int w, h, cw, ch;
evas_object_geometry_get(d.img, NULL, NULL, &w, &h);
ecore_evas_geometry_get(d.ee, NULL, NULL, &cw, &ch);
if (w < cw)
evas_object_resize(d.img, cw, ch);
else
evas_object_resize(d.img, cw / 2, ch / 2);
return EINA_TRUE; /* re-issue the timer */
}
/* let's have our events back */
static Eina_Bool
_thaw_cb(void *data __UNUSED__)
{
fprintf(stdout, "Canvas was frozen %d times, now thawing.\n",
evas_event_freeze_get(d.canvas));
evas_event_thaw(d.canvas);
return EINA_FALSE; /* do not re-issue the timer */
}
/* mouse enters the object's area */
static void
_on_mouse_in(void *data __UNUSED__,
Evas *evas __UNUSED__,
Evas_Object *o __UNUSED__,
void *einfo __UNUSED__)
{
fprintf(stdout, "Enlightenment logo has had the mouse in.\n");
}
static void
_on_mouse_out(void *data __UNUSED__,
Evas *evas __UNUSED__,
Evas_Object *o __UNUSED__,
void *einfo __UNUSED__)
{
fprintf(stdout, "Enlightenment logo has had the mouse out.\n");
} /* mouse exits the object's area */
/* examine the keys pressed */
static void
_on_keydown(void *data __UNUSED__,
Evas *evas,
Evas_Object *o __UNUSED__,
void *einfo)
{
const Evas_Modifier *mods;
Evas_Event_Key_Down *ev = einfo;
fprintf(stdout, "We've got key input: %s\n", ev->keyname);
fprintf(stdout, "It actually came from %s\n", d.focus ?
"focus" : "key grab");
if (strcmp(ev->keyname, "h") == 0) /* print help */
{
fprintf(stdout, commands);
return;
}
if (strcmp(ev->keyname, "a") == 0) /* toggle animation timer */
{
if (d.resize_timer != NULL)
{
fprintf(stdout, "Stopping animation timer\n");
ecore_timer_del(d.resize_timer);
d.resize_timer = NULL;
}
else
{
fprintf(stdout, "Re-issuing animation timer\n");
d.resize_timer = ecore_timer_add(2, _resize_cb, NULL);
}
return;
}
if (strcmp(ev->keyname, "c") == 0) /* cycle between focus and key
* grabs for key input */
{
Eina_Bool ret;
Evas_Modifier_Mask mask =
evas_key_modifier_mask_get(d.canvas, "Control");
fprintf(stdout, "Switching to %s for key input\n", d.focus ?
"key grabs" : "focus");
if (d.focus)
{
evas_object_focus_set(d.bg, EINA_FALSE);
fprintf(stdout, "Focused object is now %s\n",
evas_focus_get(d.canvas) ?
"still valid! Something went wrong." : "none.");
ret = evas_object_key_grab(d.bg, "a", 0, 0, EINA_TRUE);
if (!ret)
{
fprintf(stdout, "Something went wrong with key grabs.\n");
goto c_end;
}
ret = evas_object_key_grab(d.bg, "c", 0, 0, EINA_TRUE);
if (!ret)
{
fprintf(stdout, "Something went wrong with key grabs.\n");
goto c_end;
}
ret = evas_object_key_grab(d.bg, "d", 0, 0, EINA_TRUE);
if (!ret)
{
fprintf(stdout, "Something went wrong with key grabs.\n");
goto c_end;
}
ret = evas_object_key_grab(d.bg, "f", 0, 0, EINA_TRUE);
if (!ret)
{
fprintf(stdout, "Something went wrong with key grabs.\n");
goto c_end;
}
ret = evas_object_key_grab(d.bg, "p", 0, 0, EINA_TRUE);
if (!ret)
{
fprintf(stdout, "Something went wrong with key grabs.\n");
goto c_end;
}
ret = evas_object_key_grab(d.bg, "o", mask, 0, EINA_TRUE);
if (!ret)
{
fprintf(stdout, "Something went wrong with key grabs.\n");
goto c_end;
}
ret = evas_object_key_grab(d.bg, "h", 0, 0, EINA_TRUE);
if (!ret)
{
fprintf(stdout, "Something went wrong with key grabs.\n");
goto c_end;
}
}
else /* got here by key grabs */
{
evas_object_key_ungrab(d.bg, "a", 0, 0);
evas_object_key_ungrab(d.bg, "c", 0, 0);
evas_object_key_ungrab(d.bg, "d", 0, 0);
evas_object_key_ungrab(d.bg, "f", 0, 0);
evas_object_key_ungrab(d.bg, "p", 0, 0);
evas_object_key_ungrab(d.bg, "o", mask, 0);
evas_object_key_ungrab(d.bg, "h", 0, 0);
evas_object_focus_set(d.bg, EINA_TRUE);
}
c_end:
d.focus = !d.focus;
return;
}
if (strcmp(ev->keyname, "d") == 0) /* delete canvas' callbacks */
{
fprintf(stdout, "Deleting canvas event callbacks\n");
evas_event_callback_del_full(evas, EVAS_CALLBACK_RENDER_FLUSH_PRE,
_render_flush_cb, NULL);
evas_event_callback_del_full(
evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
_object_focus_in_cb, NULL);
return;
}
if (strcmp(ev->keyname, "f") == 0) /* freeze input for 3 seconds */
{
fprintf(stdout, "Freezing input for 3 seconds\n");
evas_event_freeze(evas);
d.freeze_timer = ecore_timer_add(3, _thaw_cb, NULL);
return;
}
if (strcmp(ev->keyname, "p") == 0) /* toggle precise point
* collision detection */
{
Eina_Bool precise = evas_object_precise_is_inside_get(d.img);
fprintf(stdout, "Toggling precise point collision detection %s on"
" Enlightenment logo\n", precise ? "off" : "on");
evas_object_precise_is_inside_set(d.img, !precise);
return;
}
mods = evas_key_modifier_get(evas);
if (evas_key_modifier_is_set(mods, "Control") &&
(strcmp(ev->keyname, "o") == 0)) /* add an obscured
* rectangle to the middle
* of the canvas */
{
fprintf(stdout, "Toggling obscured rectangle on canvas\n");
if (!d.obscured)
{
int w, h;
evas_output_viewport_get(evas, NULL, NULL, &w, &h);
evas_obscured_rectangle_add(evas, w / 4, h / 4, w / 2, h / 2);
}
else
{
int w, h;
Eina_Rectangle *rect;
Eina_List *updates, *l;
evas_output_viewport_get(evas, NULL, NULL, &w, &h);
evas_obscured_clear(evas);
/* we have to flag a damage region here because
* evas_obscured_clear() doesn't change the canvas'
* state. we'd have to wait for an animation step, for
* example, to get the result, without it */
evas_damage_rectangle_add(evas, 0, 0, w, h);
updates = evas_render_updates(evas);
EINA_LIST_FOREACH(updates, l, rect)
{
fprintf(stdout, "Rectangle (%d, %d, %d, %d) on canvas got a"
" rendering update.\n", rect->x, rect->y,
rect->w,
rect->h);
}
evas_render_updates_free(updates);
}
d.obscured = !d.obscured;
} /* end of obscured region command */
}
int
main(void)
{
int err;
if (!ecore_evas_init())
return EXIT_FAILURE;
/* this will give you a window with an Evas canvas under the first
* engine available */
d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
if (!d.ee)
goto error;
ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
ecore_evas_show(d.ee);
/* the canvas pointer, de facto */
d.canvas = ecore_evas_get(d.ee);
evas_event_callback_add(d.canvas, EVAS_CALLBACK_RENDER_FLUSH_PRE,
_render_flush_cb, NULL);
if (evas_alloc_error() != EVAS_ALLOC_ERROR_NONE)
{
fprintf(stderr, "ERROR: Callback registering failed! Aborting.\n");
goto panic;
}
evas_event_callback_add(d.canvas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
_object_focus_in_cb, NULL);
if (evas_alloc_error() != EVAS_ALLOC_ERROR_NONE)
{
fprintf(stderr, "ERROR: Callback registering failed! Aborting.\n");
goto panic;
} /* two canvas event callbacks */
d.bg = evas_object_rectangle_add(d.canvas);
evas_object_name_set(d.bg, "our dear rectangle");
evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
evas_object_move(d.bg, 0, 0); /* at canvas' origin */