2 * Simple Edje example illustrating drag functions.
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
8 * edje_cc drag.edc && gcc -o drag-box drag-box.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
19 #include <Ecore_Evas.h>
25 static const char commands[] = \
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"
39 Evas_Object *edje_obj;
43 int x, y; // relative position of part in the screen
48 _on_destroy(Ecore_Evas *ee __UNUSED__)
50 ecore_main_loop_quit();
53 /* here just to keep our example's window size and background image's
54 * size in synchrony */
56 _on_canvas_resize(Ecore_Evas *ee)
59 struct _App *app = ecore_evas_data_get(ee, "app");
61 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
62 evas_object_resize(app->bg, w, h);
63 evas_object_resize(app->edje_obj, w, h);
67 _part_move(struct _App *app, int dx, int dy)
85 snprintf(emission, sizeof(emission), "move,%d,%d", app->x, app->y);
86 edje_object_signal_emit(app->edje_obj, emission, "");
87 app->animating = EINA_TRUE;
92 _on_bg_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
94 struct _App *app = data;
95 Evas_Event_Key_Down *ev = event_info;
97 if (!strcmp(ev->keyname, "h"))
99 fprintf(stdout, commands);
102 // just moving the part and text
103 else if (!strcmp(ev->keyname, "Down"))
105 _part_move(app, 0, 1);
107 else if (!strcmp(ev->keyname, "Up"))
109 _part_move(app, 0, -1);
111 else if (!strcmp(ev->keyname, "Left"))
113 _part_move(app, -1, 0);
115 else if (!strcmp(ev->keyname, "Right"))
117 _part_move(app, 1, 0);
119 else if (!strcmp(ev->keyname, "Prior"))
121 _part_move(app, -1, -1);
123 else if (!strcmp(ev->keyname, "Next"))
125 _part_move(app, 1, 1);
127 // adjusting the perspective focal point distance
128 else if (!strcmp(ev->keyname, "KP_Add"))
131 edje_perspective_set(app->ps, 240, 160, 0, app->focal);
132 edje_object_calc_force(app->edje_obj);
134 else if (!strcmp(ev->keyname, "KP_Subtract"))
140 edje_perspective_set(app->ps, 240, 160, 0, app->focal);
141 edje_object_calc_force(app->edje_obj);
144 else if (!strcmp(ev->keyname, "Escape"))
145 ecore_main_loop_quit();
148 printf("unhandled key: %s\n", ev->keyname);
149 fprintf(stdout, commands);
154 _animation_end_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
156 struct _App *app = data;
158 app->animating = EINA_FALSE;
162 main(int argc __UNUSED__, char *argv[])
164 char edje_file_path[PATH_MAX];
165 const char *edje_file = "perspective.edj";
171 if (!ecore_evas_init())
175 goto shutdown_ecore_evas;
177 pfx = eina_prefix_new(argv[0], main,
188 edje_frametime_set(1.0 / 60.0);
190 /* this will give you a window with an Evas canvas under the first
191 * engine available */
192 app.animating = EINA_FALSE;
197 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
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");
205 ecore_evas_data_set(ee, "app", &app);
207 evas = ecore_evas_get(ee);
209 app.bg = evas_object_rectangle_add(evas);
210 evas_object_color_set(app.bg, 255, 255, 255, 255);
211 evas_object_resize(app.bg, WIDTH, HEIGHT);
212 evas_object_focus_set(app.bg, EINA_TRUE);
213 evas_object_show(app.bg);
215 evas_object_event_callback_add(app.bg, EVAS_CALLBACK_KEY_DOWN, _on_bg_key_down, &app);
217 app.edje_obj = edje_object_add(evas);
219 snprintf(edje_file_path, sizeof(edje_file_path),
220 "%s/examples/%s", eina_prefix_data_get(pfx), edje_file);
221 edje_object_file_set(app.edje_obj, edje_file_path, "example/group");
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);
226 edje_object_signal_callback_add(app.edje_obj, "animation,end", "", _animation_end_cb, &app);
228 app.ps = edje_perspective_new(evas);
229 edje_perspective_set(app.ps, 240, 160, 0, app.focal);
230 edje_perspective_global_set(app.ps, EINA_TRUE);
232 fprintf(stdout, commands);
236 ecore_main_loop_begin();
238 eina_prefix_free(pfx);
240 ecore_evas_shutdown();
246 eina_prefix_free(pfx);
250 ecore_evas_shutdown();