In this example, we add two images to a canvas, each one having a quarter of the canvas' size, positioned on the top left and bottom right corners, respectively:
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
}
else
{
printf("loaded image '%s' with succes! error string is \"%s\"\n",
}
{
fprintf(stderr, "could not load image '%s': error string is \"%s\"\n",
}
else
{
}
puts(commands);
See there is a border image around the top left one, which is the one that should be displayed. The other one will (on purpose) fail to load, because we set a wrong file path as image source on it:
static const char *valid_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/enlightenment.png";
static const char *bogus_path = "/tmp/non-existent-220986.png";
This is how one is supposed to test for success when binding source images to image objects: evas_object_image_load_error_get(), followed by evas_load_error_str(), if one wants to pretty print/log the error. We'll talk about the border image further.
To interact with the program, there's a command line interface. A help string can be asked for with the 'h' key:
static const char *commands = \
"commands are:\n"
"\tx - change image's x fill coordinate\n"
"\ty - change image's y fill coordinate\n"
"\tw - change image's w fill size\n"
"\te - change image's h fill size\n"
"\tf - toggle image filled property (overrides fill)\n"
"\ta - toggle image's alpha channel usage\n"
"\tm - toggle border's smooth scaling\n"
"\tt - change border's thickness\n"
"\tb - change border's center region aspect\n"
"\tc - change border's scaling factor\n"
"\ts - print image's fill property status\n"
"\th - print help\n";
The first four commands will change the top left images's fill property values, which dictate how the source image (Enlightenment's logo) is to be displayed through the image object's area. Experiment with those switches until you get the idea of evas_object_fill_set().
The 'f' command will toggle that image's "filled" property, which is whether it should track its size and set the fill one to fit the object's boundaries perfectly (stretching). Note that this command and the four above it will conflict: in real usage one would use one or other ways of setting an image object's viewport with regard to its image source.
There are four commands which deal with the border image. This red frame is there to illustrate image borders. The image source for the border is a solid red rectangle, with a transparent rectangular area in its middle. See how we use it to get a 3 pixel wide frame with evas_object_image_border_set(d.border, 3, 3, 3, 3)
. To finish the effect of showing it as a border, we issue evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE)
.
Use 't' to change the border's thickness. 'b' will change the border image's center region rendering schema: either a hole (no rendering), blending (see the original transparent area, in this case) or solid (the transparent area gets filled). Finally, 'c' will change the border's scaling factor.
While you have the border in 'blending mode', test the command 'm': it will set whether to use or not smooth scaling on the border's source image. Since the image is small originally (30 x 30), we're obviously up-scaling it (except the border pixels, do you remember?). With this last switch, you'll either see the transparent shape in the middle flat (no smoothing) or blurry (smoothed).
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 *border_img_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/red.png";
static const char *valid_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/enlightenment.png";
static const char *bogus_path = "/tmp/non-existent-220986.png";
static const char *commands = \
"commands are:\n"
"\tx - change image's x fill coordinate\n"
"\ty - change image's y fill coordinate\n"
"\tw - change image's w fill size\n"
"\te - change image's h fill size\n"
"\tf - toggle image filled property (overrides fill)\n"
"\ta - toggle image's alpha channel usage\n"
"\tm - toggle border's smooth scaling\n"
"\tt - change border's thickness\n"
"\tb - change border's center region aspect\n"
"\tc - change border's scaling factor\n"
"\ts - print image's fill property status\n"
"\th - print help\n";
struct test_data
{
Ecore_Evas *ee;
};
static struct test_data d = {0};
static void
{
}
static void
_canvas_resize_cb(Ecore_Evas *ee)
{
int w, h;
}
static const char *
{
switch (mode)
{
return "none";
return "default";
return "solid";
default:
return "invalid";
}
}
static void
void *einfo)
{
if (strcmp(ev->
key,
"h") == 0)
{
puts(commands);
return;
}
if (strcmp(ev->
key,
"m") == 0)
{
printf("Image's border is now %s smooth scaling\n",
smooth_scale ? "without" : "with");
return;
}
if (strcmp(ev->
key,
"t") == 0)
{
int l, r, t, b;
l = (l + 3) % 9;
r = (r + 3) % 9;
t = (t + 3) % 9;
b = (b + 3) % 9;
printf("Image's border thickness is now %d\n", l);
return;
}
if (strcmp(ev->
key,
"c") == 0)
{
scale *= 2;
if (scale > 4.0) scale = 1.0;
printf("Image's border scaling factor is now %f\n", scale);
return;
}
if (strcmp(ev->
key,
"b") == 0)
{
evas_object_image_border_center_fill_get(d.border);
fill = (fill + 1) % 3;
printf("Image's border center region aspect is now \"%s\"\n",
_border_fill_mode_to_str(fill));
return;
}
if (strcmp(ev->
key,
"a") == 0)
{
printf("Image's alpha channel is now %s\n",
alpha ? "off" : "on");
return;
}
if (strcmp(ev->
key,
"f") == 0)
{
printf("Image's x filled property is now %s\n",
filled ? "off" : "on");
return;
}
if (strcmp(ev->
key,
"x") == 0)
{
x = (x + 20) % (WIDTH / 2);
printf("Image's x fill coordinate changed to %d\n", x);
return;
}
if (strcmp(ev->
key,
"y") == 0)
{
y = (y + 20) % (HEIGHT / 2);
printf("Image's y fill coordinate changed to %d\n", y);
return;
}
if (strcmp(ev->
key,
"w") == 0)
{
if (w == (WIDTH / 4)) w = (WIDTH / 2);
else if (w == WIDTH / 2) w = WIDTH;
else w = (WIDTH / 4);
printf("Image's w fill size changed to %d\n", w);
return;
}
if (strcmp(ev->
key,
"e") == 0)
{
if (h == (HEIGHT / 4)) h = (HEIGHT / 2);
else if (h == HEIGHT / 2) h = HEIGHT;
else h = (HEIGHT / 4);
printf("Image's h fill size changed to %d\n", h);
return;
}
if (strcmp(ev->
key,
"s") == 0)
{
printf("Image has fill properties set to: %d, %d, %d, %d\n",
x, y, w, h);
return;
}
}
int
main(void)
{
int err;
return EXIT_FAILURE;
if (!d.ee)
goto error;
{
fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
}
else
{
printf("loaded image '%s' with succes! error string is \"%s\"\n",
}
{
fprintf(stderr, "could not load image '%s': error string is \"%s\"\n",
}
else
{
}
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;
}