aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/examples/evas-hints.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/evas/src/examples/evas-hints.c378
1 files changed, 0 insertions, 378 deletions
diff --git a/libraries/evas/src/examples/evas-hints.c b/libraries/evas/src/examples/evas-hints.c
deleted file mode 100644
index 78c09ba..0000000
--- a/libraries/evas/src/examples/evas-hints.c
+++ /dev/null
@@ -1,378 +0,0 @@
1/**
2 * Simple Evas example illustrating <b>alignment, minimum size, maximum
3 * size, padding and weight</b> hints on objects.
4 *
5 * To exemplify those hints, whe use the Evas box object, one of the
6 * managers using size hints to layout its children.
7 *
8 * You'll need at least one engine built for it (excluding the buffer
9 * one) and the png image loader also built. See stdout/stderr for
10 * output.
11 *
12 * @verbatim
13 * gcc -o evas-events evas-events.c `pkg-config --libs --cflags ecore-evas`
14 * @endverbatim
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#else
20#define __UNUSED__
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25
26#include <stdlib.h>
27#include <stdio.h>
28#include <string.h>
29
30#define WIDTH 320
31#define HEIGHT 480
32#define PACKAGE_EXAMPLES_DIR "."
33
34static const char commands[] = \
35 "commands are:\n"
36 "\tShift + a - change alignment hints on top rectangle\n"
37 "\tShift + m - change min. size hint on top rectangle\n"
38 "\tShift + n - change max. size hint on top rectangle\n"
39 "\tShift + p - change padding hints on top rectangle\n"
40 "\tShift + w - change weight hints on top rectangle\n\n"
41 "\tControl + a - change alignment hints on bottom rectangle\n"
42 "\tControl + m - change min. size hint on bottom rectangle\n"
43 "\tControl + n - change max. size hint on bottom rectangle\n"
44 "\tControl + p - change padding hints on bottom rectangle\n"
45 "\tControl + w - change weight hints on bottom rectangle\n\n"
46 "\ts - print current hints information\n"
47 "\th - print help\n";
48
49static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
50
51struct coord_tuple
52{
53 Evas_Coord w, h;
54};
55
56struct weight_tuple
57{
58 double x, y;
59};
60
61struct padding_tuple
62{
63 Evas_Coord l, r, t, b;
64};
65
66struct rect_data
67{
68 struct coord_tuple *min_ptr;
69 struct coord_tuple min[4];
70
71 struct coord_tuple *max_ptr;
72 struct coord_tuple max[4];
73
74 struct weight_tuple *align_ptr;
75 struct weight_tuple align[3];
76
77 struct weight_tuple *weight_ptr;
78 struct weight_tuple weight[3];
79
80 struct padding_tuple *padding_ptr;
81 struct padding_tuple padding[3];
82};
83
84struct test_data
85{
86 Ecore_Evas *ee;
87 Evas *canvas;
88 struct rect_data t_data, b_data;
89 Evas_Object *bg, *box, *t_rect, *b_rect, *border;
90};
91
92static struct test_data d = {0};
93
94/* here just to keep our example's window size and background image's
95 * size in synchrony */
96static void
97_canvas_resize_cb(Ecore_Evas *ee)
98{
99 int w, h;
100
101 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
102 evas_object_resize(d.bg, w, h);
103
104 evas_object_move(d.box, (w / 4), (h / 4));
105 evas_object_resize(d.box, (w / 2), (h / 2));
106
107 evas_object_move(d.border, (w / 4) - 3, (h / 4) - 3);
108 evas_object_resize(d.border, (w / 2) + 6, (h / 2) + 6);
109}
110
111static void
112_print_rect_stats(Evas_Object *rect)
113{
114 Evas_Coord w, h, l, r, t, b;
115 double x, y;
116
117 evas_object_size_hint_align_get(rect, &x, &y);
118 fprintf(stdout, "\talign hints: h(%f), v(%f)\n", x, y);
119
120 evas_object_size_hint_min_get(rect, &w, &h);
121 fprintf(stdout, "\tmin. size hints: h(%d), v(%d)\n", w, h);
122
123 evas_object_size_hint_max_get(rect, &w, &h);
124 fprintf(stdout, "\tmax. size hints: h(%d), v(%d)\n", w, h);
125
126 evas_object_size_hint_padding_get(rect, &l, &r, &t, &b);
127 fprintf(stdout, "\tpadding hints: l(%d), r(%d), t(%d), b(%d)\n",
128 l, r, t, b);
129
130 evas_object_size_hint_weight_get(rect, &x, &y);
131 fprintf(stdout, "\tweight hints: h(%f), v(%f)\n", x, y);
132}
133
134/* use the following commands to interact with this example - 'h' is
135 * the key for help */
136static void
137_on_keydown(void *data __UNUSED__,
138 Evas *evas __UNUSED__,
139 Evas_Object *o __UNUSED__,
140 void *einfo)
141{
142 Evas_Event_Key_Down *ev = einfo;
143 struct rect_data *r_data = NULL;
144 const Evas_Modifier *mods;
145 Evas_Object *rect = NULL;
146 const char *name = NULL;
147
148 mods = evas_key_modifier_get(evas);
149 if (evas_key_modifier_is_set(mods, "Shift"))
150 {
151 rect = d.t_rect;
152 r_data = &d.t_data;
153 name = "top";
154 }
155 else if (evas_key_modifier_is_set(mods, "Control"))
156 {
157 rect = d.b_rect;
158 r_data = &d.b_data;
159 name = "bottom";
160 }
161 else if (strcmp(ev->keyname, "h") == 0) /* print help */
162 {
163 fprintf(stdout, commands);
164 return;
165 }
166 else if (strcmp(ev->keyname, "s") == 0) /* get aspect status of the
167 * rectangles WRT size
168 * hints */
169 {
170 fprintf(stdout, "Top rectangle:\n");
171 _print_rect_stats(d.t_rect);
172
173 fprintf(stdout, "\nBottom rectangle:\n");
174 _print_rect_stats(d.b_rect);
175
176 return;
177 }
178
179 if (!rect) return;
180
181 if (strcmp(ev->keyname, "a") == 0) /* alignment hints */
182 {
183 (r_data->align_ptr)++;
184
185 if ((unsigned)
186 (((void *)(r_data->align_ptr)) - ((void *)(r_data->align))) >=
187 sizeof(r_data->align))
188 r_data->align_ptr = r_data->align;
189
190 evas_object_size_hint_align_set(
191 rect, r_data->align_ptr->x, r_data->align_ptr->y);
192
193 fprintf(stdout, "Changing align hints for %s rect. to (%f, %f)\n",
194 name, r_data->align_ptr->x, r_data->align_ptr->y);
195 return;
196 }
197
198 if (strcmp(ev->keyname, "m") == 0) /* min. size hints */
199 {
200 (r_data->min_ptr)++;
201
202 if ((unsigned)
203 (((void *)(r_data->min_ptr)) - ((void *)(r_data->min))) >=
204 sizeof(r_data->min))
205 r_data->min_ptr = r_data->min;
206
207 evas_object_size_hint_min_set(
208 rect, r_data->min_ptr->w, r_data->min_ptr->h);
209
210 fprintf(stdout, "Changing min. size hints for %s rect. to (%d, %d)\n",
211 name, r_data->min_ptr->w, r_data->min_ptr->h);
212 return;
213 }
214
215 if (strcmp(ev->keyname, "n") == 0) /* max. size hints */
216 {
217 (r_data->max_ptr)++;
218
219 if ((unsigned)
220 (((void *)(r_data->max_ptr)) - ((void *)(r_data->max))) >=
221 sizeof(r_data->max))
222 r_data->max_ptr = r_data->max;
223
224 evas_object_size_hint_max_set(
225 rect, r_data->max_ptr->w, r_data->max_ptr->h);
226
227 fprintf(stdout, "Changing max. size hints for %s rect. to (%d, %d)\n",
228 name, r_data->max_ptr->w, r_data->max_ptr->h);
229 return;
230 }
231
232 if (strcmp(ev->keyname, "p") == 0) /* padding size hints */
233 {
234 (r_data->padding_ptr)++;
235
236 if ((unsigned)
237 (((void *)(r_data->padding_ptr)) - ((void *)(r_data->padding))) >=
238 sizeof(r_data->padding))
239 r_data->padding_ptr = r_data->padding;
240
241 evas_object_size_hint_padding_set(
242 rect, r_data->padding_ptr->l, r_data->padding_ptr->r,
243 r_data->padding_ptr->t, r_data->padding_ptr->b);
244
245 fprintf(stdout, "Changing padding size hints for %s rect."
246 " to (%d, %d, %d, %d)\n",
247 name, r_data->padding_ptr->l, r_data->padding_ptr->r,
248 r_data->padding_ptr->t, r_data->padding_ptr->b);
249 return;
250 }
251
252 /* experiment with weights here. keep in mind that, for the box
253 * object, only if all the children have non zero weights this hint
254 * will have an effect */
255 if (strcmp(ev->keyname, "w") == 0) /* weight hints */
256 {
257 (r_data->weight_ptr)++;
258
259 if ((unsigned)
260 (((void *)(r_data->weight_ptr)) - ((void *)(r_data->weight))) >=
261 sizeof(r_data->weight))
262 r_data->weight_ptr = r_data->weight;
263
264 evas_object_size_hint_weight_set(
265 rect, r_data->weight_ptr->x, r_data->weight_ptr->y);
266
267 fprintf(stdout, "Changing weight hints for %s rect. to (%f, %f)\n",
268 name, r_data->weight_ptr->x, r_data->weight_ptr->y);
269 return;
270 }
271}
272
273static void
274_on_destroy(Ecore_Evas *ee __UNUSED__)
275{
276 ecore_main_loop_quit();
277}
278
279int
280main(void)
281{
282 if (!ecore_evas_init())
283 return EXIT_FAILURE;
284
285 /* init values one is going to cycle through while running this
286 * example */
287 struct rect_data init_data = \
288 {
289 .min = {{0, 0}, {30, 30}, {100, 70}, {200, 200}},
290 .max = {{0, 0}, {100, 100}, {100, 70}, {300, 300}},
291 .align = {{0.0, 0.0}, {0.5, 0.5}, {1.0, 0.5}},
292 .weight = {{0.0, 0.0}, {3, 6}, {10, 100}},
293 .padding = {{0, 0, 0, 0}, {3, 6, 9, 12}, {10, 20, 0, 30}}
294 };
295
296 d.t_data = init_data;
297
298 d.t_data.min_ptr = d.t_data.min + 1;
299 d.t_data.max_ptr = d.t_data.max + 1;
300 d.t_data.align_ptr = d.t_data.align;
301 d.t_data.weight_ptr = d.t_data.weight;
302 d.t_data.padding_ptr = d.t_data.padding;
303
304 d.b_data = init_data;
305
306 d.b_data.min_ptr = d.b_data.min + 1;
307 d.b_data.max_ptr = d.b_data.max + 1;
308 d.b_data.align_ptr = d.b_data.align;
309 d.b_data.weight_ptr = d.b_data.weight;
310 d.b_data.padding_ptr = d.b_data.padding;
311
312 /* this will give you a window with an Evas canvas under the first
313 * engine available */
314 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
315 if (!d.ee)
316 goto error;
317
318 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
319 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
320 ecore_evas_show(d.ee);
321
322 /* the canvas pointer, de facto */
323 d.canvas = ecore_evas_get(d.ee);
324
325 d.bg = evas_object_rectangle_add(d.canvas);
326 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
327 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
328 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
329 evas_object_show(d.bg);
330
331 evas_object_focus_set(d.bg, EINA_TRUE);
332 evas_object_event_callback_add(
333 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
334
335 /* Evas box with vertical layout */
336 d.box = evas_object_box_add(d.canvas);
337 evas_object_box_layout_set(
338 d.box, evas_object_box_layout_vertical, NULL, NULL);
339 evas_object_show(d.box);
340
341 /* this is a border around the box, container of the rectangles we
342 * are going to experiment with (changing some size hints). this
343 * way you can see how the container relates to the children */
344 d.border = evas_object_image_filled_add(d.canvas);
345 evas_object_image_file_set(d.border, border_img_path, NULL);
346 evas_object_image_border_set(d.border, 3, 3, 3, 3);
347 evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
348 evas_object_show(d.border);
349
350 d.t_rect = evas_object_rectangle_add(d.canvas);
351 evas_object_color_set(d.t_rect, 0, 0, 255, 255);
352
353 evas_object_size_hint_min_set(
354 d.t_rect, d.t_data.min_ptr->w, d.t_data.min_ptr->h);
355 evas_object_show(d.t_rect);
356 evas_object_box_append(d.box, d.t_rect);
357
358 d.b_rect = evas_object_rectangle_add(d.canvas);
359 evas_object_color_set(d.b_rect, 0, 255, 0, 255);
360
361 evas_object_size_hint_min_set(
362 d.b_rect, d.b_data.min_ptr->w, d.b_data.min_ptr->h);
363 evas_object_show(d.b_rect);
364 evas_object_box_append(d.box, d.b_rect);
365
366 _canvas_resize_cb(d.ee);
367
368 fprintf(stdout, commands);
369 ecore_main_loop_begin();
370 ecore_evas_shutdown();
371 return 0;
372
373error:
374 fprintf(stderr, "You got to have at least one evas engine built and linked"
375 " up to ecore-evas for this example to run properly.\n");
376 return -1;
377}
378