faf4fe5a1c5020d271af77fe99096efb693c9fd0
[framework/uifw/elementary.git] / src / examples / transit_example_04.c
1 //Compile with:
2 //gcc -g -DPACKAGE_DATA_DIR="\"<directory>\"" `pkg-config --cflags --libs elementary` transit_example_04.c -o transit_example_04
3 // where directory is the a path where images/plant_01.jpg can be found.
4
5
6 #include <Elementary.h>
7 #ifdef HAVE_CONFIG_H
8 # include "elementary_config.h"
9 #else
10 # define __UNUSED__
11 #endif
12
13 static void
14 _transit_flip(Elm_Transit *trans)
15 {
16    elm_transit_effect_flip_add(trans, ELM_TRANSIT_EFFECT_FLIP_AXIS_X, EINA_TRUE);
17 }
18
19 static void
20 _transit_blend(Elm_Transit *trans)
21 {
22    elm_transit_effect_blend_add(trans);
23 }
24
25 static void
26 _transit_fade(Elm_Transit *trans)
27 {
28    elm_transit_effect_fade_add(trans);
29 }
30
31 static void
32 _transit_resizable_flip(Elm_Transit *trans)
33 {
34    elm_transit_effect_resizable_flip_add(
35       trans, ELM_TRANSIT_EFFECT_FLIP_AXIS_Y, EINA_TRUE);
36 }
37
38 static struct {
39      const char *label;
40      void (*transition_add_cb)(Elm_Transit *);
41      Eina_Bool checked;
42 } _transitions[] = {
43        { "Flip", _transit_flip, EINA_FALSE },
44        { "Blend", _transit_blend, EINA_FALSE },
45        { "Fade", _transit_fade, EINA_FALSE },
46        { "Resizable Flip", _transit_resizable_flip, EINA_FALSE },
47        { NULL, NULL, EINA_FALSE }
48 };
49
50 static void
51 on_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
52 {
53    /* quit the mainloop (elm_run) */
54    elm_exit();
55 }
56
57 static void
58 _checkbox_transition_add(Evas_Object *box, const char *label, Eina_Bool *checked)
59 {
60    Evas_Object *check = elm_check_add(elm_object_parent_widget_get(box));
61    evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
62    evas_object_size_hint_align_set(check, 0.0, 0.0);
63    elm_object_text_set(check, label);
64    elm_check_state_pointer_set(check, checked);
65    elm_box_pack_end(box, check);
66    evas_object_show(check);
67 }
68
69 static void
70 _transit_start(void *data, Evas_Object *o, void *event_info)
71 {
72    Elm_Transit *trans = NULL;
73    Eina_List *objs = data, *l;
74    Evas_Object *obj;
75    int i;
76
77    trans = elm_transit_add();
78    EINA_LIST_FOREACH(objs, l, obj)
79       elm_transit_object_add(trans, obj);
80
81    // FIXME: Should check if there's another transit going before starting a new
82    // one
83
84    for (i = 0; _transitions[i].label; i++)
85      {
86         if (_transitions[i].checked)
87           _transitions[i].transition_add_cb(trans);
88      }
89
90    elm_transit_duration_set(trans, 2.0);
91    elm_transit_go(trans);
92 }
93
94 int
95 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
96 {
97    Evas_Object *win, *bg, *obj, *icon, *box, *vbox, *btn, *fr, *dummy;
98    Elm_Transit *trans;
99    Eina_List *objs = NULL;
100    char buf[PATH_MAX];
101    int i;
102
103    /* add a window */
104    win = elm_win_add(NULL, "transit", ELM_WIN_BASIC);
105    elm_win_title_set(win, "Transit Example");
106    evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
107    elm_win_autodel_set(win, EINA_TRUE);
108
109    /* add a scalable white background to this window */
110    bg = elm_bg_add(win);
111    elm_bg_color_set(bg, 255, 255, 255);
112    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113    evas_object_size_hint_min_set(bg, 640, 640);
114    evas_object_size_hint_max_set(bg, 640, 640);
115    elm_win_resize_object_add(win, bg);
116    evas_object_show(bg);
117
118    box = elm_box_add(win);
119    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
120    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
121    elm_win_resize_object_add(win, box);
122    evas_object_show(box);
123
124    dummy = elm_bg_add(win);
125    evas_object_size_hint_weight_set(dummy, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
126    elm_box_pack_end(box, dummy);
127    evas_object_show(dummy);
128
129    /* add an object that we are going to play with */
130    obj = elm_button_add(win);
131    elm_object_text_set(obj, "Transformed object!");
132    icon = elm_icon_add(win);
133    snprintf(buf, sizeof(buf), "%s/images/icon_07.png", PACKAGE_DATA_DIR);
134    elm_icon_file_set(icon, buf, NULL);
135    elm_object_part_content_set(obj, "icon", icon);
136    evas_object_move(obj, 160, 60);
137    evas_object_resize(obj, 250, 100);
138    evas_object_show(obj);
139
140    objs = eina_list_append(objs, obj);
141
142    /* add another object that we are going to play with */
143    obj = elm_button_add(win);
144    elm_object_text_set(obj, "Another object!");
145    icon = elm_icon_add(win);
146    snprintf(buf, sizeof(buf), "%s/images/icon_08.png", PACKAGE_DATA_DIR);
147    elm_icon_file_set(icon, buf, NULL);
148    elm_object_part_content_set(obj, "icon", icon);
149    evas_object_move(obj, 160, 60);
150    evas_object_resize(obj, 250, 100);
151
152    objs = eina_list_append(objs, obj);
153
154    btn = elm_button_add(win);
155    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
156    elm_object_text_set(btn, "Transit!");
157    elm_box_pack_end(box, btn);
158    evas_object_show(btn);
159
160    evas_object_smart_callback_add(btn, "clicked", _transit_start, objs);
161
162    vbox = elm_box_add(win);
163    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
164    evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, 0.0);
165
166    for (i = 0; _transitions[i].label; i++)
167      _checkbox_transition_add(vbox, _transitions[i].label, &_transitions[i].checked);
168
169    elm_box_pack_end(box, vbox);
170    evas_object_show(vbox);
171
172    evas_object_show(win);
173
174    elm_run();
175
176    eina_list_free(objs);
177
178    return 0;
179 }
180
181 ELM_MAIN()