2 //gcc -o transit_example_03 transit_example_03.c `pkg-config --cflags --libs elementary` -DDATA_DIR="\"<directory>\""
3 //where directory is the a path where images/icon_07.png can be found.
5 #include <Elementary.h>
7 # define DATA_DIR "/usr/share/elementary"
10 /* structure to hold context for many callbacks */
12 Eina_Bool events_enabled;
13 Eina_Bool auto_reverse;
14 Eina_Bool final_state_keep;
16 Elm_Transit_Tween_Mode tween_mode;
21 _transit_translation(Elm_Transit *trans)
23 /* considering the original position (x0, y0), moves the object from
24 * (x0 - 20, y0 - 50) to (x0 + 70, y0 + 150) */
25 elm_transit_effect_translation_add(trans, -20, -50, 70, 150);
29 _transit_color(Elm_Transit *trans)
31 /* changes the object color from 100, 255, 100, 255 to
33 elm_transit_effect_color_add(trans, 100, 255, 100, 255, 200, 50, 200, 50);
37 _transit_rotation(Elm_Transit *trans)
39 /* rotates the object from its original angle to 135 degrees to the right */
40 elm_transit_effect_rotation_add(trans, 0.0, 135.0);
44 _transit_wipe(Elm_Transit *trans)
46 /* hide the object clipping it from the left to the right */
47 elm_transit_effect_wipe_add(trans,
48 ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
49 ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT);
53 _transit_zoom(Elm_Transit *trans)
55 /* zoom the object from its original size to 2x */
56 elm_transit_effect_zoom_add(trans, 1.0, 2.0);
60 _transit_resizing(Elm_Transit *trans)
62 /* resize the object from 250x100 to 400x160 */
63 elm_transit_effect_resizing_add(trans, 250, 100, 400, 160);
67 /* helper structure that will hold the transit checkboxes string, callbacks
68 * and checked statuses */
71 void (*transition_add_cb)(Elm_Transit *);
74 { "Translation", _transit_translation, EINA_FALSE },
75 { "Color", _transit_color, EINA_FALSE },
76 { "Rotation", _transit_rotation, EINA_FALSE },
77 { "Wipe", _transit_wipe, EINA_FALSE },
78 { "Zoom", _transit_zoom, EINA_FALSE },
79 { "Resizing", _transit_resizing, EINA_FALSE },
80 { NULL, NULL, EINA_FALSE }
84 on_done(void *data, Evas_Object *obj, void *event_info)
86 /* quit the mainloop (elm_run) */
90 /* add a checkbox to the box with the given label, and uses the checked
91 * pointer as state_pointer to this checkbox */
93 _checkbox_transition_add(Evas_Object *box, const char *label, Eina_Bool *checked)
95 Evas_Object *check = elm_check_add(elm_object_parent_widget_get(box));
96 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
97 evas_object_size_hint_align_set(check, 0.0, 0.0);
98 elm_object_text_set(check, label);
99 elm_check_state_pointer_set(check, checked);
100 elm_box_pack_end(box, check);
101 evas_object_show(check);
105 _transit_start(void *data, Evas_Object *o, void *event_info)
107 Elm_Transit *trans = NULL;
109 struct Context *ctxt = data;
110 Evas_Object *obj = ctxt->obj; // the object on which the transition will be
113 // FIXME: Should check if there's another transit going before starting a new
116 /* initialization: create the transition and add the object to it */
117 trans = elm_transit_add();
118 elm_transit_object_add(trans, obj);
120 /* from our helper structure and array, check if the specified transition is
121 * checked and use its callback to add this transition to trans */
122 for (i = 0; _transitions[i].label; i++)
124 if (_transitions[i].checked)
125 _transitions[i].transition_add_cb(trans);
128 /* get the various options for this transition from the context structure */
129 elm_transit_event_enabled_set(trans, ctxt->events_enabled);
130 elm_transit_auto_reverse_set(trans, ctxt->auto_reverse);
131 elm_transit_objects_final_state_keep_set(trans, ctxt->final_state_keep);
132 elm_transit_tween_mode_set(trans, ctxt->tween_mode);
133 elm_transit_repeat_times_set(trans, ctxt->repeat_times);
135 /* set the transition time to 2 seconds and start it */
136 elm_transit_duration_set(trans, 2.0);
137 elm_transit_go(trans);
140 /* callback useful just to know whether we can receive events from the
143 _object_clicked(void *data, Evas_Object *o, void *event_info)
145 printf("object clicked!\n");
148 /* update our context with the given value for repeat count */
150 _cb_repeat_changed(void *data, Evas_Object *obj, void *event)
152 int *repeat_cnt = data;
154 *repeat_cnt = elm_spinner_value_get(obj);
157 /* update our context with the given tween mode for the transition */
159 _cb_tween_changed(void *data, Evas_Object *obj, void *event)
161 Elm_Transit_Tween_Mode *mode = data;
164 val = elm_spinner_value_get(obj);
166 *mode = ELM_TRANSIT_TWEEN_MODE_LINEAR;
168 *mode = ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL;
170 *mode = ELM_TRANSIT_TWEEN_MODE_DECELERATE;
172 *mode = ELM_TRANSIT_TWEEN_MODE_ACCELERATE;
176 elm_main(int argc, char **argv)
178 Evas_Object *win, *bg, *obj, *icon, *box, *vbox, *vbox2, *hbox, *btn;
179 Evas_Object *cbox, *dummy, *spinner;
182 struct Context context;
184 /* initialize our context */
185 context.events_enabled = EINA_FALSE;
186 context.auto_reverse = EINA_FALSE;
187 context.final_state_keep = EINA_FALSE;
188 context.repeat_times = 0;
189 context.tween_mode = ELM_TRANSIT_TWEEN_MODE_LINEAR;
192 win = elm_win_add(NULL, "transit", ELM_WIN_BASIC);
193 elm_win_title_set(win, "Transit Example");
194 evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
195 elm_win_autodel_set(win, EINA_TRUE);
197 /* add a scalable white background to this window */
198 bg = elm_bg_add(win);
199 elm_bg_color_set(bg, 255, 255, 255);
200 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
201 evas_object_size_hint_min_set(bg, 640, 640);
202 evas_object_size_hint_max_set(bg, 640, 640);
203 elm_win_resize_object_add(win, bg);
204 evas_object_show(bg);
206 /* add a vertical box that will hold everything */
207 box = elm_box_add(win);
208 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
209 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
210 elm_win_resize_object_add(win, box);
211 evas_object_show(box);
213 /* a dummy background to create some space for the animation */
214 dummy = elm_bg_add(win);
215 evas_object_size_hint_weight_set(dummy, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
216 elm_box_pack_end(box, dummy);
217 evas_object_show(dummy);
219 /* add an object that we are going to play with */
220 /* this object isn't packed inside the box because we don't want it to have
221 * its size, position, aspect or anything else controled by the container */
222 obj = elm_button_add(win);
223 elm_object_text_set(obj, "Transformed object!");
224 icon = elm_icon_add(win);
225 snprintf(buf, sizeof(buf), "%s/images/icon_07.png", DATA_DIR);
226 elm_icon_file_set(icon, buf, NULL);
227 elm_object_part_content_set(obj, "icon", icon);
228 evas_object_move(obj, 160, 60);
229 evas_object_resize(obj, 250, 100);
230 evas_object_show(obj);
233 /* a callback to know if clicks are being received */
234 evas_object_smart_callback_add(obj, "clicked", _object_clicked, NULL);
236 /* button to start our transition */
237 btn = elm_button_add(win);
238 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
239 elm_object_text_set(btn, "Transit!");
240 elm_box_pack_end(box, btn);
241 evas_object_show(btn);
242 evas_object_smart_callback_add(btn, "clicked", _transit_start, &context);
244 /* horizontal box to help visual organization */
245 hbox = elm_box_add(win);
246 elm_box_horizontal_set(hbox, EINA_TRUE);
247 evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
248 evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, 0.0);
249 elm_box_pack_end(box, hbox);
250 evas_object_show(hbox);
252 /* horizontal box that will hold the many transition checkboxes */
253 vbox = elm_box_add(win);
254 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
255 evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, 0.0);
257 /* create the respective checkboxes based on our helper structure and
259 for (i = 0; _transitions[i].label; i++)
260 _checkbox_transition_add(vbox, _transitions[i].label,
261 &_transitions[i].checked);
263 elm_box_pack_end(hbox, vbox);
264 evas_object_show(vbox);
266 /* vertical box that will hold the many transition option checkboxes */
267 vbox2 = elm_box_add(win);
268 evas_object_size_hint_weight_set(vbox2, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
269 evas_object_size_hint_align_set(vbox2, EVAS_HINT_FILL, 0.0);
270 elm_box_pack_end(hbox, vbox2);
271 evas_object_show(vbox2);
273 /* the rest of this code adds widgets to control some of the behavior of
275 cbox = elm_check_add(win);
276 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
277 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
278 elm_object_text_set(cbox, "Events enabled");
279 elm_check_state_pointer_set(cbox, &context.events_enabled);
280 elm_box_pack_end(vbox2, cbox);
281 evas_object_show(cbox);
283 cbox = elm_check_add(win);
284 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
285 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
286 elm_object_text_set(cbox, "Auto reverse");
287 elm_check_state_pointer_set(cbox, &context.auto_reverse);
288 elm_box_pack_end(vbox2, cbox);
289 evas_object_show(cbox);
291 cbox = elm_check_add(win);
292 evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
293 evas_object_size_hint_align_set(cbox, 0.0, 0.0);
294 elm_object_text_set(cbox, "Keep final state");
295 elm_check_state_pointer_set(cbox, &context.final_state_keep);
296 elm_box_pack_end(vbox2, cbox);
297 evas_object_show(cbox);
299 spinner = elm_spinner_add(win);
300 elm_object_style_set(spinner, "vertical");
301 elm_spinner_min_max_set(spinner, 0, 4);
302 elm_spinner_label_format_set(spinner, "%.0f");
303 elm_spinner_editable_set(spinner, EINA_FALSE);
304 evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
305 evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
306 evas_object_smart_callback_add(spinner, "changed", _cb_repeat_changed, &context.repeat_times);
307 elm_box_pack_end(vbox2, spinner);
308 evas_object_show(spinner);
310 spinner = elm_spinner_add(win);
311 elm_object_style_set(spinner, "vertical");
312 elm_spinner_min_max_set(spinner, 1, 4);
313 elm_spinner_label_format_set(spinner, "%.0f");
314 elm_spinner_editable_set(spinner, EINA_FALSE);
315 elm_spinner_special_value_add(spinner, 1, "linear");
316 elm_spinner_special_value_add(spinner, 2, "sinusoidal");
317 elm_spinner_special_value_add(spinner, 3, "decelerate");
318 elm_spinner_special_value_add(spinner, 4, "accelerate");
319 evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
320 evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
321 evas_object_size_hint_min_set(spinner, 200, 30);
322 evas_object_smart_callback_add(spinner, "changed", _cb_tween_changed, &context.tween_mode);
323 elm_box_pack_end(vbox2, spinner);
324 evas_object_show(spinner);
326 evas_object_show(win);