aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/elementary/src/examples/slideshow_example.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/elementary/src/examples/slideshow_example.c323
1 files changed, 323 insertions, 0 deletions
diff --git a/libraries/elementary/src/examples/slideshow_example.c b/libraries/elementary/src/examples/slideshow_example.c
new file mode 100644
index 0000000..db011b8
--- /dev/null
+++ b/libraries/elementary/src/examples/slideshow_example.c
@@ -0,0 +1,323 @@
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
14static void
15_on_done(void *data,
16 Evas_Object *obj,
17 void *event_info)
18{
19 elm_exit();
20}
21
22static Evas_Object *slideshow, *bt_start, *bt_stop;
23static Elm_Slideshow_Item_Class itc;
24
25static char img1[256], img2[256], img3[256], img4[256], img5[256], img6[256], img7[256], img8[256], img9[256];
26
27static void
28_notify_show(void *data,
29 Evas *e,
30 Evas_Object *obj,
31 void *event_info)
32{
33 evas_object_show(data);
34}
35
36/* jump to next item, cyclically */
37static void
38_next(void *data,
39 Evas_Object *obj,
40 void *event_info)
41{
42 elm_slideshow_next(data);
43}
44
45static void
46_previous(void *data,
47 Evas_Object *obj,
48 void *event_info)
49{
50 elm_slideshow_previous(data);
51}
52
53static void
54_first(void *data,
55 Evas_Object *obj,
56 void *event_info)
57{
58 elm_slideshow_item_show(data);
59}
60
61static void
62_last(void *data,
63 Evas_Object *obj,
64 void *event_info)
65{
66 elm_slideshow_item_show(data);
67}
68
69static void
70_mouse_in(void *data,
71 Evas *e,
72 Evas_Object *obj,
73 void *event_info)
74{
75 elm_notify_timeout_set(data, 0.0);
76 evas_object_show(data);
77}
78
79static void
80_mouse_out(void *data,
81 Evas *e,
82 Evas_Object *obj,
83 void *event_info)
84{
85 elm_notify_timeout_set(data, 3.0);
86}
87
88/* transition changed */
89static void
90_transition_select(void *data,
91 Evas_Object *obj,
92 void *event_info)
93{
94 elm_slideshow_transition_set(slideshow, data);
95 elm_object_text_set(obj, data);
96}
97
98static void
99_layout_select(void *data,
100 Evas_Object *obj,
101 void *event_info)
102{
103 elm_slideshow_layout_set(slideshow, data);
104 elm_object_text_set(obj, data);
105}
106
107/* start the show! */
108static void
109_start(void *data,
110 Evas_Object *obj,
111 void *event_info)
112{
113 elm_slideshow_timeout_set(slideshow, elm_spinner_value_get(data));
114
115 elm_object_disabled_set(bt_start, EINA_TRUE);
116 elm_object_disabled_set(bt_stop, EINA_FALSE);
117}
118
119static void
120_stop(void *data,
121 Evas_Object *obj,
122 void *event_info)
123{
124 elm_slideshow_timeout_set(slideshow, 0.0);
125 elm_object_disabled_set(bt_start, EINA_FALSE);
126 elm_object_disabled_set(bt_stop, EINA_TRUE);
127}
128
129/* slideshow transition time has changed */
130static void
131_spin(void *data,
132 Evas_Object *obj,
133 void *event_info)
134{
135 if (elm_slideshow_timeout_get(slideshow) > 0)
136 elm_slideshow_timeout_set(slideshow, elm_spinner_value_get(data));
137}
138
139/* get our images to make slideshow items */
140static Evas_Object *
141_get(void *data,
142 Evas_Object *obj)
143{
144 Evas_Object *photo = elm_photo_add(obj);
145 elm_photo_file_set(photo, data);
146 elm_photo_fill_inside_set(photo, EINA_TRUE);
147 elm_object_style_set(photo, "shadow");
148
149 return photo;
150}
151
152/* ordering alphabetically */
153static int
154_cmp_func(const void *data1,
155 const void *data2)
156{
157 const char *img_path1, *img_path2;
158
159 const Elm_Object_Item *slide_it1 = data1;
160 const Elm_Object_Item *slide_it2 = data2;
161
162 img_path1 = elm_object_item_data_get(slide_it1);
163 img_path2 = elm_object_item_data_get(slide_it2);
164
165 return strcasecmp(img_path1, img_path2);
166}
167
168EAPI_MAIN int
169elm_main(int argc,
170 char **argv)
171{
172 Evas_Object *win, *bg, *notify, *bx, *bt, *hv, *spin;
173 Elm_Object_Item *slide_first, *slide_last, *slide_it;
174 const char *transition, *layout;
175 const Eina_List *l, *list;
176 const char *data_dir;
177
178 elm_app_info_set(elm_main, "elementary", "images");
179 data_dir = elm_app_data_dir_get();
180 snprintf(img1, sizeof(img1), "%s/images/logo.png", data_dir);
181 snprintf(img2, sizeof(img2), "%s/images/plant_01.jpg", data_dir);
182 snprintf(img3, sizeof(img3), "%s/images/rock_01.jpg", data_dir);
183 snprintf(img4, sizeof(img4), "%s/images/rock_02.jpg", data_dir);
184 snprintf(img5, sizeof(img5), "%s/images/sky_01.jpg", data_dir);
185 snprintf(img6, sizeof(img6), "%s/images/sky_04.jpg", data_dir);
186 snprintf(img7, sizeof(img7), "%s/images/wood_01.jpg", data_dir);
187 snprintf(img8, sizeof(img8), "%s/images/mystrale.jpg", data_dir);
188 snprintf(img9, sizeof(img9), "%s/images/mystrale_2.jpg", data_dir);
189
190 win = elm_win_add(NULL, "slideshow", ELM_WIN_BASIC);
191 elm_win_title_set(win, "Slideshow example");
192 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
193 elm_win_autodel_set(win, EINA_TRUE);
194 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
195 evas_object_resize(win, 600, 400);
196 evas_object_show(win);
197
198 bg = elm_bg_add(win);
199 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
200 elm_win_resize_object_add(win, bg);
201 evas_object_show(bg);
202
203 slideshow = elm_slideshow_add(win);
204 elm_slideshow_loop_set(slideshow, EINA_TRUE);
205 evas_object_size_hint_weight_set(slideshow,
206 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
207 elm_win_resize_object_add(win, slideshow);
208 evas_object_show(slideshow);
209
210 itc.func.get = _get;
211 itc.func.del = NULL;
212
213 slide_first = elm_slideshow_item_sorted_insert(slideshow, &itc, img1, _cmp_func);
214 elm_slideshow_item_sorted_insert(slideshow, &itc, img2, _cmp_func);
215 elm_slideshow_item_sorted_insert(slideshow, &itc, img3, _cmp_func);
216 elm_slideshow_item_sorted_insert(slideshow, &itc, img4, _cmp_func);
217 elm_slideshow_item_sorted_insert(slideshow, &itc, img5, _cmp_func);
218 elm_slideshow_item_sorted_insert(slideshow, &itc, img6, _cmp_func);
219 elm_slideshow_item_sorted_insert(slideshow, &itc, img7, _cmp_func);
220 elm_slideshow_item_sorted_insert(slideshow, &itc, img8, _cmp_func);
221 slide_last = elm_slideshow_item_add(slideshow, &itc, img9);
222
223 list = elm_slideshow_items_get(slideshow);
224 fprintf(stdout, "List of items in the slideshow:\n");
225 EINA_LIST_FOREACH(list, l, slide_it)
226 fprintf(stdout, "\t%s\n",
227 (const char *)elm_object_item_data_get(slide_it));
228
229 notify = elm_notify_add(win);
230 elm_notify_orient_set(notify, ELM_NOTIFY_ORIENT_BOTTOM);
231 evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
232 elm_win_resize_object_add(win, notify);
233 elm_notify_timeout_set(notify, 3.0);
234
235 bx = elm_box_add(win);
236 elm_box_horizontal_set(bx, EINA_TRUE);
237 elm_object_content_set(notify, bx);
238 evas_object_show(bx);
239
240 evas_object_event_callback_add(bx, EVAS_CALLBACK_MOUSE_IN, _mouse_in,
241 notify);
242 evas_object_event_callback_add(bx, EVAS_CALLBACK_MOUSE_OUT, _mouse_out,
243 notify);
244
245 bt = elm_button_add(win);
246 elm_object_text_set(bt, "Previous");
247 evas_object_smart_callback_add(bt, "clicked", _previous, slideshow);
248 elm_box_pack_end(bx, bt);
249 evas_object_show(bt);
250
251 bt = elm_button_add(win);
252 elm_object_text_set(bt, "Next");
253 evas_object_smart_callback_add(bt, "clicked", _next, slideshow);
254 elm_box_pack_end(bx, bt);
255 evas_object_show(bt);
256
257 bt = elm_button_add(win);
258 elm_object_text_set(bt, "First");
259 evas_object_smart_callback_add(bt, "clicked", _first, slide_first);
260 elm_box_pack_end(bx, bt);
261 evas_object_show(bt);
262
263 bt = elm_button_add(win);
264 elm_object_text_set(bt, "Last");
265 evas_object_smart_callback_add(bt, "clicked", _last, slide_last);
266 elm_box_pack_end(bx, bt);
267 evas_object_show(bt);
268
269 hv = elm_hoversel_add(win);
270 elm_box_pack_end(bx, hv);
271 elm_hoversel_hover_parent_set(hv, win);
272 EINA_LIST_FOREACH(elm_slideshow_transitions_get(slideshow), l, transition)
273 elm_hoversel_item_add(hv, transition, NULL, 0, _transition_select,
274 transition);
275 elm_object_text_set(hv, eina_list_data_get(
276 elm_slideshow_transitions_get(slideshow)));
277 evas_object_show(hv);
278
279 hv = elm_hoversel_add(win);
280 elm_box_pack_end(bx, hv);
281 elm_hoversel_hover_parent_set(hv, win);
282 EINA_LIST_FOREACH(elm_slideshow_layouts_get(slideshow), l, layout)
283 elm_hoversel_item_add(hv, layout, NULL, 0, _layout_select, layout);
284 elm_object_text_set(hv, elm_slideshow_layout_get(slideshow));
285 evas_object_show(hv);
286
287 spin = elm_spinner_add(win);
288 elm_spinner_label_format_set(spin, "%2.0f s");
289 evas_object_smart_callback_add(spin, "changed", _spin, spin);
290 elm_spinner_step_set(spin, 1);
291 elm_spinner_min_max_set(spin, 1, 30);
292 elm_spinner_value_set(spin, 3);
293 elm_box_pack_end(bx, spin);
294 evas_object_show(spin);
295
296 bt = elm_button_add(win);
297 bt_start = bt;
298 elm_object_text_set(bt, "Start");
299 evas_object_smart_callback_add(bt, "clicked", _start, spin);
300 elm_box_pack_end(bx, bt);
301 evas_object_show(bt);
302
303 bt = elm_button_add(win);
304 bt_stop = bt;
305 elm_object_text_set(bt, "Stop");
306 evas_object_smart_callback_add(bt, "clicked", _stop, spin);
307 elm_box_pack_end(bx, bt);
308 elm_object_disabled_set(bt, EINA_TRUE);
309 evas_object_show(bt);
310
311 evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_UP,
312 _notify_show, notify);
313 evas_object_event_callback_add(slideshow, EVAS_CALLBACK_MOUSE_MOVE,
314 _notify_show, notify);
315
316 _notify_show(notify, NULL, NULL, NULL);
317
318 elm_run();
319 elm_shutdown();
320
321 return 0;
322}
323ELM_MAIN()