diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/edje/src/examples/edje-box2.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-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 '')
-rw-r--r-- | libraries/edje/src/examples/edje-box2.c | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/edje-box2.c b/libraries/edje/src/examples/edje-box2.c new file mode 100644 index 0000000..b3f4e40 --- /dev/null +++ b/libraries/edje/src/examples/edje-box2.c | |||
@@ -0,0 +1,204 @@ | |||
1 | /** | ||
2 | * Simple Edje example illustrating a custom box layout. | ||
3 | * | ||
4 | * You'll need at least one Evas engine built for it (excluding the | ||
5 | * buffer one). See stdout/stderr for output. | ||
6 | * | ||
7 | * @verbatim | ||
8 | * edje_cc box.edc && gcc -o edje-box2 edje-box2.c `pkg-config --libs --cflags evas ecore ecore-evas edje` | ||
9 | * @endverbatim | ||
10 | */ | ||
11 | |||
12 | #ifdef HAVE_CONFIG_H | ||
13 | #include "config.h" | ||
14 | #else | ||
15 | #define PACKAGE_EXAMPLES_DIR "." | ||
16 | #define __UNUSED__ | ||
17 | #endif | ||
18 | |||
19 | #include <Ecore.h> | ||
20 | #include <Evas.h> | ||
21 | #include <Ecore_Evas.h> | ||
22 | #include <Edje.h> | ||
23 | |||
24 | #include <stdlib.h> | ||
25 | #include <stdio.h> | ||
26 | #include <string.h> | ||
27 | |||
28 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/box.edj"; | ||
29 | |||
30 | struct _App { | ||
31 | Ecore_Evas *ee; | ||
32 | Evas *evas; | ||
33 | Evas_Object *bg; | ||
34 | Evas_Object *box; | ||
35 | }; | ||
36 | |||
37 | static struct _App app; | ||
38 | |||
39 | static void | ||
40 | custom_layout(Evas_Object *o, Evas_Object_Box_Data *p, void *data) | ||
41 | { | ||
42 | int x, y, w, h; | ||
43 | int xx, yy, ww, hh; | ||
44 | int count; | ||
45 | Eina_List *l; | ||
46 | Evas_Object_Box_Option *opt; | ||
47 | |||
48 | evas_object_geometry_get(o, &x, &y, &w, &h); | ||
49 | count = eina_list_count(p->children); | ||
50 | ww = w / (count?:1); | ||
51 | hh = h / (count?:1); | ||
52 | if (ww < 1) ww = 1; | ||
53 | if (hh < 1) hh = 1; | ||
54 | |||
55 | xx = x; | ||
56 | yy = y; | ||
57 | EINA_LIST_FOREACH(p->children, l, opt) | ||
58 | { | ||
59 | evas_object_move(opt->obj, xx, yy); | ||
60 | xx += ww; | ||
61 | yy += hh; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | static Evas_Object * | ||
66 | new_greenie_block(Evas *e) | ||
67 | { | ||
68 | Evas_Object *o; | ||
69 | |||
70 | o = evas_object_rectangle_add(e); | ||
71 | evas_object_resize(o, 10, 10); | ||
72 | evas_object_color_set(o, 0, 255, 0, 255); | ||
73 | evas_object_show(o); | ||
74 | |||
75 | return o; | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | on_keydown(void *data, Evas *evas, Evas_Object *o, void *einfo) | ||
80 | { | ||
81 | struct _App *app = data; | ||
82 | Evas_Event_Key_Down *ev = einfo; | ||
83 | const Evas_Modifier *mods; | ||
84 | |||
85 | mods = evas_key_modifier_get(evas); | ||
86 | if (evas_key_modifier_is_set(mods, "Shift")) | ||
87 | { | ||
88 | int pos; | ||
89 | Evas_Object *obj = NULL; | ||
90 | pos = atoi(ev->keyname); | ||
91 | obj = edje_object_part_box_remove_at(app->box, "example/box", pos); | ||
92 | if (obj) | ||
93 | evas_object_del(obj); | ||
94 | return; | ||
95 | } | ||
96 | if (evas_key_modifier_is_set(mods, "Control")) | ||
97 | { | ||
98 | Evas_Object *o; | ||
99 | int pos; | ||
100 | pos = atoi(ev->keyname); | ||
101 | o = new_greenie_block(app->evas); | ||
102 | if (!edje_object_part_box_insert_at(app->box, "example/box", o, pos)) | ||
103 | edje_object_part_box_append(app->box, "example/box", o); | ||
104 | return; | ||
105 | } | ||
106 | if (strcmp(ev->keyname, "Escape") == 0) | ||
107 | ecore_main_loop_quit(); | ||
108 | } | ||
109 | |||
110 | static Evas_Object * | ||
111 | box_new(Evas *evas, const char *name, int x, int y, int w, int h) | ||
112 | { | ||
113 | Evas_Object *o; | ||
114 | |||
115 | o = edje_object_add(evas); | ||
116 | evas_object_move(o, x, y); | ||
117 | evas_object_resize(o, w, h); | ||
118 | if (!edje_object_file_set(o, edje_file_path, "example/group2")) | ||
119 | { | ||
120 | printf("error: could not load file object.\n"); | ||
121 | } | ||
122 | evas_object_show(o); | ||
123 | |||
124 | evas_object_name_set(o, name); | ||
125 | |||
126 | return o; | ||
127 | } | ||
128 | |||
129 | static void | ||
130 | on_resize(Ecore_Evas *ee) | ||
131 | { | ||
132 | int w, h; | ||
133 | |||
134 | evas_output_viewport_get(app.evas, NULL, NULL, &w, &h); | ||
135 | evas_object_resize(app.bg, w, h); | ||
136 | evas_object_resize(app.box, w, h); | ||
137 | } | ||
138 | |||
139 | static void | ||
140 | on_destroy(Ecore_Evas *ee) | ||
141 | { | ||
142 | ecore_main_loop_quit(); | ||
143 | } | ||
144 | |||
145 | int | ||
146 | main(int argc, char *argv[]) | ||
147 | { | ||
148 | Ecore_Evas *ee; | ||
149 | int w, h, i; | ||
150 | Evas_Object *last; | ||
151 | Evas_Object *o; | ||
152 | |||
153 | evas_init(); | ||
154 | ecore_init(); | ||
155 | ecore_evas_init(); | ||
156 | edje_init(); | ||
157 | |||
158 | ee = ecore_evas_new(NULL, 0, 0, 640, 480, NULL); | ||
159 | ecore_evas_show(ee); | ||
160 | |||
161 | app.ee = ee; | ||
162 | app.evas = ecore_evas_get(ee); | ||
163 | |||
164 | ecore_evas_callback_resize_set(ee, on_resize); | ||
165 | ecore_evas_callback_destroy_set(ee, on_destroy); | ||
166 | |||
167 | evas_output_viewport_get(app.evas, NULL, NULL, &w, &h); | ||
168 | |||
169 | app.bg = evas_object_rectangle_add(app.evas); | ||
170 | evas_object_resize(app.bg, w, h); | ||
171 | evas_object_show(app.bg); | ||
172 | evas_object_focus_set(app.bg, 1); | ||
173 | evas_object_event_callback_add( | ||
174 | app.bg, EVAS_CALLBACK_KEY_DOWN, on_keydown, &app); | ||
175 | |||
176 | edje_box_layout_register("custom_layout", custom_layout, NULL, NULL, NULL, NULL); | ||
177 | |||
178 | app.box = box_new(app.evas, "box", 0, 0, w, h); | ||
179 | |||
180 | for (i = 1; i <= 5; i++) | ||
181 | { | ||
182 | o = last = evas_object_rectangle_add(app.evas); | ||
183 | evas_object_size_hint_min_set(o, 50, 50); | ||
184 | evas_object_resize(o, 50, 50); | ||
185 | evas_object_color_set(o, 255, 0, 0, 128); | ||
186 | evas_object_show(o); | ||
187 | |||
188 | if (!edje_object_part_box_append(app.box, "example/box", o)) | ||
189 | { | ||
190 | fprintf(stderr, "error appending child object!\n"); | ||
191 | return 1; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | ecore_main_loop_begin(); | ||
196 | |||
197 | edje_shutdown(); | ||
198 | ecore_evas_shutdown(); | ||
199 | ecore_shutdown(); | ||
200 | evas_shutdown(); | ||
201 | |||
202 | |||
203 | return 0; | ||
204 | } | ||