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-box.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-box.c | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/edje-box.c b/libraries/edje/src/examples/edje-box.c new file mode 100644 index 0000000..7fffba3 --- /dev/null +++ b/libraries/edje/src/examples/edje-box.c | |||
@@ -0,0 +1,191 @@ | |||
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 PACKAGE_EXAMPLES_DIR "." | ||
16 | #define __UNUSED__ | ||
17 | #endif | ||
18 | |||
19 | #include <Ecore.h> | ||
20 | #include <Ecore_Evas.h> | ||
21 | #include <Edje.h> | ||
22 | |||
23 | #define WIDTH 300 | ||
24 | #define HEIGHT 300 | ||
25 | |||
26 | #define RECTW 30 | ||
27 | #define RECTH 30 | ||
28 | |||
29 | #define NRECTS 20 | ||
30 | |||
31 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/box.edj"; | ||
32 | |||
33 | struct _App { | ||
34 | Ecore_Evas *ee; | ||
35 | Evas_Object *edje; | ||
36 | Evas_Object *bg; | ||
37 | }; | ||
38 | |||
39 | static void | ||
40 | _on_destroy(Ecore_Evas *ee __UNUSED__) | ||
41 | { | ||
42 | ecore_main_loop_quit(); | ||
43 | } | ||
44 | |||
45 | /* here just to keep our example's window size and background image's | ||
46 | * size in synchrony */ | ||
47 | static void | ||
48 | _canvas_resize_cb(Ecore_Evas *ee) | ||
49 | { | ||
50 | int w, h; | ||
51 | struct _App *app = ecore_evas_data_get(ee, "app"); | ||
52 | |||
53 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
54 | evas_object_resize(app->bg, w, h); | ||
55 | evas_object_resize(app->edje, w, h); | ||
56 | } | ||
57 | |||
58 | static void | ||
59 | _rect_mouse_down(void *data, Evas *e, Evas_Object *o, void *event_info) | ||
60 | { | ||
61 | struct _App *app = data; | ||
62 | Evas_Event_Mouse_Down *ev = event_info; | ||
63 | |||
64 | if (ev->button == 1) | ||
65 | { | ||
66 | printf("Removing rect %p under the mouse pointer.\n", o); | ||
67 | edje_object_part_box_remove(app->edje, "example/box", o); | ||
68 | evas_object_del(o); | ||
69 | } | ||
70 | else if (ev->button == 3) | ||
71 | { | ||
72 | Evas_Object *rect; | ||
73 | Eina_Bool r; | ||
74 | |||
75 | rect = evas_object_rectangle_add(e); | ||
76 | evas_object_color_set(rect, 0, 0, 255, 255); | ||
77 | evas_object_resize(rect, RECTW + 10, RECTH); | ||
78 | evas_object_show(rect); | ||
79 | |||
80 | printf("Inserting rect %p before the rectangle under the mouse pointer.\n", rect); | ||
81 | r = edje_object_part_box_insert_before(app->edje, "example/box", rect, o); | ||
82 | if (!r) | ||
83 | printf("An error ocurred when appending rect %p to the box.\n", rect); | ||
84 | |||
85 | evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN, _rect_mouse_down, app); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | static void | ||
90 | _bg_key_down(void *data, Evas *e, Evas_Object *o __UNUSED__, void *event_info) | ||
91 | { | ||
92 | struct _App *app = data; | ||
93 | Evas_Event_Key_Down *ev = event_info; | ||
94 | Evas_Object *rect; | ||
95 | Eina_Bool r; | ||
96 | |||
97 | |||
98 | if (!strcmp(ev->keyname, "i")) | ||
99 | { | ||
100 | rect = evas_object_rectangle_add(e); | ||
101 | evas_object_color_set(rect, 0, 0, 128, 255); | ||
102 | evas_object_resize(rect, RECTW + 30, RECTH); | ||
103 | evas_object_show(rect); | ||
104 | |||
105 | printf("Inserting rect %p before the rectangle under the mouse pointer.\n", rect); | ||
106 | r = edje_object_part_box_insert_at(app->edje, "example/box", rect, 0); | ||
107 | if (!r) | ||
108 | printf("An error ocurred when appending rect %p to the box.\n", rect); | ||
109 | |||
110 | evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN, _rect_mouse_down, app); | ||
111 | } | ||
112 | else if (!strcmp(ev->keyname, "a")) | ||
113 | { | ||
114 | rect = evas_object_rectangle_add(e); | ||
115 | evas_object_color_set(rect, 0, 128, 0, 255); | ||
116 | evas_object_resize(rect, RECTW, RECTH); | ||
117 | evas_object_show(rect); | ||
118 | |||
119 | printf("Inserting rect %p before the rectangle under the mouse pointer.\n", rect); | ||
120 | r = edje_object_part_box_append(app->edje, "example/box", rect); | ||
121 | if (!r) | ||
122 | printf("An error ocurred when appending rect %p to the box.\n", rect); | ||
123 | |||
124 | evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN, _rect_mouse_down, app); | ||
125 | } | ||
126 | else if (!strcmp(ev->keyname, "c")) | ||
127 | edje_object_part_box_remove_all(app->edje, "example/box", EINA_TRUE); | ||
128 | } | ||
129 | |||
130 | int | ||
131 | main(void) | ||
132 | { | ||
133 | Evas *evas; | ||
134 | struct _App app; | ||
135 | int i; | ||
136 | |||
137 | ecore_evas_init(); | ||
138 | edje_init(); | ||
139 | |||
140 | /* this will give you a window with an Evas canvas under the first | ||
141 | * engine available */ | ||
142 | app.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | ||
143 | |||
144 | ecore_evas_callback_destroy_set(app.ee, _on_destroy); | ||
145 | ecore_evas_callback_resize_set(app.ee, _canvas_resize_cb); | ||
146 | ecore_evas_title_set(app.ee, "Edje Box Example"); | ||
147 | ecore_evas_show(app.ee); | ||
148 | |||
149 | ecore_evas_data_set(app.ee, "app", &app); | ||
150 | |||
151 | evas = ecore_evas_get(app.ee); | ||
152 | |||
153 | app.bg = evas_object_rectangle_add(evas); | ||
154 | evas_object_color_set(app.bg, 255, 255, 255, 255); | ||
155 | evas_object_resize(app.bg, WIDTH, HEIGHT); | ||
156 | evas_object_focus_set(app.bg, EINA_TRUE); | ||
157 | evas_object_show(app.bg); | ||
158 | |||
159 | evas_object_event_callback_add(app.bg, EVAS_CALLBACK_KEY_DOWN, _bg_key_down, &app); | ||
160 | |||
161 | app.edje = edje_object_add(evas); | ||
162 | |||
163 | edje_object_file_set(app.edje, edje_file_path, "example/group"); | ||
164 | evas_object_move(app.edje, 0, 0); | ||
165 | evas_object_resize(app.edje, WIDTH, HEIGHT); | ||
166 | evas_object_show(app.edje); | ||
167 | |||
168 | for (i = 0; i < NRECTS; i++) | ||
169 | { | ||
170 | Evas_Object *rect; | ||
171 | Eina_Bool r = EINA_FALSE; | ||
172 | int red = (i * 10) % 256; | ||
173 | rect = evas_object_rectangle_add(evas); | ||
174 | evas_object_color_set(rect, red, 0, 0, 255); | ||
175 | evas_object_resize(rect, RECTW, RECTH); | ||
176 | r = edje_object_part_box_append(app.edje, "example/box", rect); | ||
177 | if (!r) | ||
178 | printf("An error ocurred when appending rect #%d to the box.\n", i); | ||
179 | evas_object_show(rect); | ||
180 | |||
181 | evas_object_event_callback_add( | ||
182 | rect, EVAS_CALLBACK_MOUSE_DOWN, _rect_mouse_down, &app); | ||
183 | } | ||
184 | |||
185 | ecore_main_loop_begin(); | ||
186 | |||
187 | ecore_evas_free(app.ee); | ||
188 | ecore_evas_shutdown(); | ||
189 | edje_shutdown(); | ||
190 | return 0; | ||
191 | } | ||