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)];
srand(time(NULL));
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;
}