2 //gcc -g -DPACKAGE_DATA_DIR="\"<directory>\"" `pkg-config --cflags --libs elementary` transit_example_03.c -o transit_example_03
3 // where directory is the a path where images/plant_01.jpg can be found.
5 #include <Elementary.h>
7 # include "elementary_config.h"
12 /* structure to hold context for many callbacks */
14 Eina_Bool events_enabled;
15 Eina_Bool auto_reverse;
16 Eina_Bool final_state_keep;
18 Elm_Transit_Tween_Mode tween_mode;
23 _transit_translation(Elm_Transit *trans)
25 /* considering the original position (x0, y0), moves the object from
26 * (x0 - 20, y0 - 50) to (x0 + 70, y0 + 150) */
27 elm_transit_effect_translation_add(trans, -20, -50, 70, 150);
31 _transit_color(Elm_Transit *trans)
33 /* changes the object color from 100, 255, 100, 255 to
35 elm_transit_effect_color_add(trans, 100, 255, 100, 255, 200, 50, 200, 50);
39 _transit_rotation(Elm_Transit *trans)
41 /* rotates the object from its original angle to 135 degrees to the right */
42 elm_transit_effect_rotation_add(trans, 0.0, 135.0);
46 _transit_wipe(Elm_Transit *trans)
48 /* hide the object clipping it from the left to the right */
49 elm_transit_effect_wipe_add(trans,
50 ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
51 ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT);
55 _transit_zoom(Elm_Transit *trans)
57 /* zoom the object from its original size to 2x */
58 elm_transit_effect_zoom_add(trans, 1.0, 2.0);
62 _transit_resizing(Elm_Transit *trans)
64 /* resize the object from 250x100 to 400x160 */
65 elm_transit_effect_resizing_add(trans, 250, 100, 400, 160);
69 /* helper structure that will hold the transit checkboxes string, callbacks
70 * and checked statuses */
73 void (*transition_add_cb)(Elm_Transit *);
76 { "Translation", _transit_translation, EINA_FALSE },
77 { "Color", _transit_color, EINA_FALSE },
78 { "Rotation", _transit_rotation, EINA_FALSE },
79 { "Wipe", _transit_wipe, EINA_FALSE },
80 { "Zoom", _transit_zoom, EINA_FALSE },
81 { "Resizing", _transit_resizing, EINA_FALSE },
82 { NULL, NULL, EINA_FALSE }
86 on_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
88 /* quit the mainloop (elm_run) */
92 /* add a checkbox to the box with the given label, and uses the checked
93 * pointer as state_pointer to this checkbox */
95 _checkbox_transition_add(Evas_Object *box, const char *label, Eina_Bool *checked)
97 Evas_Object *check = elm_check_add(elm_object_parent_widget_get(box));
98 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99 evas_object_size_hint_align_set(check, 0.0, 0.0);
100 elm_object_text_set(check, label);
101 elm_check_state_pointer_set(check, checked);
102 elm_box_pack_end(box, check);
103 evas_object_show(check);
107 _transit_start(void *data, Evas_Object *o, void *event_info __UNUSED__)
109 Elm_Transit *trans = NULL;
111 struct Context *ctxt = data;
112 Evas_Object *obj = ctxt->obj; // the object on which the transition will be
115 // FIXME: Should check if there's another transit going before starting a new
118 /* initialization: create the transition and add the object to it */
119 trans = elm_transit_add();
120 elm_transit_object_add(trans, obj);
122 /* from our helper structure and array, check if the specified transition is
123 * checked and use its callback to add this transition to trans */
124 for (i = 0; _transitions[i].label; i++)
126 if (_transitions[i].checked)
127 _transitions[i].transition_add_cb(trans);
130 /* get the various options for this transition from the context structure */
131 elm_transit_event_enabled_set(trans, ctxt->events_enabled);
132 elm_transit_auto_reverse_set(trans, ctxt->auto_reverse);
133 elm_transit_objects_final_state_keep_set(trans, ctxt->final_state_keep);
134 elm_transit_tween_mode_set(trans, ctxt->tween_mode);
135 elm_transit_repeat_times_set(trans, ctxt->repeat_times);
137 /* set the transition time to 2 seconds and start it */
138 elm_transit_duration_set(trans, 2.0);
139 elm_transit_go(trans);
142 /* callback useful just to know whether we can receive events from the
145 _object_clicked(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
147 printf("object clicked!\n");
150 /* update our context with the given value for repeat count */
152 _cb_repeat_changed(void *data, Evas_Object *obj, void *event __UNUSED__)
154 int *repeat_cnt = data;
156 *repeat_cnt = elm_spinner_value_get(obj);
159 /* update our context with the given tween mode for the transition */
161 _cb_tween_changed(void *data, Evas_Object *obj, void *event __UNUSED__)
163 Elm_Transit_Tween_Mode *mode = data;
166 val = elm_spinner_value_get(obj);
168 *mode = ELM_TRANSIT_TWEEN_MODE_LINEAR;
170 *mode = ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL;
172 *mode = ELM_TRANSIT_TWEEN_MODE_DECELERATE;
174 *mode = ELM_TRANSIT_TWEEN_MODE_ACCELERATE;
178 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
180 Evas_Object *win, *bg, *obj, *icon, *box, *vbox, *vbox2, *hbox, *btn, *fr;
181 Evas_Object *cbox, *dummy, *spinner;
185 struct Context context;
187 /* initialize our context */
188 context.events_enabled = EINA_FALSE;
189 context.auto_reverse = EINA_FALSE;
190 context.final_state_keep = EINA_FALSE;
191 context.repeat_times = 0;
192 context.tween_mode = ELM_TRANSIT_TWEEN_MODE_LINEAR;
195 win = elm_win_add(NULL, "transit", ELM_WIN_BASIC);
196 elm_win_title_set(win, "Transit Example");
197 evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
198 elm_win_autodel_set(win, EINA_TRUE);
200 /* add a scalable white background to this window */
201 bg = elm_bg_add(win);
202 elm_bg_color_set(bg, 255, 255, 255);
203 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
204 evas_object_size_hint_min_set(bg, 640, 640);
205 evas_object_size_hint_max_set(bg, 640, 640);
206 elm_win_resize_object_add(win, bg);
207 evas_object_show(bg);
209 /* add a vertical box that will hold everything */
210 box = elm_box_add(win);
211 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
212 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
213 elm_win_resize_object_add(win, box);
214 evas_object_show(box);
216 /* a dummy background to create some space for the animation */
217 dummy = elm_bg_add(win);
218 evas_object_size_hint_weight_set(dummy, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219 elm_box_pack_end(box, dummy);
220 evas_object_show(dummy);
222 /* add an object that we are going to play with */
223 /* this object isn't packed inside the box because we don't want it to have
224 * its size, position, aspect or anything else controled by the container */
225 obj = elm_button_add(win);
226 elm_object_text_set(obj, "Transformed object!");
227 icon = elm_icon_add(win);
228 snprintf(buf, sizeof(buf), "%s/images/icon_07.png", PACKAGE_DATA_DIR);
229 elm_icon_file_set(icon, buf, NULL);
230 elm_object_content_part_set(obj, "icon", icon);
231 evas_object_move(obj, 160, 60);
232 evas_object_resize(obj, 250, 100);
233 evas_object_show(obj);
236 /* a callback to know if clicks are being received */
237 evas_object_smart_callback_add(obj, "clicked", _object_clicked, NULL);
239 /* button to start our transition */
240 btn = elm_button_add(win);
241 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
242 elm_object_text_set(btn, "Transit!");
243 elm_box_pack_end(box, btn);
244 evas_object_show(btn);
245 evas_object_smart_callback_add(btn, "clicked", _transit_start, &context);
247 /* horizontal box to help visual organization */
248 hbox = elm_box_add(win);
249 elm_box_horizontal_set(hbox, EINA_TRUE);
250 evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
251 evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, 0.0);
252 elm_box_pack_end(box, hbox);
253 evas_object_show(hbox);
255 /* horizontal box that will hold the many transition checkboxes */
256 vbox = elm_box_add(win);
257 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
258 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, 0.0);
260 /* create the respective checkboxes based on our helper structure and
262 for (i = 0; _transitions[i].label; i++)
263 _checkbox_transition_add(vbox, _transitions[i].label,
264 &_transitions[i].checked);
266 elm_box_pack_end(hbox, vbox);
267 evas_object_show(vbox);
269 /* vertical box that will hold the many transition option checkboxes */
270 vbox2 = elm_box_add(win);
271 evas_object_size_hint_weight_set(vbox2, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
272 evas_object_size_hint_align_set(vbox2, EVAS_HINT_FILL, 0.0);
273 elm_box_pack_end(hbox, vbox2);
274 evas_object_show(vbox2);
276 /* the rest of this code adds widgets to control some of the behavior of
278 cbox = elm_check_add(win);
279 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
280 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
281 elm_object_text_set(cbox, "Events enabled");
282 elm_check_state_pointer_set(cbox, &context.events_enabled);
283 elm_box_pack_end(vbox2, cbox);
284 evas_object_show(cbox);
286 cbox = elm_check_add(win);
287 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
288 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
289 elm_object_text_set(cbox, "Auto reverse");
290 elm_check_state_pointer_set(cbox, &context.auto_reverse);
291 elm_box_pack_end(vbox2, cbox);
292 evas_object_show(cbox);
294 cbox = elm_check_add(win);
295 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
296 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
297 elm_object_text_set(cbox, "Keep final state");
298 elm_check_state_pointer_set(cbox, &context.final_state_keep);
299 elm_box_pack_end(vbox2, cbox);
300 evas_object_show(cbox);
302 spinner = elm_spinner_add(win);
303 elm_object_style_set(spinner, "vertical");
304 elm_spinner_min_max_set(spinner, 0, 4);
305 elm_spinner_label_format_set(spinner, "%.0f");
306 elm_spinner_editable_set(spinner, EINA_FALSE);
307 evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
308 evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
309 evas_object_smart_callback_add(spinner, "changed", _cb_repeat_changed, &context.repeat_times);
310 elm_box_pack_end(vbox2, spinner);
311 evas_object_show(spinner);
313 spinner = elm_spinner_add(win);
314 elm_object_style_set(spinner, "vertical");
315 elm_spinner_min_max_set(spinner, 1, 4);
316 elm_spinner_label_format_set(spinner, "%.0f");
317 elm_spinner_editable_set(spinner, EINA_FALSE);
318 elm_spinner_special_value_add(spinner, 1, "linear");
319 elm_spinner_special_value_add(spinner, 2, "sinusoidal");
320 elm_spinner_special_value_add(spinner, 3, "decelerate");
321 elm_spinner_special_value_add(spinner, 4, "accelerate");
322 evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
323 evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
324 evas_object_size_hint_min_set(spinner, 200, 30);
325 evas_object_smart_callback_add(spinner, "changed", _cb_tween_changed, &context.tween_mode);
326 elm_box_pack_end(vbox2, spinner);
327 evas_object_show(spinner);
329 evas_object_show(win);