diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/edje/src/examples/edje-box.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/edje/src/examples/edje-box.c')
-rw-r--r-- | libraries/edje/src/examples/edje-box.c | 252 |
1 files changed, 0 insertions, 252 deletions
diff --git a/libraries/edje/src/examples/edje-box.c b/libraries/edje/src/examples/edje-box.c deleted file mode 100644 index 2b0cbda..0000000 --- a/libraries/edje/src/examples/edje-box.c +++ /dev/null | |||
@@ -1,252 +0,0 @@ | |||
1 | /** | ||
2 | * Simple Edje example illustrating box functions. | ||
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-box edje-box.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 __UNUSED__ | ||
16 | #endif | ||
17 | |||
18 | #include <Ecore.h> | ||
19 | #include <Ecore_Evas.h> | ||
20 | #include <Edje.h> | ||
21 | |||
22 | #define WIDTH 300 | ||
23 | #define HEIGHT 300 | ||
24 | |||
25 | #define RECTW 30 | ||
26 | #define RECTH 30 | ||
27 | |||
28 | #define NRECTS 20 | ||
29 | |||
30 | static const char commands[] = \ | ||
31 | "commands are:\n" | ||
32 | "\ti - prepend rectangle\n" | ||
33 | "\ta - append rectangle\n" | ||
34 | "\tc - remove\n" | ||
35 | "\tEsc - exit\n" | ||
36 | "\th - print help\n"; | ||
37 | |||
38 | static void | ||
39 | _on_destroy(Ecore_Evas *ee __UNUSED__) | ||
40 | { | ||
41 | ecore_main_loop_quit(); | ||
42 | } | ||
43 | |||
44 | /* here just to keep our example's window size and background image's | ||
45 | * size in synchrony */ | ||
46 | static void | ||
47 | _on_canvas_resize(Ecore_Evas *ee) | ||
48 | { | ||
49 | Evas_Object *bg; | ||
50 | Evas_Object *edje_obj; | ||
51 | int w; | ||
52 | int h; | ||
53 | |||
54 | bg = ecore_evas_data_get(ee, "background"); | ||
55 | edje_obj = ecore_evas_data_get(ee, "edje_obj"); | ||
56 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
57 | evas_object_resize(bg, w, h); | ||
58 | evas_object_resize(edje_obj, w, h); | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | _on_rect_mouse_down(void *data, Evas *e, Evas_Object *o, void *event_info) | ||
63 | { | ||
64 | Ecore_Evas *ee; | ||
65 | Evas_Event_Mouse_Down *ev; | ||
66 | Evas_Object *edje_obj; | ||
67 | |||
68 | ee = (Ecore_Evas *)data; | ||
69 | ev = (Evas_Event_Mouse_Down *)event_info; | ||
70 | edje_obj = ecore_evas_data_get(ee, "edje_obj"); | ||
71 | |||
72 | if (ev->button == 1) | ||
73 | { | ||
74 | printf("Removing rect %p under the mouse pointer.\n", o); | ||
75 | edje_object_part_box_remove(edje_obj, "example/box", o); | ||
76 | evas_object_del(o); | ||
77 | } | ||
78 | else if (ev->button == 3) | ||
79 | { | ||
80 | Evas_Object *rect; | ||
81 | Eina_Bool r; | ||
82 | |||
83 | rect = evas_object_rectangle_add(e); | ||
84 | evas_object_color_set(rect, 0, 0, 255, 255); | ||
85 | evas_object_resize(rect, RECTW + 10, RECTH); | ||
86 | evas_object_show(rect); | ||
87 | |||
88 | printf("Inserting rect %p before the rectangle under the mouse pointer.\n", rect); | ||
89 | r = edje_object_part_box_insert_before(edje_obj, "example/box", rect, o); | ||
90 | if (!r) | ||
91 | printf("An error ocurred when appending rect %p to the box.\n", rect); | ||
92 | |||
93 | evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN, _on_rect_mouse_down, NULL); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | static void | ||
98 | _on_bg_key_down(void *data, Evas *e, Evas_Object *o __UNUSED__, void *event_info) | ||
99 | { | ||
100 | Ecore_Evas *ee; | ||
101 | Evas_Event_Key_Down *ev; | ||
102 | Evas_Object *edje_obj; | ||
103 | Evas_Object *rect; | ||
104 | Eina_Bool r; | ||
105 | |||
106 | ee = (Ecore_Evas *)data; | ||
107 | ev = (Evas_Event_Key_Down *)event_info; | ||
108 | edje_obj = ecore_evas_data_get(ee, "edje_obj"); | ||
109 | |||
110 | if (!strcmp(ev->keyname, "h")) | ||
111 | { | ||
112 | fprintf(stdout, commands); | ||
113 | return; | ||
114 | } | ||
115 | if (!strcmp(ev->keyname, "i")) | ||
116 | { | ||
117 | rect = evas_object_rectangle_add(e); | ||
118 | evas_object_color_set(rect, 0, 0, 128, 255); | ||
119 | evas_object_resize(rect, RECTW + 30, RECTH); | ||
120 | evas_object_show(rect); | ||
121 | |||
122 | printf("Inserting rect %p before the rectangle under the mouse pointer.\n", rect); | ||
123 | r = edje_object_part_box_insert_at(edje_obj, "example/box", rect, 0); | ||
124 | if (!r) | ||
125 | printf("An error ocurred when appending rect %p to the box.\n", rect); | ||
126 | |||
127 | evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN, _on_rect_mouse_down, NULL); | ||
128 | } | ||
129 | else if (!strcmp(ev->keyname, "a")) | ||
130 | { | ||
131 | rect = evas_object_rectangle_add(e); | ||
132 | evas_object_color_set(rect, 0, 128, 0, 255); | ||
133 | evas_object_resize(rect, RECTW, RECTH); | ||
134 | evas_object_show(rect); | ||
135 | |||
136 | printf("Inserting rect %p before the rectangle under the mouse pointer.\n", rect); | ||
137 | r = edje_object_part_box_append(edje_obj, "example/box", rect); | ||
138 | if (!r) | ||
139 | printf("An error ocurred when appending rect %p to the box.\n", rect); | ||
140 | |||
141 | evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN, _on_rect_mouse_down, NULL); | ||
142 | } | ||
143 | else if (!strcmp(ev->keyname, "c")) | ||
144 | edje_object_part_box_remove_all(edje_obj, "example/box", EINA_TRUE); | ||
145 | else if (!strcmp(ev->keyname, "Escape")) | ||
146 | ecore_main_loop_quit(); | ||
147 | else | ||
148 | { | ||
149 | printf("unhandled key: %s\n", ev->keyname); | ||
150 | fprintf(stdout, commands); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | int | ||
155 | main(int argc __UNUSED__, char *argv[]) | ||
156 | { | ||
157 | char edje_file_path[PATH_MAX]; | ||
158 | const char *edje_file = "box.edj"; | ||
159 | Ecore_Evas *ee; | ||
160 | Evas *evas; | ||
161 | Evas_Object *bg; | ||
162 | Evas_Object *edje_obj; | ||
163 | Eina_Prefix *pfx; | ||
164 | int i; | ||
165 | |||
166 | if (!ecore_evas_init()) | ||
167 | return EXIT_FAILURE; | ||
168 | |||
169 | if (!edje_init()) | ||
170 | goto shutdown_ecore_evas; | ||
171 | |||
172 | pfx = eina_prefix_new(argv[0], main, | ||
173 | "EDJE_EXAMPLES", | ||
174 | "edje/examples", | ||
175 | edje_file, | ||
176 | PACKAGE_BIN_DIR, | ||
177 | PACKAGE_LIB_DIR, | ||
178 | PACKAGE_DATA_DIR, | ||
179 | PACKAGE_DATA_DIR); | ||
180 | if (!pfx) | ||
181 | goto shutdown_edje; | ||
182 | |||
183 | /* this will give you a window with an Evas canvas under the first | ||
184 | * engine available */ | ||
185 | ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
186 | if (!ee) | ||
187 | goto free_prefix; | ||
188 | |||
189 | ecore_evas_callback_destroy_set(ee, _on_destroy); | ||
190 | ecore_evas_callback_resize_set(ee, _on_canvas_resize); | ||
191 | ecore_evas_title_set(ee, "Edje Box Example"); | ||
192 | |||
193 | evas = ecore_evas_get(ee); | ||
194 | |||
195 | bg = evas_object_rectangle_add(evas); | ||
196 | evas_object_color_set(bg, 255, 255, 255, 255); | ||
197 | evas_object_resize(bg, WIDTH, HEIGHT); | ||
198 | evas_object_focus_set(bg, EINA_TRUE); | ||
199 | evas_object_show(bg); | ||
200 | ecore_evas_data_set(ee, "background", bg); | ||
201 | |||
202 | evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_bg_key_down, ee); | ||
203 | |||
204 | edje_obj = edje_object_add(evas); | ||
205 | |||
206 | snprintf(edje_file_path, sizeof(edje_file_path), | ||
207 | "%s/examples/%s", eina_prefix_data_get(pfx), edje_file); | ||
208 | edje_object_file_set(edje_obj, edje_file_path, "example/group"); | ||
209 | evas_object_move(edje_obj, 0, 0); | ||
210 | evas_object_resize(edje_obj, WIDTH, HEIGHT); | ||
211 | evas_object_show(edje_obj); | ||
212 | ecore_evas_data_set(ee, "edje_obj", edje_obj); | ||
213 | |||
214 | for (i = 0; i < NRECTS; i++) | ||
215 | { | ||
216 | Evas_Object *rect; | ||
217 | Eina_Bool r = EINA_FALSE; | ||
218 | int red = (i * 10) % 256; | ||
219 | rect = evas_object_rectangle_add(evas); | ||
220 | evas_object_color_set(rect, red, 0, 0, 255); | ||
221 | evas_object_resize(rect, RECTW, RECTH); | ||
222 | r = edje_object_part_box_append(edje_obj, "example/box", rect); | ||
223 | if (!r) | ||
224 | printf("An error ocurred when appending rect #%d to the box.\n", i); | ||
225 | evas_object_show(rect); | ||
226 | |||
227 | evas_object_event_callback_add( | ||
228 | rect, EVAS_CALLBACK_MOUSE_DOWN, _on_rect_mouse_down, ee); | ||
229 | } | ||
230 | |||
231 | fprintf(stdout, commands); | ||
232 | |||
233 | ecore_evas_show(ee); | ||
234 | |||
235 | ecore_main_loop_begin(); | ||
236 | |||
237 | eina_prefix_free(pfx); | ||
238 | ecore_evas_free(ee); | ||
239 | ecore_evas_shutdown(); | ||
240 | edje_shutdown(); | ||
241 | |||
242 | return EXIT_SUCCESS; | ||
243 | |||
244 | free_prefix: | ||
245 | eina_prefix_free(pfx); | ||
246 | shutdown_edje: | ||
247 | edje_shutdown(); | ||
248 | shutdown_ecore_evas: | ||
249 | ecore_evas_shutdown(); | ||
250 | |||
251 | return EXIT_FAILURE; | ||
252 | } | ||