aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/examples/edje-perspective.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/edje/src/examples/edje-perspective.c132
1 files changed, 92 insertions, 40 deletions
diff --git a/libraries/edje/src/examples/edje-perspective.c b/libraries/edje/src/examples/edje-perspective.c
index 5220b74..1037043 100644
--- a/libraries/edje/src/examples/edje-perspective.c
+++ b/libraries/edje/src/examples/edje-perspective.c
@@ -10,10 +10,9 @@
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> 18#include <Ecore.h>
@@ -23,11 +22,21 @@
23#define WIDTH 480 22#define WIDTH 480
24#define HEIGHT 320 23#define HEIGHT 320
25 24
26static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/perspective.edj"; 25static const char commands[] = \
26 "commands are:\n"
27 "\tDown - move part down\n"
28 "\tUp - move part up\n"
29 "\tLeft - move part left\n"
30 "\tRight - move part right\n"
31 "\tPrior - move part up-left\n"
32 "\tNext - move part down-right\n"
33 "\tInsert - increase focal\n"
34 "\tSuppr - decrease focal\n"
35 "\tEsc - exit\n"
36 "\th - print help\n";
27 37
28struct _App { 38struct _App {
29 Ecore_Evas *ee; 39 Evas_Object *edje_obj;
30 Evas_Object *edje;
31 Evas_Object *bg; 40 Evas_Object *bg;
32 Edje_Perspective *ps; 41 Edje_Perspective *ps;
33 Eina_Bool animating; 42 Eina_Bool animating;
@@ -44,14 +53,14 @@ _on_destroy(Ecore_Evas *ee __UNUSED__)
44/* here just to keep our example's window size and background image's 53/* here just to keep our example's window size and background image's
45 * size in synchrony */ 54 * size in synchrony */
46static void 55static void
47_canvas_resize_cb(Ecore_Evas *ee) 56_on_canvas_resize(Ecore_Evas *ee)
48{ 57{
49 int w, h; 58 int w, h;
50 struct _App *app = ecore_evas_data_get(ee, "app"); 59 struct _App *app = ecore_evas_data_get(ee, "app");
51 60
52 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); 61 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
53 evas_object_resize(app->bg, w, h); 62 evas_object_resize(app->bg, w, h);
54 evas_object_resize(app->edje, w, h); 63 evas_object_resize(app->edje_obj, w, h);
55} 64}
56 65
57static void 66static void
@@ -74,20 +83,24 @@ _part_move(struct _App *app, int dx, int dy)
74 app->y = 0; 83 app->y = 0;
75 84
76 snprintf(emission, sizeof(emission), "move,%d,%d", app->x, app->y); 85 snprintf(emission, sizeof(emission), "move,%d,%d", app->x, app->y);
77 edje_object_signal_emit(app->edje, emission, ""); 86 edje_object_signal_emit(app->edje_obj, emission, "");
78 app->animating = EINA_TRUE; 87 app->animating = EINA_TRUE;
79} 88}
80 89
81 90
82static void 91static void
83_bg_key_down(void *data, Evas *e, Evas_Object *o __UNUSED__, void *event_info) 92_on_bg_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
84{ 93{
85 struct _App *app = data; 94 struct _App *app = data;
86 Evas_Event_Key_Down *ev = event_info; 95 Evas_Event_Key_Down *ev = event_info;
87 96
88 97 if (!strcmp(ev->keyname, "h"))
98 {
99 fprintf(stdout, commands);
100 return;
101 }
89 // just moving the part and text 102 // just moving the part and text
90 if (!strcmp(ev->keyname, "Down")) 103 else if (!strcmp(ev->keyname, "Down"))
91 { 104 {
92 _part_move(app, 0, 1); 105 _part_move(app, 0, 1);
93 } 106 }
@@ -116,7 +129,7 @@ _bg_key_down(void *data, Evas *e, Evas_Object *o __UNUSED__, void *event_info)
116 { 129 {
117 app->focal += 5; 130 app->focal += 5;
118 edje_perspective_set(app->ps, 240, 160, 0, app->focal); 131 edje_perspective_set(app->ps, 240, 160, 0, app->focal);
119 edje_object_calc_force(app->edje); 132 edje_object_calc_force(app->edje_obj);
120 } 133 }
121 else if (!strcmp(ev->keyname, "KP_Subtract")) 134 else if (!strcmp(ev->keyname, "KP_Subtract"))
122 { 135 {
@@ -125,13 +138,16 @@ _bg_key_down(void *data, Evas *e, Evas_Object *o __UNUSED__, void *event_info)
125 app->focal = 5; 138 app->focal = 5;
126 139
127 edje_perspective_set(app->ps, 240, 160, 0, app->focal); 140 edje_perspective_set(app->ps, 240, 160, 0, app->focal);
128 edje_object_calc_force(app->edje); 141 edje_object_calc_force(app->edje_obj);
129 } 142 }
130 // exiting 143 // exiting
131 else if (!strcmp(ev->keyname, "Escape")) 144 else if (!strcmp(ev->keyname, "Escape"))
132 ecore_main_loop_quit(); 145 ecore_main_loop_quit();
133 else 146 else
134 printf("unhandled key: %s\n", ev->keyname); 147 {
148 printf("unhandled key: %s\n", ev->keyname);
149 fprintf(stdout, commands);
150 }
135} 151}
136 152
137static void 153static void
@@ -143,16 +159,33 @@ _animation_end_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __
143} 159}
144 160
145int 161int
146main(void) 162main(int argc __UNUSED__, char *argv[])
147{ 163{
148 Evas *evas; 164 char edje_file_path[PATH_MAX];
149 struct _App app; 165 const char *edje_file = "perspective.edj";
150 int i; 166 struct _App app;
151 167 Ecore_Evas *ee;
152 ecore_evas_init(); 168 Evas *evas;
153 edje_init(); 169 Eina_Prefix *pfx;
154 170
155 edje_frametime_set(((double)1) / 60); 171 if (!ecore_evas_init())
172 return EXIT_FAILURE;
173
174 if (!edje_init())
175 goto shutdown_ecore_evas;
176
177 pfx = eina_prefix_new(argv[0], main,
178 "EDJE_EXAMPLES",
179 "edje/examples",
180 edje_file,
181 PACKAGE_BIN_DIR,
182 PACKAGE_LIB_DIR,
183 PACKAGE_DATA_DIR,
184 PACKAGE_DATA_DIR);
185 if (!pfx)
186 goto shutdown_edje;
187
188 edje_frametime_set(1.0 / 60.0);
156 189
157 /* this will give you a window with an Evas canvas under the first 190 /* this will give you a window with an Evas canvas under the first
158 * engine available */ 191 * engine available */
@@ -160,16 +193,18 @@ main(void)
160 app.x = 0; 193 app.x = 0;
161 app.y = 0; 194 app.y = 0;
162 app.focal = 50; 195 app.focal = 50;
163 app.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
164 196
165 ecore_evas_callback_destroy_set(app.ee, _on_destroy); 197 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
166 ecore_evas_callback_resize_set(app.ee, _canvas_resize_cb); 198 if (!ee)
167 ecore_evas_title_set(app.ee, "Edje Box Example"); 199 goto free_prefix;
168 ecore_evas_show(app.ee); 200
201 ecore_evas_callback_destroy_set(ee, _on_destroy);
202 ecore_evas_callback_resize_set(ee, _on_canvas_resize);
203 ecore_evas_title_set(ee, "Edje Box Example");
169 204
170 ecore_evas_data_set(app.ee, "app", &app); 205 ecore_evas_data_set(ee, "app", &app);
171 206
172 evas = ecore_evas_get(app.ee); 207 evas = ecore_evas_get(ee);
173 208
174 app.bg = evas_object_rectangle_add(evas); 209 app.bg = evas_object_rectangle_add(evas);
175 evas_object_color_set(app.bg, 255, 255, 255, 255); 210 evas_object_color_set(app.bg, 255, 255, 255, 255);
@@ -177,25 +212,42 @@ main(void)
177 evas_object_focus_set(app.bg, EINA_TRUE); 212 evas_object_focus_set(app.bg, EINA_TRUE);
178 evas_object_show(app.bg); 213 evas_object_show(app.bg);
179 214
180 evas_object_event_callback_add(app.bg, EVAS_CALLBACK_KEY_DOWN, _bg_key_down, &app); 215 evas_object_event_callback_add(app.bg, EVAS_CALLBACK_KEY_DOWN, _on_bg_key_down, &app);
181 216
182 app.edje = edje_object_add(evas); 217 app.edje_obj = edje_object_add(evas);
183 218
184 edje_object_file_set(app.edje, edje_file_path, "example/group"); 219 snprintf(edje_file_path, sizeof(edje_file_path),
185 evas_object_move(app.edje, 0, 0); 220 "%s/examples/%s", eina_prefix_data_get(pfx), edje_file);
186 evas_object_resize(app.edje, WIDTH, HEIGHT); 221 edje_object_file_set(app.edje_obj, edje_file_path, "example/group");
187 evas_object_show(app.edje); 222 evas_object_move(app.edje_obj, 0, 0);
223 evas_object_resize(app.edje_obj, WIDTH, HEIGHT);
224 evas_object_show(app.edje_obj);
188 225
189 edje_object_signal_callback_add(app.edje, "animation,end", "", _animation_end_cb, &app); 226 edje_object_signal_callback_add(app.edje_obj, "animation,end", "", _animation_end_cb, &app);
190 227
191 app.ps = edje_perspective_new(evas); 228 app.ps = edje_perspective_new(evas);
192 edje_perspective_set(app.ps, 240, 160, 0, app.focal); 229 edje_perspective_set(app.ps, 240, 160, 0, app.focal);
193 edje_perspective_global_set(app.ps, EINA_TRUE); 230 edje_perspective_global_set(app.ps, EINA_TRUE);
194 231
232 fprintf(stdout, commands);
233
234 ecore_evas_show(ee);
235
195 ecore_main_loop_begin(); 236 ecore_main_loop_begin();
196 237
197 ecore_evas_free(app.ee); 238 eina_prefix_free(pfx);
239 ecore_evas_free(ee);
198 ecore_evas_shutdown(); 240 ecore_evas_shutdown();
199 edje_shutdown(); 241 edje_shutdown();
200 return 0; 242
243 return EXIT_SUCCESS;
244
245 free_prefix:
246 eina_prefix_free(pfx);
247 shutdown_edje:
248 edje_shutdown();
249 shutdown_ecore_evas:
250 ecore_evas_shutdown();
251
252 return EXIT_FAILURE;
201} 253}