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