In this example, we have three images on the canvas, but one of them is special – we're using it as a proxy image object. It will mirror the contents of the other two images (which are the ones on the top of the canvas), one at a time:
As in other examples, we have a command line interface on it.
The 'p' one will change the source of the proxy image to one of the other two, as seem above.
Since we are creating the data for its pixel buffer ourselves, we have to set its size with evas_object_image_size_set(), first. We set our data with the function evas_object_image_data_set(), where the second argument is a buffer with random data. There's a last command to print it's stride value. Since its created with one quarter of the canvas's original width
you can check this value.
naturally.
The full example follows.
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#endif
#include <Ecore.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 *commands = \
"commands are:\n"
"\tp - change proxy image's source\n"
"\ts - print noise image's stride value\n"
"\ta - save noise image to disk (/tmp dir)\n"
"\tv - change source visibility\n"
"\te - enable/disable source events\n"
"\th - print help\n";
const char *file_path = "/tmp/evas-images2-example.png";
const char *quality_str = "quality=100";
struct test_data
{
Ecore_Evas *ee;
Evas_Object *logo, *noise_img, *proxy_img, *text_obj, *bg;
};
static struct test_data d = {0};
static void
void *event_info)
{
printf("Mouse Down - obj(%p), coords(%d %d)\n",
}
static void
void *event_info)
{
printf("Mouse Move - obj(%p), coords(%d %d)\n",
}
static void
void *event_info)
{
printf("Mouse Up - obj(%p), coords(%d %d)\n",
}
static void
void *event_info)
{
printf("Multi Down - obj(%p), coords(%d %d)\n",
obj, ev->canvas.
x, ev->canvas.
y);
}
static void
void *event_info)
{
printf("Multi Move - obj(%p), coords(%d %d)\n",
}
static void
void *event_info)
{
printf("Multi Up - obj(%p), coords(%d %d)\n",
obj, ev->canvas.
x, ev->canvas.
y);
}
static void
void *event_info)
{
printf("Mouse In - obj(%p), coords(%d %d)\n",
}
static void
void *event_info)
{
printf("Mouse Out - obj(%p), coords(%d %d)\n",
}
static void
void *event_info)
{
printf(
"Hold - obj(%p), hold(%d)\n", obj, ev->
hold);
}
static void
{
printf("Image has been pre-loaded!\n");
}
static void
{
}
static void
_canvas_resize_cb(Ecore_Evas *ee)
{
int w, h;
}
static void
void *einfo)
{
if (strcmp(ev->
key,
"h") == 0)
{
puts(commands);
return;
}
if (strcmp(ev->
key,
"s") == 0)
{
printf("Image has row stride value of %d, which accounts"
" for %d pixels\n", stride, stride / 4);
return;
}
if (strcmp(ev->
key,
"p") == 0)
{
if (source == d.logo) source = d.noise_img;
else if (source == d.noise_img) source = d.text_obj;
else source = d.logo;
printf("Proxy image's source changed\n");
return;
}
if (strcmp(ev->
key,
"a") == 0)
{
fprintf(stderr, "Cannot save image to '%s' (flags '%s')\n",
file_path, quality_str);
else
printf("Image saved to '%s' (flags '%s'), check it out with "
"an image viewer\n", file_path, quality_str);
return;
}
if (strcmp(ev->
key,
"v") == 0)
{
return;
}
if (strcmp(ev->
key,
"e") == 0)
{
return;
}
}
int
main(void)
{
unsigned int i;
unsigned int pixels[(WIDTH / 4) * (HEIGHT / 4)];
return EXIT_FAILURE;
if (!d.ee)
goto error;
for (i = 0; i < sizeof(pixels) / sizeof(pixels[0]); i++)
pixels[i] = rand();
printf("Creating noise image with size %d, %d\n",
WIDTH / 4, HEIGHT / 4);
puts(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
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition: ecore_evas.c:1083
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
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
EVAS_API int evas_object_image_stride_get(const Evas_Object *obj)
Retrieves the row stride of the given image object.
Definition: evas_image_legacy.c:176
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_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_API void evas_object_image_source_visible_set(Evas_Object *eo, Eina_Bool visible)
Set the source object to be visible or not.
Definition: evas_image_legacy.c:1052
EVAS_API void evas_object_image_source_events_set(Evas_Object *eo, Eina_Bool repeat)
Set whether an Evas object is to source events.
Definition: evas_image_legacy.c:498
EVAS_API Eina_Bool evas_object_image_source_events_get(const Evas_Object *eo)
Determine whether an object is set to source events.
Definition: evas_image_legacy.c:505
EVAS_API Eina_Bool evas_object_image_source_visible_get(const Evas_Object *eo)
Get the state of the source object visibility.
Definition: evas_image_legacy.c:1089
EVAS_API Evas_Object * evas_object_rectangle_add(Evas *e)
Adds a rectangle to the given evas.
Definition: evas_object_rectangle.c:78
EVAS_API void evas_object_textblock_text_markup_set(Eo *eo_obj, const char *text)
Sets given text as markup for the textblock object.
Definition: evas_object_textblock.c:8792
EVAS_API void evas_object_textblock_style_set(Eo *eo_obj, const Evas_Textblock_Style *ts)
Sets object's style to given style.
Definition: evas_object_textblock.c:8304
struct _Efl_Canvas_Textblock_Style Evas_Textblock_Style
A textblock style object.
Definition: evas_textblock_legacy.h:140
EVAS_API Evas_Textblock_Style * evas_textblock_style_new(void)
Creates a new textblock style.
Definition: evas_object_textblock.c:7971
EVAS_API Evas_Object * evas_object_textblock_add(Evas *e)
Adds a textblock to the given evas.
Definition: evas_object_textblock.c:7907
EVAS_API void evas_textblock_style_set(Evas_Textblock_Style *ts, const char *text)
Sets the style ts to the style passed as text by text.
Definition: evas_object_textblock.c:8048
Evas_Coord y
y co-ordinate
Definition: Evas_Common.h:233
Evas_Coord x
x co-ordinate
Definition: Evas_Common.h:232
Hold change event.
Definition: Evas_Legacy.h:348
int hold
The hold flag.
Definition: Evas_Legacy.h:349
Key press event.
Definition: Evas_Legacy.h:314
const char * key
The logical key : (eg shift+1 == exclamation)
Definition: Evas_Legacy.h:320
Mouse enter event.
Definition: Evas_Legacy.h:196
Evas_Coord_Point canvas
The X/Y location of the cursor.
Definition: Evas_Legacy.h:200
Mouse move event.
Definition: Evas_Legacy.h:228
Evas_Position cur
Current mouse position.
Definition: Evas_Legacy.h:231
Mouse leave event.
Definition: Evas_Legacy.h:212
Evas_Coord_Point canvas
The X/Y location of the cursor.
Definition: Evas_Legacy.h:216
Mouse button release event.
Definition: Evas_Legacy.h:178
Evas_Coord_Point canvas
The X/Y location of the cursor.
Definition: Evas_Legacy.h:182
Multi button press event.
Definition: Evas_Legacy.h:260
Multi button down event.
Definition: Evas_Legacy.h:298
Multi button release event.
Definition: Evas_Legacy.h:279
Evas_Coord_Point canvas
position on the canvas
Definition: Evas_Common.h:247
Evas_Coord_Precision_Point canvas
position on the canvas
Definition: Evas_Common.h:253