aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/examples/edje-box2.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-04-22 09:19:23 +1000
committerDavid Walter Seikel2012-04-22 09:19:23 +1000
commitc963d75dfdeec11f82e79e727062fbf89afa2c04 (patch)
tree895633dbf641110be46f117c29890c49b3ffc0bd /libraries/edje/src/examples/edje-box2.c
parentAdding the new extantz viewer and grid manager. (diff)
downloadSledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.zip
SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.gz
SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.bz2
SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.xz
Update EFL to latest beta.
Diffstat (limited to 'libraries/edje/src/examples/edje-box2.c')
-rw-r--r--libraries/edje/src/examples/edje-box2.c187
1 files changed, 115 insertions, 72 deletions
diff --git a/libraries/edje/src/examples/edje-box2.c b/libraries/edje/src/examples/edje-box2.c
index b3f4e40..81f1a90 100644
--- a/libraries/edje/src/examples/edje-box2.c
+++ b/libraries/edje/src/examples/edje-box2.c
@@ -10,40 +10,35 @@
10 */ 10 */
11 11
12#ifdef HAVE_CONFIG_H 12#ifdef HAVE_CONFIG_H
13#include "config.h" 13# include "config.h"
14#else 14#else
15#define PACKAGE_EXAMPLES_DIR "." 15# define __UNUSED__
16#define __UNUSED__
17#endif 16#endif
18 17
19#include <Ecore.h>
20#include <Evas.h>
21#include <Ecore_Evas.h>
22#include <Edje.h>
23
24#include <stdlib.h> 18#include <stdlib.h>
25#include <stdio.h> 19#include <stdio.h>
26#include <string.h> 20#include <string.h>
27 21
28static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/box.edj"; 22#include <Ecore.h>
29 23#include <Evas.h>
30struct _App { 24#include <Ecore_Evas.h>
31 Ecore_Evas *ee; 25#include <Edje.h>
32 Evas *evas;
33 Evas_Object *bg;
34 Evas_Object *box;
35};
36 26
37static struct _App app; 27static const char commands[] = \
28 "commands are:\n"
29 "\tShift - remove box\n"
30 "\tCtrl - insert box\n"
31 "\tEsc - exit\n"
32 "\th - print help\n";
38 33
39static void 34static void
40custom_layout(Evas_Object *o, Evas_Object_Box_Data *p, void *data) 35custom_layout(Evas_Object *o, Evas_Object_Box_Data *p, void *data __UNUSED__)
41{ 36{
37 Evas_Object_Box_Option *opt;
38 Eina_List *l;
42 int x, y, w, h; 39 int x, y, w, h;
43 int xx, yy, ww, hh; 40 int xx, yy, ww, hh;
44 int count; 41 int count;
45 Eina_List *l;
46 Evas_Object_Box_Option *opt;
47 42
48 evas_object_geometry_get(o, &x, &y, &w, &h); 43 evas_object_geometry_get(o, &x, &y, &w, &h);
49 count = eina_list_count(p->children); 44 count = eina_list_count(p->children);
@@ -76,129 +71,177 @@ new_greenie_block(Evas *e)
76} 71}
77 72
78static void 73static void
79on_keydown(void *data, Evas *evas, Evas_Object *o, void *einfo) 74on_keydown(void *data, Evas *evas, Evas_Object *o __UNUSED__, void *einfo)
80{ 75{
81 struct _App *app = data; 76 Evas_Event_Key_Down *ev;
82 Evas_Event_Key_Down *ev = einfo; 77 Evas_Object *edje_obj;
83 const Evas_Modifier *mods; 78 const Evas_Modifier *mods;
84 79
80 ev = (Evas_Event_Key_Down *)einfo;
81 edje_obj = (Evas_Object *)data;
82
85 mods = evas_key_modifier_get(evas); 83 mods = evas_key_modifier_get(evas);
84 if (!strcmp(ev->keyname, "h"))
85 {
86 fprintf(stdout, commands);
87 return;
88 }
86 if (evas_key_modifier_is_set(mods, "Shift")) 89 if (evas_key_modifier_is_set(mods, "Shift"))
87 { 90 {
88 int pos; 91 int pos;
89 Evas_Object *obj = NULL; 92 Evas_Object *obj = NULL;
90 pos = atoi(ev->keyname); 93 pos = atoi(ev->keyname);
91 obj = edje_object_part_box_remove_at(app->box, "example/box", pos); 94 obj = edje_object_part_box_remove_at(edje_obj, "example/box", pos);
92 if (obj) 95 if (obj)
93 evas_object_del(obj); 96 evas_object_del(obj);
94 return; 97 return;
95 } 98 }
96 if (evas_key_modifier_is_set(mods, "Control")) 99 if (evas_key_modifier_is_set(mods, "Control"))
97 { 100 {
98 Evas_Object *o; 101 Evas_Object *obj;
99 int pos; 102 int pos;
100 pos = atoi(ev->keyname); 103 pos = atoi(ev->keyname);
101 o = new_greenie_block(app->evas); 104 obj = new_greenie_block(evas);
102 if (!edje_object_part_box_insert_at(app->box, "example/box", o, pos)) 105 if (!edje_object_part_box_insert_at(edje_obj, "example/box", obj, pos))
103 edje_object_part_box_append(app->box, "example/box", o); 106 edje_object_part_box_append(edje_obj, "example/box", obj);
104 return; 107 return;
105 } 108 }
106 if (strcmp(ev->keyname, "Escape") == 0) 109 if (!strcmp(ev->keyname, "Escape"))
107 ecore_main_loop_quit(); 110 ecore_main_loop_quit();
108} 111}
109 112
110static Evas_Object * 113static Evas_Object *
111box_new(Evas *evas, const char *name, int x, int y, int w, int h) 114box_new(Ecore_Evas *ee, const char *edje_file_path, const char *name, int x, int y, int w, int h)
112{ 115{
113 Evas_Object *o; 116 Evas_Object *edje_obj;
114 117
115 o = edje_object_add(evas); 118 edje_obj = edje_object_add(ecore_evas_get(ee));
116 evas_object_move(o, x, y); 119 evas_object_move(edje_obj, x, y);
117 evas_object_resize(o, w, h); 120 evas_object_resize(edje_obj, w, h);
118 if (!edje_object_file_set(o, edje_file_path, "example/group2")) 121 if (!edje_object_file_set(edje_obj, edje_file_path, "example/group2"))
119 { 122 {
120 printf("error: could not load file object.\n"); 123 printf("error: could not load file object.\n");
121 } 124 }
122 evas_object_show(o); 125 evas_object_show(edje_obj);
123 126 evas_object_name_set(edje_obj, name);
124 evas_object_name_set(o, name); 127 ecore_evas_data_set(ee, "edje_obj", edje_obj);
125 128
126 return o; 129 return edje_obj;
127} 130}
128 131
129static void 132static void
130on_resize(Ecore_Evas *ee) 133on_resize(Ecore_Evas *ee)
131{ 134{
132 int w, h; 135 Evas_Object *bg;
133 136 Evas_Object *edje_obj;
134 evas_output_viewport_get(app.evas, NULL, NULL, &w, &h); 137 int w;
135 evas_object_resize(app.bg, w, h); 138 int h;
136 evas_object_resize(app.box, w, h); 139
140 bg = ecore_evas_data_get(ee, "background");
141 edje_obj = ecore_evas_data_get(ee, "edje_obj");
142 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
143 evas_object_resize(bg, w, h);
144 evas_object_resize(edje_obj, w, h);
137} 145}
138 146
139static void 147static void
140on_destroy(Ecore_Evas *ee) 148on_destroy(Ecore_Evas *ee __UNUSED__)
141{ 149{
142 ecore_main_loop_quit(); 150 ecore_main_loop_quit();
143} 151}
144 152
145int 153int
146main(int argc, char *argv[]) 154main(int argc __UNUSED__, char *argv[])
147{ 155{
148 Ecore_Evas *ee; 156 char edje_file_path[PATH_MAX];
149 int w, h, i; 157 const char *edje_file = "box.edj";
158 Ecore_Evas *ee;
159 Evas *evas;
160 Evas_Object *bg;
161 Evas_Object *edje_obj;
150 Evas_Object *last; 162 Evas_Object *last;
151 Evas_Object *o; 163 Evas_Object *o;
152 164 Eina_Prefix *pfx;
153 evas_init(); 165 int w;
154 ecore_init(); 166 int h;
155 ecore_evas_init(); 167 int i;
156 edje_init(); 168
157 169 if (!ecore_evas_init())
170 return EXIT_FAILURE;
171
172 if (!edje_init())
173 goto shutdown_ecore_evas;
174
175 pfx = eina_prefix_new(argv[0], main,
176 "EDJE_EXAMPLES",
177 "edje/examples",
178 edje_file,
179 PACKAGE_BIN_DIR,
180 PACKAGE_LIB_DIR,
181 PACKAGE_DATA_DIR,
182 PACKAGE_DATA_DIR);
183 if (!pfx)
184 goto shutdown_edje;
185
186 /* this will give you a window with an Evas canvas under the first
187 * engine available */
158 ee = ecore_evas_new(NULL, 0, 0, 640, 480, NULL); 188 ee = ecore_evas_new(NULL, 0, 0, 640, 480, NULL);
159 ecore_evas_show(ee); 189 if (!ee)
160 190 goto free_prefix;
161 app.ee = ee;
162 app.evas = ecore_evas_get(ee);
163 191
164 ecore_evas_callback_resize_set(ee, on_resize); 192 ecore_evas_callback_resize_set(ee, on_resize);
165 ecore_evas_callback_destroy_set(ee, on_destroy); 193 ecore_evas_callback_destroy_set(ee, on_destroy);
194 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
166 195
167 evas_output_viewport_get(app.evas, NULL, NULL, &w, &h); 196 evas = ecore_evas_get(ee);
168 197
169 app.bg = evas_object_rectangle_add(app.evas); 198 bg = evas_object_rectangle_add(evas);
170 evas_object_resize(app.bg, w, h); 199 evas_object_resize(bg, w, h);
171 evas_object_show(app.bg); 200 evas_object_show(bg);
172 evas_object_focus_set(app.bg, 1); 201 evas_object_focus_set(bg, 1);
173 evas_object_event_callback_add( 202 ecore_evas_data_set(ee, "background", bg);
174 app.bg, EVAS_CALLBACK_KEY_DOWN, on_keydown, &app);
175 203
176 edje_box_layout_register("custom_layout", custom_layout, NULL, NULL, NULL, NULL); 204 edje_box_layout_register("custom_layout", custom_layout, NULL, NULL, NULL, NULL);
177 205
178 app.box = box_new(app.evas, "box", 0, 0, w, h); 206 snprintf(edje_file_path, sizeof(edje_file_path),
207 "%s/examples/%s", eina_prefix_data_get(pfx), edje_file);
208 edje_obj = box_new(ee, edje_file_path, "box", 0, 0, w, h);
209 evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, on_keydown, edje_obj);
179 210
180 for (i = 1; i <= 5; i++) 211 for (i = 1; i <= 5; i++)
181 { 212 {
182 o = last = evas_object_rectangle_add(app.evas); 213 o = last = evas_object_rectangle_add(evas);
183 evas_object_size_hint_min_set(o, 50, 50); 214 evas_object_size_hint_min_set(o, 50, 50);
184 evas_object_resize(o, 50, 50); 215 evas_object_resize(o, 50, 50);
185 evas_object_color_set(o, 255, 0, 0, 128); 216 evas_object_color_set(o, 255, 0, 0, 128);
186 evas_object_show(o); 217 evas_object_show(o);
187 218
188 if (!edje_object_part_box_append(app.box, "example/box", o)) 219 if (!edje_object_part_box_append(edje_obj, "example/box", o))
189 { 220 {
190 fprintf(stderr, "error appending child object!\n"); 221 fprintf(stderr, "error appending child object!\n");
191 return 1; 222 return 1;
192 } 223 }
193 } 224 }
194 225
226 fprintf(stdout, commands);
227
228 ecore_evas_show(ee);
229
195 ecore_main_loop_begin(); 230 ecore_main_loop_begin();
196 231
197 edje_shutdown(); 232 eina_prefix_free(pfx);
233 ecore_evas_free(ee);
198 ecore_evas_shutdown(); 234 ecore_evas_shutdown();
199 ecore_shutdown(); 235 edje_shutdown();
200 evas_shutdown(); 236
237 return EXIT_SUCCESS;
201 238
239 free_prefix:
240 eina_prefix_free(pfx);
241 shutdown_edje:
242 edje_shutdown();
243 shutdown_ecore_evas:
244 ecore_evas_shutdown();
202 245
203 return 0; 246 return EXIT_FAILURE;
204} 247}