2 //gcc -o transit_example_03 transit_example_03.c `pkg-config --cflags --libs elementary` -DPACKAGE_DATA_DIR="\"<directory>\""
3 //where directory is the a path where images/icon_07.png can be found.
5 #include <Elementary.h>
7 /* structure to hold context for many callbacks */
9 Eina_Bool events_enabled;
10 Eina_Bool auto_reverse;
11 Eina_Bool final_state_keep;
13 Elm_Transit_Tween_Mode tween_mode;
18 _transit_translation(Elm_Transit *trans)
20 /* considering the original position (x0, y0), moves the object from
21 * (x0 - 20, y0 - 50) to (x0 + 70, y0 + 150) */
22 elm_transit_effect_translation_add(trans, -20, -50, 70, 150);
26 _transit_color(Elm_Transit *trans)
28 /* changes the object color from 100, 255, 100, 255 to
30 elm_transit_effect_color_add(trans, 100, 255, 100, 255, 200, 50, 200, 50);
34 _transit_rotation(Elm_Transit *trans)
36 /* rotates the object from its original angle to 135 degrees to the right */
37 elm_transit_effect_rotation_add(trans, 0.0, 135.0);
41 _transit_wipe(Elm_Transit *trans)
43 /* hide the object clipping it from the left to the right */
44 elm_transit_effect_wipe_add(trans,
45 ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
46 ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT);
50 _transit_zoom(Elm_Transit *trans)
52 /* zoom the object from its original size to 2x */
53 elm_transit_effect_zoom_add(trans, 1.0, 2.0);
57 _transit_resizing(Elm_Transit *trans)
59 /* resize the object from 250x100 to 400x160 */
60 elm_transit_effect_resizing_add(trans, 250, 100, 400, 160);
64 /* helper structure that will hold the transit checkboxes string, callbacks
65 * and checked statuses */
68 void (*transition_add_cb)(Elm_Transit *);
71 { "Translation", _transit_translation, EINA_FALSE },
72 { "Color", _transit_color, EINA_FALSE },
73 { "Rotation", _transit_rotation, EINA_FALSE },
74 { "Wipe", _transit_wipe, EINA_FALSE },
75 { "Zoom", _transit_zoom, EINA_FALSE },
76 { "Resizing", _transit_resizing, EINA_FALSE },
77 { NULL, NULL, EINA_FALSE }
81 on_done(void *data, Evas_Object *obj, void *event_info)
83 /* quit the mainloop (elm_run) */
87 /* add a checkbox to the box with the given label, and uses the checked
88 * pointer as state_pointer to this checkbox */
90 _checkbox_transition_add(Evas_Object *box, const char *label, Eina_Bool *checked)
92 Evas_Object *check = elm_check_add(elm_object_parent_widget_get(box));
93 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
94 evas_object_size_hint_align_set(check, 0.0, 0.0);
95 elm_object_text_set(check, label);
96 elm_check_state_pointer_set(check, checked);
97 elm_box_pack_end(box, check);
98 evas_object_show(check);
102 _transit_start(void *data, Evas_Object *o, void *event_info)
104 Elm_Transit *trans = NULL;
106 struct Context *ctxt = data;
107 Evas_Object *obj = ctxt->obj; // the object on which the transition will be
110 // FIXME: Should check if there's another transit going before starting a new
113 /* initialization: create the transition and add the object to it */
114 trans = elm_transit_add();
115 elm_transit_object_add(trans, obj);
117 /* from our helper structure and array, check if the specified transition is
118 * checked and use its callback to add this transition to trans */
119 for (i = 0; _transitions[i].label; i++)
121 if (_transitions[i].checked)
122 _transitions[i].transition_add_cb(trans);
125 /* get the various options for this transition from the context structure */
126 elm_transit_event_enabled_set(trans, ctxt->events_enabled);
127 elm_transit_auto_reverse_set(trans, ctxt->auto_reverse);
128 elm_transit_objects_final_state_keep_set(trans, ctxt->final_state_keep);
129 elm_transit_tween_mode_set(trans, ctxt->tween_mode);
130 elm_transit_repeat_times_set(trans, ctxt->repeat_times);
132 /* set the transition time to 2 seconds and start it */
133 elm_transit_duration_set(trans, 2.0);
134 elm_transit_go(trans);
137 /* callback useful just to know whether we can receive events from the
140 _object_clicked(void *data, Evas_Object *o, void *event_info)
142 printf("object clicked!\n");
145 /* update our context with the given value for repeat count */
147 _cb_repeat_changed(void *data, Evas_Object *obj, void *event)
149 int *repeat_cnt = data;
151 *repeat_cnt = elm_spinner_value_get(obj);
154 /* update our context with the given tween mode for the transition */
156 _cb_tween_changed(void *data, Evas_Object *obj, void *event)
158 Elm_Transit_Tween_Mode *mode = data;
161 val = elm_spinner_value_get(obj);
163 *mode = ELM_TRANSIT_TWEEN_MODE_LINEAR;
165 *mode = ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL;
167 *mode = ELM_TRANSIT_TWEEN_MODE_DECELERATE;
169 *mode = ELM_TRANSIT_TWEEN_MODE_ACCELERATE;
173 elm_main(int argc, char **argv)
175 Evas_Object *win, *bg, *obj, *icon, *box, *vbox, *vbox2, *hbox, *btn;
176 Evas_Object *cbox, *dummy, *spinner;
179 struct Context context;
181 /* initialize our context */
182 context.events_enabled = EINA_FALSE;
183 context.auto_reverse = EINA_FALSE;
184 context.final_state_keep = EINA_FALSE;
185 context.repeat_times = 0;
186 context.tween_mode = ELM_TRANSIT_TWEEN_MODE_LINEAR;
189 win = elm_win_add(NULL, "transit", ELM_WIN_BASIC);
190 elm_win_title_set(win, "Transit Example");
191 evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
192 elm_win_autodel_set(win, EINA_TRUE);
194 /* add a scalable white background to this window */
195 bg = elm_bg_add(win);
196 elm_bg_color_set(bg, 255, 255, 255);
197 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
198 evas_object_size_hint_min_set(bg, 640, 640);
199 evas_object_size_hint_max_set(bg, 640, 640);
200 elm_win_resize_object_add(win, bg);
201 evas_object_show(bg);
203 /* add a vertical box that will hold everything */
204 box = elm_box_add(win);
205 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
206 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
207 elm_win_resize_object_add(win, box);
208 evas_object_show(box);
210 /* a dummy background to create some space for the animation */
211 dummy = elm_bg_add(win);
212 evas_object_size_hint_weight_set(dummy, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
213 elm_box_pack_end(box, dummy);
214 evas_object_show(dummy);
216 /* add an object that we are going to play with */
217 /* this object isn't packed inside the box because we don't want it to have
218 * its size, position, aspect or anything else controled by the container */
219 obj = elm_button_add(win);
220 elm_object_text_set(obj, "Transformed object!");
221 icon = elm_icon_add(win);
222 snprintf(buf, sizeof(buf), "%s/images/icon_07.png", PACKAGE_DATA_DIR);
223 elm_icon_file_set(icon, buf, NULL);
224 elm_object_part_content_set(obj, "icon", icon);
225 evas_object_move(obj, 160, 60);
226 evas_object_resize(obj, 250, 100);
227 evas_object_show(obj);
230 /* a callback to know if clicks are being received */
231 evas_object_smart_callback_add(obj, "clicked", _object_clicked, NULL);
233 /* button to start our transition */
234 btn = elm_button_add(win);
235 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
236 elm_object_text_set(btn, "Transit!");
237 elm_box_pack_end(box, btn);
238 evas_object_show(btn);
239 evas_object_smart_callback_add(btn, "clicked", _transit_start, &context);
241 /* horizontal box to help visual organization */
242 hbox = elm_box_add(win);
243 elm_box_horizontal_set(hbox, EINA_TRUE);
244 evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
245 evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, 0.0);
246 elm_box_pack_end(box, hbox);
247 evas_object_show(hbox);
249 /* horizontal box that will hold the many transition checkboxes */
250 vbox = elm_box_add(win);
251 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
252 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, 0.0);
254 /* create the respective checkboxes based on our helper structure and
256 for (i = 0; _transitions[i].label; i++)
257 _checkbox_transition_add(vbox, _transitions[i].label,
258 &_transitions[i].checked);
260 elm_box_pack_end(hbox, vbox);
261 evas_object_show(vbox);
263 /* vertical box that will hold the many transition option checkboxes */
264 vbox2 = elm_box_add(win);
265 evas_object_size_hint_weight_set(vbox2, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
266 evas_object_size_hint_align_set(vbox2, EVAS_HINT_FILL, 0.0);
267 elm_box_pack_end(hbox, vbox2);
268 evas_object_show(vbox2);
270 /* the rest of this code adds widgets to control some of the behavior of
272 cbox = elm_check_add(win);
273 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
274 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
275 elm_object_text_set(cbox, "Events enabled");
276 elm_check_state_pointer_set(cbox, &context.events_enabled);
277 elm_box_pack_end(vbox2, cbox);
278 evas_object_show(cbox);
280 cbox = elm_check_add(win);
281 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
282 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
283 elm_object_text_set(cbox, "Auto reverse");
284 elm_check_state_pointer_set(cbox, &context.auto_reverse);
285 elm_box_pack_end(vbox2, cbox);
286 evas_object_show(cbox);
288 cbox = elm_check_add(win);
289 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
290 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
291 elm_object_text_set(cbox, "Keep final state");
292 elm_check_state_pointer_set(cbox, &context.final_state_keep);
293 elm_box_pack_end(vbox2, cbox);
294 evas_object_show(cbox);
296 spinner = elm_spinner_add(win);
297 elm_object_style_set(spinner, "vertical");
298 elm_spinner_min_max_set(spinner, 0, 4);
299 elm_spinner_label_format_set(spinner, "%.0f");
300 elm_spinner_editable_set(spinner, EINA_FALSE);
301 evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
302 evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
303 evas_object_smart_callback_add(spinner, "changed", _cb_repeat_changed, &context.repeat_times);
304 elm_box_pack_end(vbox2, spinner);
305 evas_object_show(spinner);
307 spinner = elm_spinner_add(win);
308 elm_object_style_set(spinner, "vertical");
309 elm_spinner_min_max_set(spinner, 1, 4);
310 elm_spinner_label_format_set(spinner, "%.0f");
311 elm_spinner_editable_set(spinner, EINA_FALSE);
312 elm_spinner_special_value_add(spinner, 1, "linear");
313 elm_spinner_special_value_add(spinner, 2, "sinusoidal");
314 elm_spinner_special_value_add(spinner, 3, "decelerate");
315 elm_spinner_special_value_add(spinner, 4, "accelerate");
316 evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
317 evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
318 evas_object_size_hint_min_set(spinner, 200, 30);
319 evas_object_smart_callback_add(spinner, "changed", _cb_tween_changed, &context.tween_mode);
320 elm_box_pack_end(vbox2, spinner);
321 evas_object_show(spinner);
323 evas_object_show(win);