aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/examples/edje-animations.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/edje/src/examples/edje-animations.c')
-rw-r--r--libraries/edje/src/examples/edje-animations.c227
1 files changed, 0 insertions, 227 deletions
diff --git a/libraries/edje/src/examples/edje-animations.c b/libraries/edje/src/examples/edje-animations.c
deleted file mode 100644
index 15f2ee0..0000000
--- a/libraries/edje/src/examples/edje-animations.c
+++ /dev/null
@@ -1,227 +0,0 @@
1/**
2 * Simple Edje example illustrating animations 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 animations.edc && gcc -o edje-animations edje-animations.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 __UNUSED__
16#endif
17
18#include <Ecore.h>
19#include <Ecore_Evas.h>
20#include <Edje.h>
21
22#define WIDTH (400)
23#define HEIGHT (300)
24
25static const char commands[] = \
26 "commands are:\n"
27 "\t+ - increase frametime\n"
28 "\t- - decrease frametime\n"
29 "\t= - status of the animation\n"
30 "\ts - pause\n"
31 "\tp - play\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"
38 "\tEsc - exit\n"
39 "\th - print help\n";
40
41static double frametime = 1.0 / 30.0; /* default value */
42
43static void
44_on_delete_cb(Ecore_Evas *ee __UNUSED__)
45{
46 ecore_main_loop_quit();
47}
48
49static void
50_on_canvas_resize(Ecore_Evas *ee)
51{
52 Evas_Object *bg;
53 Evas_Object *edje_obj;
54 int w;
55 int h;
56
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);
62}
63
64static void
65_on_key_down(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
66{
67 Evas_Event_Key_Down *ev;
68 double ft;
69
70 ev = (Evas_Event_Key_Down *)event_info;
71
72 if (!strcmp(ev->keyname, "h"))
73 {
74 fprintf(stdout, commands);
75 return;
76 }
77 else if (!strcmp(ev->key, "plus"))
78 {
79 frametime *= 2.0;
80 fprintf(stdout, "Increasing frametime to: %f\n", frametime);
81 edje_frametime_set(frametime);
82 }
83 else if (!strcmp(ev->key, "minus"))
84 {
85 frametime /= 2.0;
86 fprintf(stdout, "Decreasing frametime to: %f\n", frametime);
87 edje_frametime_set(frametime);
88 }
89 else if (!strcmp(ev->key, "equal"))
90 {
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");
95 else
96 fprintf(stdout, "Object was paused\n");
97 if (edje_object_animation_get(obj))
98 fprintf(stdout, "Animation is running\n");
99 else
100 fprintf(stdout, "Animation was stopped\n");
101 }
102 else if (!strcmp(ev->key, "s"))
103 {
104 edje_object_play_set(obj, EINA_FALSE);
105 fprintf(stdout, "Pausing the object\n");
106 }
107 else if (!strcmp(ev->key, "p"))
108 {
109 edje_object_play_set(obj, EINA_TRUE);
110 fprintf(stdout, "Playing the object\n");
111 }
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"))
117 {
118 edje_freeze();
119 fprintf(stdout, "Freezing all objects\n");
120 }
121 else if (!strcmp(ev->key, "T"))
122 {
123 edje_thaw();
124 fprintf(stdout, "Thawing all objects\n");
125 }
126 else if (!strcmp(ev->key, "a"))
127 {
128 edje_object_animation_set(obj, EINA_TRUE);
129 fprintf(stdout, "Starting the animation in the Edje object\n");
130 }
131 else if (!strcmp(ev->key, "A"))
132 {
133 edje_object_animation_set(obj, EINA_FALSE);
134 fprintf(stdout, "Stopping the animation in the Edje object\n");
135 }
136 else if (!strcmp(ev->keyname, "Escape"))
137 ecore_main_loop_quit();
138 else
139 {
140 printf("unhandled key: %s\n", ev->keyname);
141 fprintf(stdout, commands);
142 }
143}
144
145int
146main(int argc __UNUSED__, char *argv[])
147{
148 char edje_file_path[PATH_MAX];
149 const char *edje_file = "animations.edj";
150 Ecore_Evas *ee;
151 Evas *evas;
152 Evas_Object *bg;
153 Evas_Object *edje_obj;
154 Eina_Prefix *pfx;
155
156 if (!ecore_evas_init())
157 return EXIT_FAILURE;
158
159 if (!edje_init())
160 goto shutdown_ecore_evas;
161
162 pfx = eina_prefix_new(argv[0], main,
163 "EDJE_EXAMPLES",
164 "edje/examples",
165 edje_file,
166 PACKAGE_BIN_DIR,
167 PACKAGE_LIB_DIR,
168 PACKAGE_DATA_DIR,
169 PACKAGE_DATA_DIR);
170 if (!pfx)
171 goto shutdown_edje;
172
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);
176 if (!ee)
177 goto free_prefix;
178
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");
182
183 evas = ecore_evas_get(ee);
184
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);
191
192 edje_obj = edje_object_add(evas);
193
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);
201
202 evas_object_event_callback_add(edje_obj, EVAS_CALLBACK_KEY_DOWN,
203 _on_key_down, NULL);
204 evas_object_focus_set(edje_obj, EINA_TRUE);
205
206 fprintf(stdout, commands);
207
208 ecore_evas_show(ee);
209
210 ecore_main_loop_begin();
211
212 eina_prefix_free(pfx);
213 ecore_evas_free(ee);
214 ecore_evas_shutdown();
215 edje_shutdown();
216
217 return EXIT_SUCCESS;
218
219 free_prefix:
220 eina_prefix_free(pfx);
221 shutdown_edje:
222 edje_shutdown();
223 shutdown_ecore_evas:
224 ecore_evas_shutdown();
225
226 return EXIT_FAILURE;
227}