2 * Simple Edje example illustrating animations 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 animations.edc && gcc -o edje-animations edje-animations.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
19 #include <Ecore_Evas.h>
25 static const char commands[] = \
27 "\t+ - increase frametime\n"
28 "\t- - decrease frametime\n"
29 "\t= - status of the animation\n"
32 "\tf - freeze one object\n"
33 "\tF - freeze all objects\n"
34 "\tt - thaw one object\n"
35 "\tT - thaw all objects\n"
36 "\ta - start animation of one object\n"
37 "\tA - stop animation of one object\n"
41 static double frametime = 1.0 / 30.0; /* default value */
44 _on_delete_cb(Ecore_Evas *ee __UNUSED__)
46 ecore_main_loop_quit();
50 _on_canvas_resize(Ecore_Evas *ee)
53 Evas_Object *edje_obj;
57 bg = ecore_evas_data_get(ee, "background");
58 edje_obj = ecore_evas_data_get(ee, "edje_obj");
59 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
60 evas_object_resize(bg, w, h);
61 evas_object_resize(edje_obj, w, h);
65 _on_key_down(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
67 Evas_Event_Key_Down *ev;
70 ev = (Evas_Event_Key_Down *)event_info;
72 if (!strcmp(ev->keyname, "h"))
74 fprintf(stdout, commands);
77 else if (!strcmp(ev->key, "plus"))
80 fprintf(stdout, "Increasing frametime to: %f\n", frametime);
81 edje_frametime_set(frametime);
83 else if (!strcmp(ev->key, "minus"))
86 fprintf(stdout, "Decreasing frametime to: %f\n", frametime);
87 edje_frametime_set(frametime);
89 else if (!strcmp(ev->key, "equal"))
91 ft = edje_frametime_get();
92 fprintf(stdout, "Frametime: %f\n", ft);
93 if (edje_object_play_get(obj))
94 fprintf(stdout, "Object is playing\n");
96 fprintf(stdout, "Object was paused\n");
97 if (edje_object_animation_get(obj))
98 fprintf(stdout, "Animation is running\n");
100 fprintf(stdout, "Animation was stopped\n");
102 else if (!strcmp(ev->key, "s"))
104 edje_object_play_set(obj, EINA_FALSE);
105 fprintf(stdout, "Pausing the object\n");
107 else if (!strcmp(ev->key, "p"))
109 edje_object_play_set(obj, EINA_TRUE);
110 fprintf(stdout, "Playing the object\n");
112 else if (!strcmp(ev->key, "f"))
113 fprintf(stdout, "Freezing object. Count: %d\n", edje_object_freeze(obj));
114 else if (!strcmp(ev->key, "t"))
115 fprintf(stdout, "Thawing object. Count: %d\n", edje_object_thaw(obj));
116 else if (!strcmp(ev->key, "F"))
119 fprintf(stdout, "Freezing all objects\n");
121 else if (!strcmp(ev->key, "T"))
124 fprintf(stdout, "Thawing all objects\n");
126 else if (!strcmp(ev->key, "a"))
128 edje_object_animation_set(obj, EINA_TRUE);
129 fprintf(stdout, "Starting the animation in the Edje object\n");
131 else if (!strcmp(ev->key, "A"))
133 edje_object_animation_set(obj, EINA_FALSE);
134 fprintf(stdout, "Stopping the animation in the Edje object\n");
136 else if (!strcmp(ev->keyname, "Escape"))
137 ecore_main_loop_quit();
140 printf("unhandled key: %s\n", ev->keyname);
141 fprintf(stdout, commands);
146 main(int argc __UNUSED__, char *argv[])
148 char edje_file_path[PATH_MAX];
149 const char *edje_file = "animations.edj";
153 Evas_Object *edje_obj;
156 if (!ecore_evas_init())
160 goto shutdown_ecore_evas;
162 pfx = eina_prefix_new(argv[0], main,
173 /* this will give you a window with an Evas canvas under the first
174 * engine available */
175 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
179 ecore_evas_callback_delete_request_set(ee, _on_delete_cb);
180 ecore_evas_callback_resize_set(ee, _on_canvas_resize);
181 ecore_evas_title_set(ee, "Edje Animations Example");
183 evas = ecore_evas_get(ee);
185 bg = evas_object_rectangle_add(evas);
186 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
187 evas_object_move(bg, 0, 0); /* at canvas' origin */
188 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
189 evas_object_show(bg);
190 ecore_evas_data_set(ee, "background", bg);
192 edje_obj = edje_object_add(evas);
194 snprintf(edje_file_path, sizeof(edje_file_path),
195 "%s/examples/%s", eina_prefix_data_get(pfx), edje_file);
196 edje_object_file_set(edje_obj, edje_file_path, "animations_group");
197 evas_object_move(edje_obj, 0, 0);
198 evas_object_resize(edje_obj, WIDTH, HEIGHT);
199 evas_object_show(edje_obj);
200 ecore_evas_data_set(ee, "edje_obj", edje_obj);
202 evas_object_event_callback_add(edje_obj, EVAS_CALLBACK_KEY_DOWN,
204 evas_object_focus_set(edje_obj, EINA_TRUE);
206 fprintf(stdout, commands);
210 ecore_main_loop_begin();
212 eina_prefix_free(pfx);
214 ecore_evas_shutdown();
220 eina_prefix_free(pfx);
224 ecore_evas_shutdown();