2012-11-14 12:12:53 -08:00
|
|
|
/**
|
2017-05-08 15:25:12 -07:00
|
|
|
* Example of basic object manipulation in Evas.
|
2012-11-14 12:12:53 -08:00
|
|
|
*
|
2017-07-10 01:02:20 -07:00
|
|
|
* The evas-buffer-simple.c example shows how to manually create and
|
|
|
|
* manage buffers, but mentioned that real code would use higher level
|
|
|
|
* functionality from Ecore's Ecore-Evas submodule. This example
|
|
|
|
* shows the use of that submodule to create an Evas canvas and
|
|
|
|
* manipulate the objects within it.
|
|
|
|
*
|
|
|
|
* Please note that this example uses Evas' legacy API. Compare this
|
|
|
|
* implementation with evas-object-manipulation-eo.c to learn how the
|
|
|
|
* new Eo API is used.
|
|
|
|
*
|
2012-11-14 12:12:53 -08:00
|
|
|
* 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-object-manipulation evas-object-manipulation.c `pkg-config --libs --cflags ecore evas ecore-evas`
|
|
|
|
* @endverbatim
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2015-02-20 08:59:27 -08:00
|
|
|
#include "evas-common.h"
|
2012-11-14 12:12:53 -08:00
|
|
|
|
|
|
|
#define WIDTH (320)
|
|
|
|
#define HEIGHT (240)
|
|
|
|
|
2015-02-20 08:59:27 -08:00
|
|
|
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";
|
2012-11-14 12:12:53 -08:00
|
|
|
|
|
|
|
struct test_data
|
|
|
|
{
|
|
|
|
Ecore_Evas *ee;
|
|
|
|
Evas *canvas;
|
|
|
|
Evas_Object *img, *bg, *clipper, *clipper_border, *text;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_data d = {0};
|
|
|
|
|
2017-05-11 22:42:29 -07:00
|
|
|
/* Keep the example's window size in sync with the background image's size */
|
2012-11-14 12:12:53 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* Keyboard event callback routine, to enable the user to toggle various
|
|
|
|
* object properties on the clipper object.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
static void
|
2012-12-30 17:40:50 -08:00
|
|
|
_on_keydown(void *data EINA_UNUSED,
|
|
|
|
Evas *evas EINA_UNUSED,
|
|
|
|
Evas_Object *o EINA_UNUSED,
|
2012-11-14 12:12:53 -08:00
|
|
|
void *einfo)
|
|
|
|
{
|
|
|
|
Evas_Event_Key_Down *ev = einfo;
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
if (strcmp(ev->key, "h") == 0)
|
2012-11-14 12:12:53 -08:00
|
|
|
{
|
2017-07-10 01:02:20 -07:00
|
|
|
/* h - print help */
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("commands are:\n"
|
2017-05-10 02:03:37 -07:00
|
|
|
"\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");
|
2012-11-14 12:12:53 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
if (strcmp(ev->key, "o") == 0)
|
2012-11-14 12:12:53 -08:00
|
|
|
{
|
2017-07-10 01:02:20 -07:00
|
|
|
/* o - Change clipper's opacity */
|
2012-11-14 12:12:53 -08:00
|
|
|
int alpha, r, g, b;
|
|
|
|
|
|
|
|
evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
|
2013-11-22 15:07:14 -08:00
|
|
|
evas_color_argb_unpremul(alpha, &r, &g, &b);
|
|
|
|
|
2012-11-14 12:12:53 -08:00
|
|
|
alpha -= 20;
|
|
|
|
if (alpha < 0)
|
|
|
|
alpha = 255;
|
|
|
|
|
2013-11-22 15:07:14 -08:00
|
|
|
evas_color_argb_premul(alpha, &r, &g, &b);
|
2012-11-14 12:12:53 -08:00
|
|
|
evas_object_color_set(d.clipper, r, g, b, alpha);
|
|
|
|
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("Changing clipper's opacity: %d%%\n",
|
2012-11-14 12:12:53 -08:00
|
|
|
(int)((alpha / 255.0) * 100));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
if (strcmp(ev->key, "r") == 0)
|
2012-11-14 12:12:53 -08:00
|
|
|
{
|
2017-07-10 01:02:20 -07:00
|
|
|
/* r - Toggle clipper's color between red and white */
|
2012-11-14 12:12:53 -08:00
|
|
|
int alpha, r, g, b;
|
|
|
|
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("Changing clipper's color to");
|
2012-11-14 12:12:53 -08:00
|
|
|
|
|
|
|
evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
|
2013-11-22 15:07:14 -08:00
|
|
|
evas_color_argb_unpremul(alpha, &r, &g, &b);
|
|
|
|
|
2012-11-14 12:12:53 -08:00
|
|
|
if (g > 0)
|
|
|
|
{
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("red\n");
|
2012-11-14 12:12:53 -08:00
|
|
|
g = b = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("white\n");
|
2012-11-14 12:12:53 -08:00
|
|
|
g = b = 255;
|
|
|
|
}
|
|
|
|
|
2013-11-22 15:07:14 -08:00
|
|
|
evas_color_argb_premul(alpha, &r, &g, &b);
|
2012-11-14 12:12:53 -08:00
|
|
|
evas_object_color_set(d.clipper, r, g, b, alpha);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
if (strcmp(ev->key, "c") == 0)
|
2012-11-14 12:12:53 -08:00
|
|
|
{
|
2017-07-10 01:02:20 -07:00
|
|
|
/* o - Toggle clipper's clipping function */
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("Toggling clipping ");
|
2012-11-14 12:12:53 -08:00
|
|
|
|
|
|
|
if (evas_object_clip_get(d.img) == d.clipper)
|
|
|
|
{
|
|
|
|
evas_object_clip_unset(d.img);
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("off\n");
|
2012-11-14 12:12:53 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_clip_set(d.img, d.clipper);
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("on\n");
|
2012-11-14 12:12:53 -08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
if (strcmp(ev->key, "v") == 0)
|
2012-11-14 12:12:53 -08:00
|
|
|
{
|
2017-07-10 01:02:20 -07:00
|
|
|
/* v - Toggle clipper's visibility */
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("Clipper is now ");
|
2012-11-14 12:12:53 -08:00
|
|
|
|
|
|
|
if (evas_object_visible_get(d.clipper))
|
|
|
|
{
|
|
|
|
evas_object_hide(d.clipper);
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("hidden\n");
|
2012-11-14 12:12:53 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_show(d.clipper);
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("visible\n");
|
2012-11-14 12:12:53 -08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* In other examples, evas_init() has been used to turn Evas on. In this
|
|
|
|
* example we're using Ecore-Evas' init routine, which takes care of
|
|
|
|
* bringing up Evas.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
if (!ecore_evas_init())
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* In the evas-buffer-simple.c example, we coded our own
|
|
|
|
* create_canvas() routine. Here we make use of Ecore-Evas's
|
|
|
|
* ecore_evas_new() routine to do it. The first argument of this
|
|
|
|
* function is used to specify the name of an engine we wish to use;
|
|
|
|
* by passing NULL instead, we are requesting a window with an Evas
|
|
|
|
* canvas using the first engine available.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
|
|
|
|
if (!d.ee)
|
|
|
|
goto error;
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* Like other windowing systems, Ecore-Evas provides hooks for a
|
|
|
|
* number of different events. We can register our own functions to
|
|
|
|
* be called when the events occur in our window.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
|
|
|
|
ecore_evas_show(d.ee);
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* Retrieve a pointer to the canvas we created. */
|
2012-11-14 12:12:53 -08:00
|
|
|
d.canvas = ecore_evas_get(d.ee);
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* 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.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
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);
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* Callbacks can also be set on Evas objects. We'll add a keyboard
|
|
|
|
* handler routine to the background rectangle, for processing user
|
|
|
|
* key hits.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
evas_object_focus_set(d.bg, EINA_TRUE);
|
|
|
|
evas_object_event_callback_add(
|
|
|
|
d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* Load enlightenment.png as an image object, then make it fill the
|
|
|
|
* whole canvas area.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
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);
|
|
|
|
|
2017-04-19 22:21:21 -07:00
|
|
|
printf("Image object added, type is: %s\n",
|
2012-11-14 12:12:53 -08:00
|
|
|
evas_object_type_get(d.img));
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* Add a second image to the canvas - a red square this time. It
|
|
|
|
* will be given a border to emphasize its position.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-07-10 01:02:20 -07:00
|
|
|
/* Lastly, add a rectangle. It will be white (the default color for
|
|
|
|
* rectangles) and so won't change the color of anything it clips.
|
|
|
|
*/
|
2012-11-14 12:12:53 -08:00
|
|
|
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, "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();
|
|
|
|
return -1;
|
|
|
|
}
|