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