aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/examples/evas-object-manipulation.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/evas/src/examples/evas-object-manipulation.c235
1 files changed, 235 insertions, 0 deletions
diff --git a/libraries/evas/src/examples/evas-object-manipulation.c b/libraries/evas/src/examples/evas-object-manipulation.c
new file mode 100644
index 0000000..e9c9442
--- /dev/null
+++ b/libraries/evas/src/examples/evas-object-manipulation.c
@@ -0,0 +1,235 @@
1/**
2 * Simple Evas example illustrating basic objects manipulation.
3 *
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
6 * output.
7 *
8 * @verbatim
9 * gcc -o evas-object-manipulation evas-object-manipulation.c `pkg-config --libs --cflags ecore evas ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14
15#include "config.h"
16#else
17
18#define PACKAGE_EXAMPLES_DIR "."
19#define __UNUSED__
20
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25#include <stdio.h>
26#include <errno.h>
27
28#define WIDTH (320)
29#define HEIGHT (240)
30
31static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
32static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
33
34struct test_data
35{
36 Ecore_Evas *ee;
37 Evas *canvas;
38 Evas_Object *img, *bg, *clipper, *clipper_border, *text;
39};
40
41static struct test_data d = {0};
42
43/* here just to keep our example's window size and background image's
44 * size in synchrony */
45static void
46_canvas_resize_cb(Ecore_Evas *ee)
47{
48 int w, h;
49
50 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
51 evas_object_resize(d.bg, w, h);
52}
53
54static void
55_on_keydown(void *data __UNUSED__,
56 Evas *evas __UNUSED__,
57 Evas_Object *o __UNUSED__,
58 void *einfo)
59{
60 Evas_Event_Key_Down *ev = einfo;
61
62 if (strcmp(ev->keyname, "h") == 0) /* print help */
63 {
64 fprintf(stdout, "commands are:\n"
65 "\to - change clipper's opacity\n"
66 "\tr - toggle clipper's color between red and white\n"
67 "\tc - toggle clipper's clipping function\n"
68 "\tv - toggle clipper's visibility\n");
69 return;
70 }
71
72 if (strcmp(ev->keyname, "o") == 0) /* change clipper's opacity */
73 {
74 int alpha, r, g, b;
75
76 evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
77 alpha -= 20;
78 if (alpha < 0)
79 alpha = 255;
80
81 evas_object_color_set(d.clipper, r, g, b, alpha);
82
83 fprintf(stdout, "Changing clipper's opacity: %d%%\n",
84 (int)((alpha / 255.0) * 100));
85 return;
86 }
87
88 if (strcmp(ev->keyname, "r") == 0) /* toggle clipper's color
89 * between red and white */
90 {
91 int alpha, r, g, b;
92
93 fprintf(stdout, "Changing clipper's color to");
94
95 evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
96 if (g > 0)
97 {
98 fprintf(stdout, "red\n");
99 g = b = 0;
100 }
101 else
102 {
103 fprintf(stdout, "white\n");
104 g = b = 255;
105 }
106
107 evas_object_color_set(d.clipper, r, g, b, alpha);
108 return;
109 }
110
111 if (strcmp(ev->keyname, "c") == 0) /* toggle clipper's clipping function */
112 {
113 fprintf(stdout, "Toggling clipping ");
114
115 if (evas_object_clip_get(d.img) == d.clipper)
116 {
117 evas_object_clip_unset(d.img);
118 fprintf(stdout, "off\n");
119 }
120 else
121 {
122 evas_object_clip_set(d.img, d.clipper);
123 fprintf(stdout, "on\n");
124 }
125 return;
126 }
127
128 if (strcmp(ev->keyname, "v") == 0) /* toggle clipper's visibility */
129 {
130 fprintf(stdout, "Clipper is now ");
131
132 if (evas_object_visible_get(d.clipper))
133 {
134 evas_object_hide(d.clipper);
135 fprintf(stdout, "hidden\n");
136 }
137 else
138 {
139 evas_object_show(d.clipper);
140 fprintf(stdout, "visible\n");
141 }
142 return;
143 }
144}
145
146int
147main(void)
148{
149 int err;
150
151 if (!ecore_evas_init())
152 return EXIT_FAILURE;
153
154 /* this will give you a window with an Evas canvas under the first
155 * engine available */
156 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
157 if (!d.ee)
158 goto error;
159
160 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
161 ecore_evas_show(d.ee);
162
163 /* the canvas pointer, de facto */
164 d.canvas = ecore_evas_get(d.ee);
165
166 d.bg = evas_object_rectangle_add(d.canvas);
167 evas_object_name_set(d.bg, "background rectangle");
168 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
169 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
170 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
171 evas_object_show(d.bg);
172
173 evas_object_focus_set(d.bg, EINA_TRUE);
174 evas_object_event_callback_add(
175 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
176
177 d.img = evas_object_image_filled_add(d.canvas);
178 evas_object_image_file_set(d.img, img_path, NULL);
179 err = evas_object_image_load_error_get(d.img);
180 if (err != EVAS_LOAD_ERROR_NONE)
181 {
182 goto panic;
183 }
184 else
185 {
186 evas_object_move(d.img, 0, 0);
187 evas_object_resize(d.img, WIDTH, HEIGHT);
188 evas_object_show(d.img);
189
190 fprintf(stdout, "Image object added, type is: %s\n",
191 evas_object_type_get(d.img));
192 }
193
194 /* border on the image's clipper, here just to emphasize its position */
195 d.clipper_border = evas_object_image_filled_add(d.canvas);
196 evas_object_image_file_set(d.clipper_border, border_img_path, NULL);
197 err = evas_object_image_load_error_get(d.clipper_border);
198 if (err != EVAS_LOAD_ERROR_NONE)
199 {
200 goto panic;
201 }
202 else
203 {
204 evas_object_image_border_set(d.clipper_border, 3, 3, 3, 3);
205 evas_object_image_border_center_fill_set(
206 d.clipper_border, EVAS_BORDER_FILL_NONE);
207 evas_object_move(d.clipper_border, (WIDTH / 4) - 3, (HEIGHT / 4) - 3);
208 evas_object_resize(
209 d.clipper_border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
210 evas_object_show(d.clipper_border);
211 }
212
213 /* solid white clipper (note that it's the default color for a
214 * rectangle) - it won't change clippees' colors, then (multiplying
215 * by 255) */
216 d.clipper = evas_object_rectangle_add(d.canvas);
217 evas_object_move(d.clipper, WIDTH / 4, HEIGHT / 4);
218 evas_object_resize(d.clipper, WIDTH / 2, HEIGHT / 2);
219 evas_object_clip_set(d.img, d.clipper);
220 evas_object_show(d.clipper);
221
222 ecore_main_loop_begin();
223
224 ecore_evas_free(d.ee);
225 ecore_evas_shutdown();
226 return 0;
227
228error:
229 fprintf(stderr, "you got to have at least one evas engine built and linked"
230 " up to ecore-evas for this example to run properly.\n");
231panic:
232 ecore_evas_free(d.ee);
233 ecore_evas_shutdown();
234 return -1;
235}