summaryrefslogtreecommitdiff
path: root/src/examples/elementary/slideshow_example.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-03-23 12:56:14 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-03-23 13:24:41 -0700
commitc2a1c49ab2042f559b28e840e54feb8494888e0e (patch)
treec6eb110b7c479499854eede9d0c3ab0a80c9a11a /src/examples/elementary/slideshow_example.c
parent9340855597e7e465435c69b6278650346688da14 (diff)
elementary: move all legacy files to their expected new location.
Diffstat (limited to 'src/examples/elementary/slideshow_example.c')
-rw-r--r--src/examples/elementary/slideshow_example.c276
1 files changed, 276 insertions, 0 deletions
diff --git a/src/examples/elementary/slideshow_example.c b/src/examples/elementary/slideshow_example.c
new file mode 100644
index 0000000000..5687b9e79a
--- /dev/null
+++ b/src/examples/elementary/slideshow_example.c
@@ -0,0 +1,276 @@
1/**
2 * Simple Elementary's <b>slide show widget</b> example, illustrating its
3 * usage and API.
4 *
5 * See stdout/stderr for output. Compile with:
6 *
7 * @verbatim
8 * gcc -o slideshow_example slideshow_example.c -g `pkg-config --cflags --libs elementary`
9 * @endverbatim
10 */
11
12#include <Elementary.h>
13
14#define IMG_NUM 8
15
16static Evas_Object *slideshow, *bt_start, *bt_stop;
17static Elm_Slideshow_Item_Class itc;
18
19static void
20_notify_show(void *data, Evas *e, Evas_Object *obj, void *event_info)
21{
22 evas_object_show(data);
23}
24
25/* jump to next item, cyclically */
26static void
27_next(void *data, Evas_Object *obj, void *event_info)
28{
29 elm_slideshow_next(data);
30}
31
32static void
33_previous(void *data, Evas_Object *obj, void *event_info)
34{
35 elm_slideshow_previous(data);
36}
37
38static void
39_first(void *data, Evas_Object *obj, void *event_info)
40{
41 elm_slideshow_item_show(data);
42}
43
44static void
45_last(void *data, Evas_Object *obj, void *event_info)
46{
47 elm_slideshow_item_show(data);
48}
49
50static void
51_mouse_in_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
52{
53 elm_notify_timeout_set(data, 0.0);
54 evas_object_show(data);
55}
56
57static void
58_mouse_out_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
59{
60 elm_notify_timeout_set(data, 3.0);
61}
62
63/* transition changed */
64static void
65_transition_select(void *data, Evas_Object *obj, void *event_info)
66{
67 elm_slideshow_transition_set(slideshow, data);
68 elm_object_text_set(obj, data);
69}
70
71static void
72_layout_select(void *data, Evas_Object *obj, void *event_info)
73{
74 elm_slideshow_layout_set(slideshow, data);
75 elm_object_text_set(obj, data);
76}
77
78/* start the show! */
79static void
80_start(void *data, Evas_Object *obj, void *event_info)
81{
82 elm_slideshow_timeout_set(slideshow, elm_spinner_value_get(data));
83
84 elm_object_disabled_set(bt_start, EINA_TRUE);
85 elm_object_disabled_set(bt_stop, EINA_FALSE);
86}
87
88static void
89_stop(void *data, Evas_Object *obj, void *event_info)
90{
91 elm_slideshow_timeout_set(slideshow, 0.0);
92 elm_object_disabled_set(bt_start, EINA_FALSE);
93 elm_object_disabled_set(bt_stop, EINA_TRUE);
94}
95
96/* slideshow transition time has changed */
97static void
98_spin(void *data, Evas_Object *obj, void *event_info)
99{
100 if (elm_slideshow_timeout_get(slideshow) > 0)
101 elm_slideshow_timeout_set(slideshow, elm_spinner_value_get(data));
102}
103
104/* get our images to make slideshow items */
105static Evas_Object *
106_get(void *data, Evas_Object *obj)
107{
108 Evas_Object *photo = elm_photo_add(obj);
109 elm_photo_file_set(photo, data);
110 elm_photo_fill_inside_set(photo, EINA_TRUE);
111 elm_object_style_set(photo, "shadow");
112
113 return photo;
114}
115
116/* ordering alphabetically */
117static int
118_cmp_func(const void *data1, const void *data2)
119{
120 const char *img_path1, *img_path2;
121
122 const Elm_Object_Item *slide_it1 = data1;
123 const Elm_Object_Item *slide_it2 = data2;
124
125 img_path1 = elm_object_item_data_get(slide_it1);
126 img_path2 = elm_object_item_data_get(slide_it2);
127
128 return strcasecmp(img_path1, img_path2);
129}
130
131EAPI_MAIN int
132elm_main(int argc, char **argv)
133{
134 Evas_Object *win, *notify, *bx, *bt, *hv, *spin;
135 Elm_Object_Item *slide_first = NULL, *slide_last = NULL, *slide_it = NULL;
136 const char *transition, *layout;
137 const Eina_List *l, *list;
138 const char *data_dir;
139 char img[IMG_NUM][PATH_MAX];
140 char *img_files[] =
141 {
142 "logo.png", "plant_01.jpg", "rock_01.jpg", "rock_02.jpg", "sky_01.jpg",
143 "wood_01.jpg", "mystrale.jpg", "mystrale_2.jpg"
144 };
145 int i = 0;
146
147 elm_app_info_set(elm_main, "elementary", "images");
148
149 data_dir = elm_app_data_dir_get();
150 for (i = 0; i < IMG_NUM; i++)
151 snprintf(img[i], PATH_MAX, "%s/images/%s", data_dir, img_files[i]);
152
153 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
154
155 win = elm_win_util_standard_add("slideshow", "Slideshow example");
156 elm_win_autodel_set(win, EINA_TRUE);
157
158 slideshow = elm_slideshow_add(win);
159 elm_slideshow_loop_set(slideshow, EINA_TRUE);
160 evas_object_size_hint_weight_set(slideshow,
161 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
162 elm_win_resize_object_add(win, slideshow);
163 evas_object_show(slideshow);
164
165 itc.func.get = _get;
166 itc.func.del = NULL;
167
168 for (i = 0; i < IMG_NUM; i++)
169 {
170 slide_it = elm_slideshow_item_sorted_insert(slideshow, &itc, img[i],
171 _cmp_func);
172 if (!slide_first) slide_first = slide_it;
173 }
174 slide_last = slide_it;
175
176 list = elm_slideshow_items_get(slideshow);
177 fprintf(stdout, "List of items in the slideshow:\n");
178 EINA_LIST_FOREACH(list, l, slide_it)
179 fprintf(stdout, "\t%s\n",
180 (const char *)elm_object_item_data_get(slide_it));
181
182 notify = elm_notify_add(win);
183 elm_notify_align_set(notify, 0.5, 1.0);
184 evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
185 elm_notify_timeout_set(notify, 3.0);
186 evas_object_show(notify);
187
188 bx = elm_box_add(win);
189 elm_box_horizontal_set(bx, EINA_TRUE);
190 elm_object_content_set(notify, bx);
191 evas_object_show(bx);
192
193 evas_object_event_callback_add(bx, EVAS_CALLBACK_MOUSE_IN,
194 _mouse_in_cb, notify);
195 evas_object_event_callback_add(bx, EVAS_CALLBACK_MOUSE_OUT,
196 _mouse_out_cb, notify);
197
198 bt = elm_button_add(win);
199 elm_object_text_set(bt, "First");
200 evas_object_smart_callback_add(bt, "clicked", _first, slide_first);
201 elm_box_pack_end(bx, bt);
202 evas_object_show(bt);
203
204 bt = elm_button_add(win);
205 elm_object_text_set(bt, "Previous");
206 evas_object_smart_callback_add(bt, "clicked", _previous, slideshow);
207 elm_box_pack_end(bx, bt);
208 evas_object_show(bt);
209
210 bt = elm_button_add(win);
211 elm_object_text_set(bt, "Next");
212 evas_object_smart_callback_add(bt, "clicked", _next, slideshow);
213 elm_box_pack_end(bx, bt);
214 evas_object_show(bt);
215
216 bt = elm_button_add(win);
217 elm_object_text_set(bt, "Last");
218 evas_object_smart_callback_add(bt, "clicked", _last, slide_last);
219 elm_box_pack_end(bx, bt);
220 evas_object_show(bt);
221
222 hv = elm_hoversel_add(win);
223 elm_box_pack_end(bx, hv);
224 elm_hoversel_hover_parent_set(hv, win);
225 EINA_LIST_FOREACH(elm_slideshow_transitions_get(slideshow), l, transition)
226 elm_hoversel_item_add(hv, transition, NULL, 0, _transition_select,
227 transition);
228 elm_object_text_set(hv, eina_list_data_get(
229 elm_slideshow_transitions_get(slideshow)));
230 evas_object_show(hv);
231
232 hv = elm_hoversel_add(win);
233 elm_box_pack_end(bx, hv);
234 elm_hoversel_hover_parent_set(hv, win);
235 EINA_LIST_FOREACH(elm_slideshow_layouts_get(slideshow), l, layout)
236 elm_hoversel_item_add(hv, layout, NULL, 0, _layout_select, layout);
237 elm_object_text_set(hv, elm_slideshow_layout_get(slideshow));
238 evas_object_show(hv);
239
240 spin = elm_spinner_add(win);
241 elm_spinner_label_format_set(spin, "%2.0f s");
242 evas_object_smart_callback_add(spin, "changed", _spin, spin);
243 elm_spinner_step_set(spin, 1);
244 elm_spinner_min_max_set(spin, 1, 30);
245 elm_spinner_value_set(spin, 3);
246 elm_box_pack_end(bx, spin);
247 evas_object_show(spin);
248
249 bt = elm_button_add(win);
250 bt_start = bt;
251 elm_object_text_set(bt, "Start");
252 evas_object_smart_callback_add(bt, "clicked", _start, spin);
253 elm_box_pack_end(bx, bt);
254 evas_object_show(bt);
255
256 bt = elm_button_add(win);
257 bt_stop = bt;
258 elm_object_text_set(bt, "Stop");
259 evas_object_smart_callback_add(bt, "clicked", _stop, spin);
260 elm_box_pack_end(bx, bt);
261 elm_object_disabled_set(bt, EINA_TRUE);
262 evas_object_show(bt);
263
264 evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_UP,
265 _notify_show, notify);
266 evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_MOVE,
267 _notify_show, notify);
268
269 evas_object_resize(win, 600, 400);
270 evas_object_show(win);
271
272 elm_run();
273
274 return 0;
275}
276ELM_MAIN()