From 31b2d1155a8c5273932ab38b1ad77a43c35152af Mon Sep 17 00:00:00 2001 From: Jonathan Atton Date: Thu, 24 Sep 2009 09:43:05 +0000 Subject: [PATCH] elementary slideshow : add a timer SVN revision: 42670 --- src/bin/test_slideshow.c | 55 +++++++++++++++++- src/lib/Elementary.h.in | 6 ++ src/lib/elm_slideshow.c | 146 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 184 insertions(+), 23 deletions(-) diff --git a/src/bin/test_slideshow.c b/src/bin/test_slideshow.c index d0495f9..ceece30 100644 --- a/src/bin/test_slideshow.c +++ b/src/bin/test_slideshow.c @@ -4,7 +4,7 @@ #include #ifndef ELM_LIB_QUICKLAUNCH -static Evas_Object *slideshow; +static Evas_Object *slideshow, *bt_start, *bt_stop; static void _notify_show(void *data, Evas_Object *obj, void *event_info) @@ -45,11 +45,34 @@ _hv_select(void *data, Evas_Object *obj, void *event_info) elm_hoversel_label_set(obj, data); } +static void +_start(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + elm_slideshow_timeout_set(slideshow, (int)elm_spinner_value_get(data)); + + elm_widget_disabled_set(bt_start, 1); + elm_widget_disabled_set(bt_stop, 0); +} + +static void +_stop(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + elm_slideshow_timeout_set(slideshow, 0); + elm_widget_disabled_set(bt_start, 0); + elm_widget_disabled_set(bt_stop, 1); +} + +static void +_spin(void *data, Evas *e, Evas_Object *obj, void *event_info) +{ + if(elm_slideshow_timeout_get(slideshow) > 0) + elm_slideshow_timeout_set(slideshow, (int)elm_spinner_value_get(data)); +} void test_slideshow(void *data, Evas_Object *obj, void *event_info) { - Evas_Object *win, *bg, *notify, *bx, *bt, *hv; + Evas_Object *win, *bg, *notify, *bx, *bt, *hv, *spin; char buf[PATH_MAX]; const Eina_List *l; const char *transition; @@ -64,6 +87,7 @@ test_slideshow(void *data, Evas_Object *obj, void *event_info) evas_object_show(bg); slideshow = elm_slideshow_add(win); + elm_slideshow_loop_set(slideshow, 1); elm_win_resize_object_add(win, slideshow); evas_object_size_hint_weight_set(slideshow, 1.0, 1.0); evas_object_show(slideshow); @@ -109,10 +133,35 @@ test_slideshow(void *data, Evas_Object *obj, void *event_info) elm_hoversel_label_set(hv, eina_list_data_get(elm_slideshow_transitions_get(slideshow))); evas_object_show(hv); + spin = elm_spinner_add(win); + elm_spinner_label_format_set(spin, "%2.0f secs."); + evas_object_smart_callback_add(spin, "changed", _spin, spin); + elm_spinner_step_set(spin, 1); + elm_spinner_min_max_set(spin, 1, 30); + elm_spinner_value_set(spin, 3); + elm_box_pack_end(bx, spin); + evas_object_show(spin); + + bt = elm_button_add(win); + bt_start = bt; + elm_button_label_set(bt, "Start"); + evas_object_smart_callback_add(bt, "clicked", _start, spin); + elm_box_pack_end(bx, bt); + evas_object_show(bt); + + bt = elm_button_add(win); + bt_stop = bt; + elm_button_label_set(bt, "Stop"); + evas_object_smart_callback_add(bt, "clicked", _stop, spin); + elm_box_pack_end(bx, bt); + elm_widget_disabled_set(bt, 1); + evas_object_show(bt); + + evas_object_smart_callback_add(slideshow, "clicked", _notify_show, notify); evas_object_smart_callback_add(slideshow, "move", _notify_show, notify); - evas_object_resize(win, 250, 200); + evas_object_resize(win, 350, 200); evas_object_show(win); } diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index 4a37b98..6df2571 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -798,7 +798,13 @@ extern "C" { EAPI void elm_slideshow_previous(Evas_Object *obj); EAPI const Eina_List *elm_slideshow_transitions_get(Evas_Object *obj); EAPI void elm_slideshow_transition_set(Evas_Object *obj, const char *); + EAPI void elm_slideshow_timeout_set(Evas_Object *obj ,int timeout); + EAPI int elm_slideshow_timeout_get(Evas_Object *obj); + EAPI void elm_slideshow_loop_set(Evas_Object *obj, int loop); + EAPI void elm_slideshow_clear(Evas_Object *obj); /* smart callbacks called: + * "clicked" - the use click on the widget + * "move" - the mouse move on the widget) */ diff --git a/src/lib/elm_slideshow.c b/src/lib/elm_slideshow.c index f29cae8..c0d61f8 100644 --- a/src/lib/elm_slideshow.c +++ b/src/lib/elm_slideshow.c @@ -27,14 +27,17 @@ struct _Node struct _Widget_Data { Evas_Object *slideshow; - Evas_Object *img1, *img2; // list of char* Eina_List *images; int current; + int loop; Eina_List *transitions; const char *transition; + + Ecore_Timer *timer; + int timeout; }; static void _del_hook(Evas_Object *obj); @@ -49,6 +52,8 @@ static void _signal_move(void *data, Evas *e, Evas_Object *obj, void *event_info _del_hook(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); + elm_slideshow_clear(obj); + _stringlist_free(wd->transitions); free(wd); } @@ -83,18 +88,12 @@ _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info) static void _sub_del(void *data, Evas_Object *obj, void *event_info) { + Node *node; Widget_Data *wd = elm_widget_data_get(obj); Evas_Object *sub = event_info; - evas_object_event_callback_del - (wd->img1, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints); - evas_object_del(wd->img1); - - evas_object_event_callback_del - (wd->img2, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints); - evas_object_del(wd->img2); } -static void + static void _signal_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info) { Widget_Data *wd = elm_widget_data_get(data); @@ -102,7 +101,7 @@ _signal_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info) evas_object_smart_callback_call(data, "clicked", NULL); } -static void + static void _signal_move(void *data, Evas *e, Evas_Object *obj, void *event_info) { Widget_Data *wd = elm_widget_data_get(data); @@ -110,7 +109,7 @@ _signal_move(void *data, Evas *e, Evas_Object *obj, void *event_info) evas_object_smart_callback_call(data, "move", NULL); } -static void + static void _end(void *data, Evas_Object *obj, const char *emission, const char *source) { Node *node; @@ -125,6 +124,18 @@ _end(void *data, Evas_Object *obj, const char *emission, const char *source) evas_object_image_file_set((Evas_Object *)o, node->file, node->group); } + + static int +_timer_cb(void *data) +{ + Evas_Object *obj = data; + Widget_Data *wd = elm_widget_data_get(obj); + + wd->timer = NULL; + elm_slideshow_next(obj); + return 0; +} + /** * Add a new slideshow to the parent * @@ -211,9 +222,6 @@ elm_slideshow_goto(Evas_Object *obj, int pos) if(pos<0 || pos>=eina_list_count(wd->images)) return ; - if(wd->img1) - evas_object_del(wd->img1); - wd->current = pos; node = eina_list_nth(wd->images, wd->current); @@ -232,13 +240,21 @@ elm_slideshow_next(Evas_Object *obj) char buf[1024]; const Evas_Object *o; Node *node; + int next; Widget_Data *wd = elm_widget_data_get(obj); if(!wd) return; - if(wd->current >= eina_list_count(wd->images) - 1) + if(eina_list_count(wd->images) <= 0 + || (wd->current >= eina_list_count(wd->images) - 1 + && !wd->loop)) return ; - node = eina_list_nth(wd->images, wd->current + 1); + if(wd->current >= eina_list_count(wd->images) - 1) + next = 0; + else + next = wd->current + 1; + + node = eina_list_nth(wd->images, next); _end(obj, obj, NULL, NULL); @@ -248,7 +264,13 @@ elm_slideshow_next(Evas_Object *obj) snprintf(buf, 1024, "%s,next", wd->transition); edje_object_signal_emit(wd->slideshow, buf, "slideshow"); - wd->current++; + wd->current = next; + + if(wd->timer) + ecore_timer_del(wd->timer); + wd->timer = NULL; + if(wd->timeout>0) + wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj); } /** @@ -262,13 +284,21 @@ elm_slideshow_previous(Evas_Object *obj) char buf[1024]; const Evas_Object *o; Node *node; + int previous; Widget_Data *wd = elm_widget_data_get(obj); if(!wd) return; - if(wd->current <= 0) + if(eina_list_count(wd->images) <= 0 + || (wd->current <= 0 + && !wd->loop)) return ; - node = eina_list_nth(wd->images, wd->current - 1); + if(wd->current <= 0) + previous = eina_list_count(wd->images) - 1; + else + previous = wd->current - 1; + + node = eina_list_nth(wd->images, previous); _end(obj, obj, NULL, NULL); @@ -278,7 +308,13 @@ elm_slideshow_previous(Evas_Object *obj) snprintf(buf, 1024, "%s,previous", wd->transition); edje_object_signal_emit(wd->slideshow, buf, "slideshow"); - wd->current--; + wd->current = previous; + + if(wd->timer) + ecore_timer_del(wd->timer); + wd->timer = NULL; + if(wd->timeout>0) + wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj); } /** @@ -312,3 +348,73 @@ elm_slideshow_transition_set(Evas_Object *obj, const char *transition) wd->transition = eina_stringshare_add(transition); } +/** + * The object can go to the next image automatically after a few seconds. + * This method set the timeout to use. A timeout <=0 disable the timer. + * + * @param obj The slideshow object + * @param timeout The new timeout + */ + EAPI void +elm_slideshow_timeout_set(Evas_Object *obj ,int timeout) +{ + Widget_Data *wd = elm_widget_data_get(obj); + if(!wd) return; + + wd->timeout = timeout; + if(wd->timer) + ecore_timer_del(wd->timer); + wd->timer = NULL; + if(timeout>0) + wd->timer = ecore_timer_add(timeout, _timer_cb, obj); +} + +/** + * Returns the timeout value + * + * @param obj The slideshow object + * @return Returns the timeout + */ + EAPI int +elm_slideshow_timeout_get(Evas_Object *obj) +{ + Widget_Data *wd = elm_widget_data_get(obj); + if(!wd) return; + + return wd->timeout; +} + +/** + * Set if the first image should follow the last + * + * @param obj The slideshow object + * @param loop if 1, the first image will follow the last + */ + EAPI void +elm_slideshow_loop_set(Evas_Object *obj, int loop) +{ + Widget_Data *wd = elm_widget_data_get(obj); + if(!wd) return; + + wd->loop = loop; +} + +/** + * Delete all the images + * + * @param obj The slideshow object + */ + EAPI void +elm_slideshow_clear(Evas_Object *obj) +{ + Node *node; + Widget_Data *wd = elm_widget_data_get(obj); + if(!wd) return; + + EINA_LIST_FREE(wd->images, node) + { + if(node->file) eina_stringshare_del(node->file); + if(node->group) eina_stringshare_del(node->group); + } +} + -- 2.7.4