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