Evas objects basic manipulation example

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

Evas objects basic manipulation example
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#endif
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <stdio.h>
#include <errno.h>
#include "evas-common.h"
#define WIDTH (320)
#define HEIGHT (240)
static const char *img_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/enlightenment.png";
static const char *border_img_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/red.png";
struct test_data
{
Ecore_Evas *ee;
Evas *canvas;
Evas_Object *img, *bg, *clipper, *clipper_border, *text;
};
static struct test_data d = {0};
/* Keep the example's window size in sync with the background image's size */
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);
}
/* Keyboard event callback routine, to enable the user to toggle various
* object properties on the clipper object.
*/
static void
_on_keydown(void *data EINA_UNUSED,
Evas *evas EINA_UNUSED,
Evas_Object *o EINA_UNUSED,
void *einfo)
{
Evas_Event_Key_Down *ev = einfo;
if (strcmp(ev->key, "h") == 0)
{
/* h - print help */
printf("commands are:\n"
"\to - change clipper's opacity\n"
"\tr - toggle clipper's color between red and white\n"
"\tc - toggle clipper's clipping function\n"
"\tv - toggle clipper's visibility\n");
return;
}
if (strcmp(ev->key, "o") == 0)
{
/* o - Change clipper's opacity */
int alpha, r, g, b;
evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
evas_color_argb_unpremul(alpha, &r, &g, &b);
alpha -= 20;
if (alpha < 0)
alpha = 255;
evas_color_argb_premul(alpha, &r, &g, &b);
evas_object_color_set(d.clipper, r, g, b, alpha);
printf("Changing clipper's opacity: %d%%\n",
(int)((alpha / 255.0) * 100));
return;
}
if (strcmp(ev->key, "r") == 0)
{
/* r - Toggle clipper's color between red and white */
int alpha, r, g, b;
printf("Changing clipper's color to");
evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
evas_color_argb_unpremul(alpha, &r, &g, &b);
if (g > 0)
{
printf("red\n");
g = b = 0;
}
else
{
printf("white\n");
g = b = 255;
}
evas_color_argb_premul(alpha, &r, &g, &b);
evas_object_color_set(d.clipper, r, g, b, alpha);
return;
}
if (strcmp(ev->key, "c") == 0)
{
/* o - Toggle clipper's clipping function */
printf("Toggling clipping ");
if (evas_object_clip_get(d.img) == d.clipper)
{
evas_object_clip_unset(d.img);
printf("off\n");
}
else
{
evas_object_clip_set(d.img, d.clipper);
printf("on\n");
}
return;
}
if (strcmp(ev->key, "v") == 0)
{
/* v - Toggle clipper's visibility */
printf("Clipper is now ");
if (evas_object_visible_get(d.clipper))
{
evas_object_hide(d.clipper);
printf("hidden\n");
}
else
{
evas_object_show(d.clipper);
printf("visible\n");
}
return;
}
}
int
main(void)
{
int err;
if (!ecore_evas_init())
return EXIT_FAILURE;
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);
d.canvas = ecore_evas_get(d.ee);
/* Create background. As mentioned earlier, the evas_object_*
* routines are part of the legacy Evas API; with the new API
* you should use code as shown in evas-object-manipulation-eo.c.
*/
d.bg = evas_object_rectangle_add(d.canvas);
evas_object_name_set(d.bg, "background rectangle");
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);
/* Load enlightenment.png as an image object, then make it fill the
* whole canvas area.
*/
d.img = evas_object_image_filled_add(d.canvas);
evas_object_image_file_set(d.img, img_path, NULL);
err = evas_object_image_load_error_get(d.img);
if (err != EVAS_LOAD_ERROR_NONE)
{
goto panic;
}
else
{
evas_object_move(d.img, 0, 0);
evas_object_resize(d.img, WIDTH, HEIGHT);
evas_object_show(d.img);
printf("Image object added, type is: %s\n",
evas_object_type_get(d.img));
}
/* Add a second image to the canvas - a red square this time. It
* will be given a border to emphasize its position.
*/
d.clipper_border = evas_object_image_filled_add(d.canvas);
evas_object_image_file_set(d.clipper_border, border_img_path, NULL);
err = evas_object_image_load_error_get(d.clipper_border);
if (err != EVAS_LOAD_ERROR_NONE)
{
goto panic;
}
else
{
evas_object_image_border_set(d.clipper_border, 3, 3, 3, 3);
evas_object_image_border_center_fill_set(
d.clipper_border, EVAS_BORDER_FILL_NONE);
evas_object_move(d.clipper_border, (WIDTH / 4) - 3, (HEIGHT / 4) - 3);
evas_object_resize(
d.clipper_border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
evas_object_show(d.clipper_border);
}
/* Lastly, add a rectangle. It will be white (the default color for
* rectangles) and so won't change the color of anything it clips.
*/
d.clipper = evas_object_rectangle_add(d.canvas);
evas_object_move(d.clipper, WIDTH / 4, HEIGHT / 4);
evas_object_resize(d.clipper, WIDTH / 2, HEIGHT / 2);
evas_object_clip_set(d.img, d.clipper);
evas_object_show(d.clipper);
ecore_main_loop_begin();
ecore_evas_free(d.ee);
ecore_evas_shutdown();
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");
panic:
ecore_evas_free(d.ee);
ecore_evas_shutdown();
return -1;
}
Ecore_Evas.h
Evas wrapper functions.
EVAS_CALLBACK_KEY_DOWN
@ EVAS_CALLBACK_KEY_DOWN
Key Press Event.
Definition: Evas_Common.h:430
ecore_evas_init
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition: ecore_evas.c:602
ecore_evas_show
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition: ecore_evas.c:1480
ecore_evas_get
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition: ecore_evas.c:1300
ecore_evas_geometry_get
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
ecore_evas_new
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
ecore_evas_callback_resize_set
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
ecore_evas_shutdown
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition: ecore_evas.c:666
ecore_evas_free
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition: ecore_evas.c:1083
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
Evas
Eo Evas
An opaque handle to an Evas canvas.
Definition: Evas_Common.h:163
EVAS_LOAD_ERROR_NONE
@ EVAS_LOAD_ERROR_NONE
No error on load.
Definition: Evas_Loader.h:141
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
evas_object_type_get
EVAS_API const char * evas_object_type_get(const Evas_Object *eo_obj)
Retrieves the type of the given Evas object.
Definition: evas_object_main.c:2558
evas_object_name_set
EVAS_API void evas_object_name_set(Evas_Object *eo_obj, const char *name)
Sets the name of the given Evas object to the given name.
Definition: evas_name.c:5
evas_object_color_set
EVAS_API void evas_object_color_set(Evas_Object *obj, int r, int g, int b, int a)
Sets the general/main color of the given Evas object to the given one.
Definition: evas_object_main.c:2024
evas_object_color_get
EVAS_API void evas_object_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
Retrieves the general/main color of the given Evas object.
Definition: evas_object_main.c:2071
evas_object_hide
EVAS_API void evas_object_hide(Evas_Object *eo_obj)
Makes the given Evas object invisible.
Definition: evas_object_main.c:1823
evas_object_event_callback_add
EVAS_API void evas_object_event_callback_add(Evas_Object *eo_obj, Evas_Callback_Type type, Evas_Object_Event_Cb func, const void *data)
Add (register) a callback function to a given Evas object event.
Definition: evas_callbacks.c:478
evas_object_clip_unset
EVAS_API void evas_object_clip_unset(Evas_Object *eo_obj)
Disable/cease clipping on a clipped obj object.
Definition: evas_clip.c:463
evas_object_move
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition: evas_object_main.c:1171
evas_object_clip_set
EVAS_API void evas_object_clip_set(Efl_Canvas_Object *obj, Efl_Canvas_Object *clipper)
Clip one object to another.
Definition: efl_canvas_object_eo.legacy.c:15
evas_object_visible_get
EVAS_API Eina_Bool evas_object_visible_get(const Evas_Object *obj)
Retrieves whether or not the given Evas object is visible.
Definition: evas_object_main.c:1830
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
evas_object_focus_set
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
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
evas_object_clip_get
EVAS_API Efl_Canvas_Object * evas_object_clip_get(const Efl_Canvas_Object *obj)
Get the object clipping obj (if any).
Definition: efl_canvas_object_eo.legacy.c:21
evas_object_image_border_set
EVAS_API void evas_object_image_border_set(Evas_Object *obj, int l, int r, int t, int b)
Dimensions of this image's border, a region that does not scale with the center area.
Definition: evas_image_legacy.c:117
evas_object_image_load_error_get
EVAS_API Evas_Load_Error evas_object_image_load_error_get(const Evas_Object *obj)
Retrieves a number representing any error that occurred during the last loading of the given image ob...
Definition: evas_image_legacy.c:400
evas_object_image_border_center_fill_set
EVAS_API void evas_object_image_border_center_fill_set(Evas_Object *obj, Evas_Border_Fill_Mode fill)
Specifies how the center part of the object (not the borders) should be drawn when EFL is rendering i...
Definition: evas_image_legacy.c:145
evas_object_image_file_set
EVAS_API void evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
Set the source file from where an image object must fetch the real image data (it may be an Eet file,...
Definition: evas_image_legacy.c:194
evas_object_image_filled_add
EVAS_API Evas_Object * evas_object_image_filled_add(Evas *eo_e)
Creates a new image object that automatically scales its bound image to the object's area,...
Definition: evas_image_legacy.c:35
EVAS_BORDER_FILL_NONE
@ EVAS_BORDER_FILL_NONE
Image's center region is not to be rendered.
Definition: Evas_Legacy.h:5721
evas_object_rectangle_add
EVAS_API Evas_Object * evas_object_rectangle_add(Evas *e)
Adds a rectangle to the given evas.
Definition: evas_object_rectangle.c:78
evas_color_argb_unpremul
EVAS_API void evas_color_argb_unpremul(int a, int *r, int *g, int *b)
Undo pre-multiplication of a rgb triplet by an alpha factor.
Definition: evas_main.c:1016
evas_color_argb_premul
EVAS_API void evas_color_argb_premul(int a, int *r, int *g, int *b)
Pre-multiplies a rgb triplet by an alpha factor.
Definition: evas_main.c:1010
_Evas_Event_Key_Down
Key press event.
Definition: Evas_Legacy.h:314
_Evas_Event_Key_Down::key
const char * key
The logical key : (eg shift+1 == exclamation)
Definition: Evas_Legacy.h:320