[Genlist] Fix genlist size problem
[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    elm_win_resize_object_add(win, bg);
201    evas_object_show(bg);
202
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);
209
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);
215
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", elm_app_data_dir_get());
223    elm_image_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);
228    context.obj = obj;
229
230    /* a callback to know if clicks are being received */
231    evas_object_smart_callback_add(obj, "clicked", _object_clicked, NULL);
232
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);
240
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);
248
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);
253
254    /* create the respective checkboxes based on our helper structure and
255     * array */
256    for (i = 0; _transitions[i].label; i++)
257      _checkbox_transition_add(vbox, _transitions[i].label,
258                               &_transitions[i].checked);
259
260    elm_box_pack_end(hbox, vbox);
261    evas_object_show(vbox);
262
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);
269
270    /* the rest of this code adds widgets to control some of the behavior of
271     * the transitions */
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);
279
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);
287
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);
295
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);
306
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_smart_callback_add(spinner, "changed", _cb_tween_changed, &context.tween_mode);
319    elm_box_pack_end(vbox2, spinner);
320    evas_object_show(spinner);
321
322    evas_object_show(win);
323
324    elm_run();
325    elm_shutdown();
326
327    return 0;
328 }
329 ELM_MAIN()