The elm_toolbar_iteams_count have to return only the number of manually added items.
[framework/uifw/elementary.git] / src / examples / transit_example_03.c
1 //Compile with:
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.
4
5 #include <Elementary.h>
6
7 /* structure to hold context for many callbacks */
8 struct Context {
9      Eina_Bool events_enabled;
10      Eina_Bool auto_reverse;
11      Eina_Bool final_state_keep;
12      int repeat_times;
13      Elm_Transit_Tween_Mode tween_mode;
14      Evas_Object *obj;
15 };
16
17 static void
18 _transit_translation(Elm_Transit *trans)
19 {
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);
23 }
24
25 static void
26 _transit_color(Elm_Transit *trans)
27 {
28    /* changes the object color from 100, 255, 100, 255 to
29     * 200, 50, 200, 50 */
30    elm_transit_effect_color_add(trans, 100, 255, 100, 255, 200, 50, 200, 50);
31 }
32
33 static void
34 _transit_rotation(Elm_Transit *trans)
35 {
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);
38 }
39
40 static void
41 _transit_wipe(Elm_Transit *trans)
42 {
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);
47 }
48
49 static void
50 _transit_zoom(Elm_Transit *trans)
51 {
52    /* zoom the object from its original size to 2x */
53    elm_transit_effect_zoom_add(trans, 1.0, 2.0);
54 }
55
56 static void
57 _transit_resizing(Elm_Transit *trans)
58 {
59    /* resize the object from 250x100 to 400x160 */
60    elm_transit_effect_resizing_add(trans, 250, 100, 400, 160);
61 }
62
63
64 /* helper structure that will hold the transit checkboxes string, callbacks
65  * and checked statuses */
66 static struct {
67      const char *label;
68      void (*transition_add_cb)(Elm_Transit *);
69      Eina_Bool checked;
70 } _transitions[] = {
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 }
78 };
79
80 static void
81 on_done(void *data, Evas_Object *obj, void *event_info)
82 {
83    /* quit the mainloop (elm_run) */
84    elm_exit();
85 }
86
87 /* add a checkbox to the box with the given label, and uses the checked
88  * pointer as state_pointer to this checkbox */
89 static void
90 _checkbox_transition_add(Evas_Object *box, const char *label, Eina_Bool *checked)
91 {
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);
99 }
100
101 static void
102 _transit_start(void *data, Evas_Object *o, void *event_info)
103 {
104    Elm_Transit *trans = NULL;
105    int i;
106    struct Context *ctxt = data;
107    Evas_Object *obj = ctxt->obj; // the object on which the transition will be
108                                  // applied
109
110    // FIXME: Should check if there's another transit going before starting a new
111    // one
112
113    /* initialization: create the transition and add the object to it */
114    trans = elm_transit_add();
115    elm_transit_object_add(trans, obj);
116
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++)
120      {
121         if (_transitions[i].checked)
122           _transitions[i].transition_add_cb(trans);
123      }
124
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);
131
132    /* set the transition time to 2 seconds and start it */
133    elm_transit_duration_set(trans, 2.0);
134    elm_transit_go(trans);
135 }
136
137 /* callback useful just to know whether we can receive events from the
138  * object or not */
139 static void
140 _object_clicked(void *data, Evas_Object *o, void *event_info)
141 {
142    printf("object clicked!\n");
143 }
144
145 /* update our context with the given value for repeat count */
146 static void
147 _cb_repeat_changed(void *data, Evas_Object *obj, void *event)
148 {
149    int *repeat_cnt = data;
150
151    *repeat_cnt = elm_spinner_value_get(obj);
152 }
153
154 /* update our context with the given tween mode for the transition */
155 static void
156 _cb_tween_changed(void *data, Evas_Object *obj, void *event)
157 {
158    Elm_Transit_Tween_Mode *mode = data;
159    double val = 0.0;
160
161    val = elm_spinner_value_get(obj);
162    if (val == 1.0)
163      *mode = ELM_TRANSIT_TWEEN_MODE_LINEAR;
164    else if (val == 2.0)
165      *mode = ELM_TRANSIT_TWEEN_MODE_SINUSOIDAL;
166    else if (val == 3.0)
167      *mode = ELM_TRANSIT_TWEEN_MODE_DECELERATE;
168    else if (val == 4.0)
169      *mode = ELM_TRANSIT_TWEEN_MODE_ACCELERATE;
170 }
171
172 EAPI_MAIN int
173 elm_main(int argc, char **argv)
174 {
175    Evas_Object *win, *bg, *obj, *icon, *box, *vbox, *vbox2, *hbox, *btn;
176    Evas_Object *cbox, *dummy, *spinner;
177    char buf[PATH_MAX];
178    int i;
179    struct Context context;
180
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;
187
188    elm_app_info_set(elm_main, "elementary", "images/icon_07.png");
189
190    /* add a window */
191    win = elm_win_add(NULL, "transit", ELM_WIN_BASIC);
192    elm_win_title_set(win, "Transit Example");
193    evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
194    elm_win_autodel_set(win, EINA_TRUE);
195
196    /* add a scalable white background to this window */
197    bg = elm_bg_add(win);
198    elm_bg_color_set(bg, 255, 255, 255);
199    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
200    evas_object_size_hint_min_set(bg, 640, 640);
201    evas_object_size_hint_max_set(bg, 640, 640);
202    elm_win_resize_object_add(win, bg);
203    evas_object_show(bg);
204
205    /* add a vertical box that will hold everything */
206    box = elm_box_add(win);
207    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
208    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
209    elm_win_resize_object_add(win, box);
210    evas_object_show(box);
211
212    /* a dummy background to create some space for the animation */
213    dummy = elm_bg_add(win);
214    evas_object_size_hint_weight_set(dummy, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215    elm_box_pack_end(box, dummy);
216    evas_object_show(dummy);
217
218    /* add an object that we are going to play with */
219    /* this object isn't packed inside the box because we don't want it to have
220     * its size, position, aspect or anything else controled by the container */
221    obj = elm_button_add(win);
222    elm_object_text_set(obj, "Transformed object!");
223    icon = elm_icon_add(win);
224    snprintf(buf, sizeof(buf), "%s/images/icon_07.png", elm_app_data_dir_get());
225    elm_icon_file_set(icon, buf, NULL);
226    elm_object_part_content_set(obj, "icon", icon);
227    evas_object_move(obj, 160, 60);
228    evas_object_resize(obj, 250, 100);
229    evas_object_show(obj);
230    context.obj = obj;
231
232    /* a callback to know if clicks are being received */
233    evas_object_smart_callback_add(obj, "clicked", _object_clicked, NULL);
234
235    /* button to start our transition */
236    btn = elm_button_add(win);
237    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
238    elm_object_text_set(btn, "Transit!");
239    elm_box_pack_end(box, btn);
240    evas_object_show(btn);
241    evas_object_smart_callback_add(btn, "clicked", _transit_start, &context);
242
243    /* horizontal box to help visual organization */
244    hbox = elm_box_add(win);
245    elm_box_horizontal_set(hbox, EINA_TRUE);
246    evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
247    evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, 0.0);
248    elm_box_pack_end(box, hbox);
249    evas_object_show(hbox);
250
251    /* horizontal box that will hold the many transition checkboxes */
252    vbox = elm_box_add(win);
253    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
254    evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, 0.0);
255
256    /* create the respective checkboxes based on our helper structure and
257     * array */
258    for (i = 0; _transitions[i].label; i++)
259      _checkbox_transition_add(vbox, _transitions[i].label,
260                               &_transitions[i].checked);
261
262    elm_box_pack_end(hbox, vbox);
263    evas_object_show(vbox);
264
265    /* vertical box that will hold the many transition option checkboxes */
266    vbox2 = elm_box_add(win);
267    evas_object_size_hint_weight_set(vbox2, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
268    evas_object_size_hint_align_set(vbox2, EVAS_HINT_FILL, 0.0);
269    elm_box_pack_end(hbox, vbox2);
270    evas_object_show(vbox2);
271
272    /* the rest of this code adds widgets to control some of the behavior of
273     * the transitions */
274    cbox = elm_check_add(win);
275    evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
276    evas_object_size_hint_align_set(cbox, 0.0, 0.0);
277    elm_object_text_set(cbox, "Events enabled");
278    elm_check_state_pointer_set(cbox, &context.events_enabled);
279    elm_box_pack_end(vbox2, cbox);
280    evas_object_show(cbox);
281
282    cbox = elm_check_add(win);
283    evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
284    evas_object_size_hint_align_set(cbox, 0.0, 0.0);
285    elm_object_text_set(cbox, "Auto reverse");
286    elm_check_state_pointer_set(cbox, &context.auto_reverse);
287    elm_box_pack_end(vbox2, cbox);
288    evas_object_show(cbox);
289
290    cbox = elm_check_add(win);
291    evas_object_size_hint_weight_set(cbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
292    evas_object_size_hint_align_set(cbox, 0.0, 0.0);
293    elm_object_text_set(cbox, "Keep final state");
294    elm_check_state_pointer_set(cbox, &context.final_state_keep);
295    elm_box_pack_end(vbox2, cbox);
296    evas_object_show(cbox);
297
298    spinner = elm_spinner_add(win);
299    elm_object_style_set(spinner, "vertical");
300    elm_spinner_min_max_set(spinner, 0, 4);
301    elm_spinner_label_format_set(spinner, "%.0f");
302    elm_spinner_editable_set(spinner, EINA_FALSE);
303    evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
304    evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
305    evas_object_smart_callback_add(spinner, "changed", _cb_repeat_changed, &context.repeat_times);
306    elm_box_pack_end(vbox2, spinner);
307    evas_object_show(spinner);
308
309    spinner = elm_spinner_add(win);
310    elm_object_style_set(spinner, "vertical");
311    elm_spinner_min_max_set(spinner, 1, 4);
312    elm_spinner_label_format_set(spinner, "%.0f");
313    elm_spinner_editable_set(spinner, EINA_FALSE);
314    elm_spinner_special_value_add(spinner, 1, "linear");
315    elm_spinner_special_value_add(spinner, 2, "sinusoidal");
316    elm_spinner_special_value_add(spinner, 3, "decelerate");
317    elm_spinner_special_value_add(spinner, 4, "accelerate");
318    evas_object_size_hint_weight_set(spinner, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
319    evas_object_size_hint_align_set(spinner, 0.0, EVAS_HINT_FILL);
320    evas_object_size_hint_min_set(spinner, 200, 30);
321    evas_object_smart_callback_add(spinner, "changed", _cb_tween_changed, &context.tween_mode);
322    elm_box_pack_end(vbox2, spinner);
323    evas_object_show(spinner);
324
325    evas_object_show(win);
326
327    elm_run();
328    elm_shutdown();
329
330    return 0;
331 }
332 ELM_MAIN()