2 * Simple Evas example illustrating some image objects functions and evas_load_error_str()'s usage.
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader also built. See stdout/stderr for
9 * gcc -o evas-load-error-str evas-load-error-str.c `pkg-config --libs \
10 * --cflags ecore-evas`
21 #include <Ecore_Evas.h>
28 static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
29 static const char *valid_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
30 static const char *bogus_path = "/tmp/non-existent-220986.png";
33 _on_keydown(void *data,
34 Evas *evas __UNUSED__,
35 Evas_Object *o __UNUSED__,
38 Evas_Object *img = data;
39 Evas_Event_Key_Down *ev = einfo;
41 if (strcmp(ev->keyname, "h") == 0) /* print help */
43 fprintf(stdout, "commands are:\n"
44 "\tx - change image's x fill coordinate\n"
45 "\ty - change image's y fill coordinate\n"
46 "\tw - change image's w fill size\n"
47 "\te - change image's h fill size\n"
48 "\tf - toggle image filled property (overrides fill)\n"
49 "\ts - print image's fill property status\n"
50 "\th - print help\n");
54 if (strcmp(ev->keyname, "f") == 0) /* toggle filled property */
56 Eina_Bool filled = evas_object_image_filled_get(img);
58 evas_object_image_filled_set(img, !filled);
60 fprintf(stdout, "Image's x filled property is now %s\n",
61 filled ? "off" : "on");
66 if (strcmp(ev->keyname, "x") == 0) /* change x fill coordinate */
68 Evas_Coord x, y, w, h;
70 evas_object_image_fill_get(img, &x, &y, &w, &h);
71 x = (x + 20) % (WIDTH / 2);
72 evas_object_image_fill_set(img, x, y, w, h);
74 fprintf(stdout, "Image's x fill coordinate changed to %d\n", x);
79 if (strcmp(ev->keyname, "y") == 0) /* change y fill coordinate */
81 Evas_Coord x, y, w, h;
83 evas_object_image_fill_get(img, &x, &y, &w, &h);
84 y = (y + 20) % (HEIGHT / 2);
85 evas_object_image_fill_set(img, x, y, w, h);
87 fprintf(stdout, "Image's y fill coordinate changed to %d\n", y);
92 if (strcmp(ev->keyname, "w") == 0) /* change w fill size */
94 Evas_Coord x, y, w, h;
96 evas_object_image_fill_get(img, &x, &y, &w, &h);
97 if (w > (WIDTH / 2)) w = (WIDTH / 2);
99 evas_object_image_fill_set(img, x, y, w, h);
101 fprintf(stdout, "Image's w fill size changed to %d\n", w);
106 if (strcmp(ev->keyname, "e") == 0) /* change h fill size */
108 Evas_Coord x, y, w, h;
110 evas_object_image_fill_get(img, &x, &y, &w, &h);
111 if (h > (HEIGHT / 2)) h = (HEIGHT / 2);
113 evas_object_image_fill_set(img, x, y, w, h);
115 fprintf(stdout, "Image's h fill size changed to %d\n", h);
120 if (strcmp(ev->keyname, "s") == 0) /* status */
122 Evas_Coord x, y, w, h;
124 evas_object_image_fill_get(img, &x, &y, &w, &h);
126 fprintf(stdout, "Image has fill properties set to: %d, %d, %d, %d\n",
138 Evas_Object *img1, *img2, *bg, *border;
141 if (!ecore_evas_init())
144 /* this will give you a window with an Evas canvas under the first
145 * engine available */
146 ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
152 /* the canvas pointer, de facto */
153 evas = ecore_evas_get(ee);
155 bg = evas_object_rectangle_add(evas);
156 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
157 evas_object_move(bg, 0, 0); /* at canvas' origin */
158 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
159 evas_object_show(bg);
161 img1 = evas_object_image_add(evas);
162 evas_object_image_file_set(img1, valid_path, NULL);
163 err = evas_object_image_load_error_get(img1);
164 if (err != EVAS_LOAD_ERROR_NONE)
166 fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
167 valid_path, evas_load_error_str(err));
172 "loaded image '%s' with succes! error string is \"%s\"\n",
173 valid_path, evas_load_error_str(err));
175 evas_object_move(img1, 0, 0);
176 evas_object_image_fill_set(img1, 0, 0, WIDTH / 2, HEIGHT / 2);
177 evas_object_resize(img1, WIDTH / 2, HEIGHT / 2);
178 evas_object_show(img1);
180 evas_object_focus_set(bg, EINA_TRUE);
181 evas_object_event_callback_add(
182 bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, img1);
185 /* this is a border around the image above, here just to emphasize
187 border = evas_object_image_filled_add(evas);
188 evas_object_image_file_set(border, border_img_path, NULL);
189 evas_object_image_border_set(border, 3, 3, 3, 3);
190 evas_object_image_border_center_fill_set(border, EVAS_BORDER_FILL_NONE);
192 evas_object_move(border, 0, 0);
193 evas_object_resize(border, (WIDTH / 2) + 3, (HEIGHT / 2) + 3);
194 evas_object_show(border);
196 /* image loading will fail for this one -- unless one cheats and
197 * puts a valid image on that path */
198 img2 = evas_object_image_add(evas);
199 evas_object_image_file_set(img2, bogus_path, NULL);
200 err = evas_object_image_load_error_get(img2);
201 if (err != EVAS_LOAD_ERROR_NONE)
203 fprintf(stderr, "could not load image '%s': error string is \"%s\"\n",
204 bogus_path, evas_load_error_str(err));
208 evas_object_move(img2, WIDTH / 2, HEIGHT / 2);
209 evas_object_image_fill_set(img2, 0, 0, WIDTH / 2, HEIGHT / 2);
210 evas_object_resize(img2, WIDTH / 2, HEIGHT / 2);
211 evas_object_show(img2);
214 ecore_main_loop_begin();
217 ecore_evas_shutdown();
221 fprintf(stderr, "you got to have at least one evas engine built and linked"
222 " up to ecore-evas for this example to run properly.\n");
223 ecore_evas_shutdown();