Initialize Tizen 2.3
[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` -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 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    elm_app_info_set(elm_main, "elementary", "images/icon_07.png");
97    /* add a window */
98    win = elm_win_add(NULL, "transit", ELM_WIN_BASIC);
99    elm_win_title_set(win, "Transit Example");
100    evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
101    elm_win_autodel_set(win, EINA_TRUE);
102
103    /* add a scalable white background to this window */
104    bg = elm_bg_add(win);
105    elm_bg_color_set(bg, 255, 255, 255);
106    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107    elm_win_resize_object_add(win, bg);
108    evas_object_show(bg);
109
110    box = elm_box_add(win);
111    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
112    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
113    elm_win_resize_object_add(win, box);
114    evas_object_show(box);
115
116    dummy = elm_bg_add(win);
117    evas_object_size_hint_weight_set(dummy, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
118    elm_box_pack_end(box, dummy);
119    evas_object_show(dummy);
120
121    /* add an object that we are going to play with */
122    obj = elm_button_add(win);
123    elm_object_text_set(obj, "Transformed object!");
124    icon = elm_icon_add(win);
125    snprintf(buf, sizeof(buf), "%s/images/icon_07.png", elm_app_data_dir_get());
126    elm_image_file_set(icon, buf, NULL);
127    elm_object_part_content_set(obj, "icon", icon);
128    evas_object_move(obj, 160, 60);
129    evas_object_resize(obj, 250, 100);
130    evas_object_show(obj);
131
132    objs = eina_list_append(objs, obj);
133
134    /* add another object that we are going to play with */
135    obj = elm_button_add(win);
136    elm_object_text_set(obj, "Another object!");
137    icon = elm_icon_add(win);
138    snprintf(buf, sizeof(buf), "%s/images/icon_08.png", elm_app_data_dir_get());
139    elm_image_file_set(icon, buf, NULL);
140    elm_object_part_content_set(obj, "icon", icon);
141    evas_object_move(obj, 160, 60);
142    evas_object_resize(obj, 250, 100);
143
144    objs = eina_list_append(objs, obj);
145
146    btn = elm_button_add(win);
147    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148    elm_object_text_set(btn, "Transit!");
149    elm_box_pack_end(box, btn);
150    evas_object_show(btn);
151
152    evas_object_smart_callback_add(btn, "clicked", _transit_start, objs);
153
154    vbox = elm_box_add(win);
155    evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
156    evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, 0.0);
157
158    for (i = 0; _transitions[i].label; i++)
159      _checkbox_transition_add(vbox, _transitions[i].label, &_transitions[i].checked);
160
161    elm_box_pack_end(box, vbox);
162    evas_object_show(vbox);
163
164    evas_object_show(win);
165
166    elm_run();
167    elm_shutdown();
168
169    return 0;
170 }
171 ELM_MAIN()