In this example, we illustrate how to stack objects in a custom manner and how to deal with layers.
We have three objects of interest in it – white background, red rectangle, green rectangle and blue rectangle.
At any given point, like seem above, you'll be operating one rectangle only. You may stacking it below an adjacent object with "b":
At any time, use the "s" command to see the status of the ordering. It will show the background's ordering too. Note that it also shows the layer for this object. It starts at a different layer than the others. Use "l" to change its layer (higher layer numbers mean higher layers). If the background is on the same layer as the others (0), you'll see it interact with them on the ordering. If it's in the layer above, no matter what you do, you'll see nothing but the white rectangle: it covers the other layers. For the initial layer (-1), it will never mess nor occlude the others.
Let's make some tests with those commands. The rectangle which starts selected and which will receive our commands is the red one. It starts stacked above all the others, like seem above:
Note how the rectangle which laid above it, the green one, is now on top of it. Now change the rectangle to operate on to the blue one, with two consecutive 'c' commands. Note that it's the lowest one on the stack of rectangles. Issue the 'a' command for it, thus re-stacking it one level above:
Like said above, we have two layers used at the beginning of the example: the default one (0) and the one immediately below it (-1), for the white background. Let's change this setup by issuing the 'l' command, which will change the background's layer to 1, i.e., a layer above the one holding the other rectangles:
See how it now covers everything else. Press 'l' again, taking it now to layer 0. It's still covering everything because it lands the layer as the highest one on the objects stack. As we have the blue rectangle as the one receiving stacking commands, hit 't' and you'll see it again:
The last two commands available are "p" and "r", which will make the target rectangle to pass (ignore) and repeat the mouse events occurring on it (the commands will cycle through on and off states). This is demonstrated with the following EVAS_CALLBACK_MOUSE_DOWN callback, registered on each of the colored rectangles:
Try to change these properties on the three rectangles while experimenting with mouse clicks on their intersection region.
The full example follows.
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#endif
#include <Ecore.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define WIDTH 320
#define HEIGHT 320
struct test_data
{
Ecore_Evas *ee;
int layers[3];
int cur_rect, cur_layer;
};
static struct test_data d = {0};
static const char *commands = \
"commands are:\n"
"\tc - change the target rectangle to operate on\n"
"\ta - stack target rectangle one level above\n"
"\tb - stack target rectangle one level below\n"
"\tt - stack target rectangle up to the top of its layer\n"
"\tm - stack target rectangle down to the bottom of its layer\n"
"\tp - toggle target rectangle's 'pass events' property\n"
"\tr - toggle target rectangle's 'repeat events' property\n"
"\ts - print current stacking information\n"
"\tl - change background rectangle's layer\n"
"\th - print help\n";
static const char *
{
if (!s) s = "(null)";
return s;
}
static void
{
printf("Mouse down on rectangle %s!\n", _name_get(o));
}
static void
_canvas_resize_cb(Ecore_Evas *ee)
{
int w, h;
}
static void
void *einfo)
{
const char *name = _name_get(d.rects[d.cur_rect]);
if (strcmp(ev->
key,
"h") == 0)
{
printf("%s\n", commands);
return;
}
if (strcmp(ev->
key,
"s") == 0)
{
printf("Order of stacking, from top to bottom, is: ");
printf("%s", _name_get(rect));
while (rect)
{
printf(", %s", _name_get(rect));
}
printf(".\n");
printf("Current target rectangle is %s\n",
_name_get(d.rects[d.cur_rect]));
printf("Background rectangle's layer is %d\n",
return;
}
if (strcmp(ev->
key,
"l") == 0)
{
d.cur_layer = (d.cur_layer + 1) % 3;
printf("Changing background rectangle's layer to %d\n",
d.layers[d.cur_layer]);
return;
}
if (strcmp(ev->
key,
"c") == 0)
{
d.cur_rect = (d.cur_rect + 1) % 3;
printf("Changing target rectangle to the %s one\n",
_name_get(d.rects[d.cur_rect]));
return;
}
if (strcmp(ev->
key,
"t") == 0)
{
printf("%s rectangle was re-stacked to the top if its layer\n",
name);
printf("Below of %s rect is %s\n", name,
neighbour ? _name_get(neighbour) : "no object");
return;
}
if (strcmp(ev->
key,
"m") == 0)
{
printf("%s rectangle was re-stacked to the bottom if its layer\n",
name);
printf("Below of %s rect is %s\n", name,
neighbour ? _name_get(neighbour) : "no object");
return;
}
if (strcmp(ev->
key,
"p") == 0)
{
printf("%s rectangle is now set to%s pass (ignore) events\n",
name, pass ? " NOT" : "");
return;
}
if (strcmp(ev->
key,
"r") == 0)
{
printf("%s rectangle is now set to%s repeat events\n",
name, repeat ? " NOT" : "");
return;
}
if (strcmp(ev->
key,
"a") == 0)
{
return;
printf("%s rectangle was re-stacked one level above\n", name);
printf("Above of %s rect is %s\n", name,
neighbour ? _name_get(neighbour) : "no object");
printf("Below of %s rect is %s\n", name,
neighbour ? _name_get(neighbour) : "no object");
return;
}
if (strcmp(ev->
key,
"b") == 0)
{
return;
printf("%s rectangle was re-stacked one level below\n", name);
printf("Above of %s rect is %s\n", name,
neighbour ? _name_get(neighbour) : "no object");
printf("Below of %s rect is %s\n", name,
neighbour ? _name_get(neighbour) : "no object");
return;
}
}
static void
{
}
int
main(void)
{
return EXIT_FAILURE;
if (!d.ee)
goto error;
d.layers[1] = d.layers[0] - 1;
d.layers[2] = d.layers[0] + 1;
d.cur_layer = 1;
printf("%s\n", commands);
return 0;
error:
fprintf(stderr, "error: Requires at least one Evas engine built and linked"
" to ecore-evas for this example to run properly.\n");
return -1;
}
@ EVAS_CALLBACK_KEY_DOWN
Key Press Event.
Definition: Evas_Common.h:430
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition: ecore_evas.c:602
EAPI void ecore_evas_callback_destroy_set(Ecore_Evas *ee, Ecore_Evas_Event_Cb func)
Sets a callback for Ecore_Evas destroy events.
Definition: ecore_evas.c:1185
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition: ecore_evas.c:1480
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition: ecore_evas.c:1300
EAPI void ecore_evas_geometry_get(const Ecore_Evas *ee, int *x, int *y, int *w, int *h)
Gets the geometry of an Ecore_Evas.
Definition: ecore_evas.c:1362
EAPI Ecore_Evas * ecore_evas_new(const char *engine_name, int x, int y, int w, int h, const char *extra_options)
Creates a new Ecore_Evas based on engine name and common parameters.
Definition: ecore_evas.c:1039
EAPI void ecore_evas_callback_resize_set(Ecore_Evas *ee, Ecore_Evas_Event_Cb func)
Sets a callback for Ecore_Evas resize events.
Definition: ecore_evas.c:1140
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition: ecore_evas.c:666
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition: ecore_main.c:1321
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
EVAS_API Efl_Canvas_Object * evas_object_top_get(const Evas_Canvas *obj)
Get the highest (stacked) Evas object on the canvas e.
Definition: evas_canvas_eo.legacy.c:63
EVAS_API const char * evas_object_name_get(const Evas_Object *eo_obj)
Retrieves the name of the given Evas object.
Definition: evas_name.c:26
EVAS_API Eina_Bool evas_object_pass_events_get(const Efl_Canvas_Object *obj)
Determine whether an object is set to pass (ignore) events.
Definition: efl_canvas_object_eo.legacy.c:82
EVAS_API Evas_Object * evas_object_below_get(const Evas_Object *obj)
Get the Evas object stacked right below obj.
Definition: evas_stack.x:352
EVAS_API void evas_object_layer_set(Evas_Object *obj, short l)
Sets the layer of its canvas that the given object will be part of.
Definition: evas_layer.c:212
EVAS_API Evas_Object * evas_object_above_get(const Evas_Object *obj)
Get the Evas object stacked right above obj.
Definition: evas_stack.x:323
EVAS_API void evas_object_pass_events_set(Efl_Canvas_Object *obj, Eina_Bool pass)
Set whether an Evas object is to pass (ignore) events.
Definition: efl_canvas_object_eo.legacy.c:76
EVAS_API short evas_object_layer_get(const Evas_Object *obj)
Retrieves the layer of its canvas that the given object is part of.
Definition: evas_layer.c:269
EVAS_API Eina_Bool evas_object_repeat_events_get(const Efl_Canvas_Object *obj)
Determine whether an object is set to repeat events.
Definition: efl_canvas_object_eo.legacy.c:33
EVAS_API void evas_object_repeat_events_set(Efl_Canvas_Object *obj, Eina_Bool repeat)
Set whether an Evas object is to repeat events.
Definition: efl_canvas_object_eo.legacy.c:27
EVAS_API void evas_object_focus_set(Efl_Canvas_Object *obj, Eina_Bool focus)
Indicates that this object is the keyboard event receiver on its canvas.
Definition: efl_canvas_object_eo.legacy.c:39
Key press event.
Definition: Evas_Legacy.h:314
const char * key
The logical key : (eg shift+1 == exclamation)
Definition: Evas_Legacy.h:320