elementary, new widget: slideshow. See elementary_test

SVN revision: 42660
This commit is contained in:
Jonathan Atton 2009-09-23 22:56:47 +00:00
parent c85b70fc50
commit 82a9eb4bc5
9 changed files with 707 additions and 52 deletions

View File

@ -6402,6 +6402,323 @@ collections {
}
}
}
///////////////////////////////////////////////////////////////////////////////
group { name: "elm/slideshow/base/default";
data {
item: transitions "fade black_fade horizontal vertical square";
}
parts {
part { name: "elm.image.1";
type: IMAGE;
description {
state: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "fade_prev_next" 0.0;
inherit: "default" 0.0;
color: 255 255 255 0;
}
description {
state: "black_fade_prev_next_init" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "black_fade_prev_next" 0.0;
inherit: "default" 0.0;
color: 0 0 0 255;
}
description {
state: "horizontal_next_init" 0.0;
inherit: "default" 0.0;
}
description {
state: "horizontal_next" 0.0;
inherit: "default" 0.0;
rel1.relative: -1.0 0.0;
rel2.relative: 0.0 1.0;
}
description {
state: "horizontal_prev_init" 0.0;
inherit: "default" 0.0;
}
description {
state: "horizontal_prev" 0.0;
inherit: "default" 0.0;
rel1.relative: 1.0 0.0;
rel2.relative: 2.0 1.0;
}
description {
state: "vertical_next_init" 0.0;
inherit: "default" 0.0;
}
description {
state: "vertical_next" 0.0;
inherit: "default" 0.0;
rel1.relative: 0.0 -1.0;
rel2.relative: 1.0 0.0;
}
description {
state: "vertical_prev_init" 0.0;
inherit: "default" 0.0;
}
description {
state: "vertical_prev" 0.0;
inherit: "default" 0.0;
rel1.relative: 0.0 1.0;
rel2.relative: 1.0 2.0;
}
}
part { name: "elm.image.2";
type: IMAGE;
description {
state: "default" 0.0;
color: 255 255 255 0;
}
description {
state: "fade_prev_next" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "black_fade_prev_next_init" 0.0;
inherit: "default" 0.0;
color: 0 0 0 0;
}
description {
state: "black_fade_prev_next" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "horizontal_next_init" 0.0;
inherit: "default" 0.0;
rel1.relative: 1.0 0.0;
rel2.relative: 2.0 1.0;
color: 255 255 255 255;
}
description {
state: "horizontal_next" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "horizontal_prev_init" 0.0;
inherit: "default" 0.0;
rel1.relative: -1.0 0.0;
rel2.relative: 0.0 1.0;
color: 255 255 255 255;
}
description {
state: "horizontal_prev" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "vertical_next_init" 0.0;
inherit: "default" 0.0;
rel1.relative: 0.0 1.0;
rel2.relative: 1.0 2.0;
color: 255 255 255 255;
}
description {
state: "vertical_next" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "vertical_prev_init" 0.0;
inherit: "default" 0.0;
rel1.relative: 0.0 -1.0;
rel2.relative: 1.0 0.0;
color: 255 255 255 255;
}
description {
state: "vertical_prev" 0.0;
inherit: "default" 0.0;
color: 255 255 255 255;
}
description {
state: "square_prev_next_init" 0.0;
inherit: "default" 0.0;
rel1.relative: 0.5 0.5;
rel2.relative: 0.5 0.5;
color: 255 255 255 255;
}
description {
state: "square_prev_next" 0.0;
inherit: "default" 0.0;
rel1.relative: 0.0 0.0;
rel2.relative: 1.0 1.0;
color: 255 255 255 255;
}
}
}
programs {
program { name: "fade_next";
signal: "fade,next";
source: "slideshow";
action: STATE_SET "default" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "fade_next_2";
}
program { name: "fade_next_2";
action: STATE_SET "fade_prev_next" 0.0;
target: "elm.image.1";
target: "elm.image.2";
transition: SINUSOIDAL 1.5;
after: "end";
}
program { name: "fade_previous";
signal: "fade,previous";
source: "slideshow";
action: STATE_SET "default" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "fade_previous_2";
}
program { name: "fade_previous_2";
action: STATE_SET "fade_prev_next" 0.0;
target: "elm.image.1";
target: "elm.image.2";
transition: SINUSOIDAL 1.5;
after: "end";
}
program { name: "black_fade_next";
signal: "black_fade,next";
source: "slideshow";
action: STATE_SET "black_fade_prev_next_init" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "black_fade_next_2";
}
program { name: "black_fade_next_2";
action: STATE_SET "black_fade_prev_next" 0.0;
target: "elm.image.1";
transition: SINUSOIDAL 0.75;
after: "black_fade_next_3";
}
program { name: "black_fade_next_3";
action: STATE_SET "black_fade_prev_next" 0.0;
target: "elm.image.2";
transition: SINUSOIDAL 0.75;
after: "end";
}
program { name: "black_fade_previous";
signal: "black_fade,previous";
source: "slideshow";
action: STATE_SET "black_fade_prev_next_init" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "black_fade_previous_2";
}
program { name: "black_fade_previous_2";
action: STATE_SET "black_fade_prev_next" 0.0;
target: "elm.image.1";
transition: SINUSOIDAL 0.75;
after: "black_fade_previous_3";
}
program { name: "black_fade_previous_3";
action: STATE_SET "black_fade_prev_next" 0.0;
target: "elm.image.2";
transition: SINUSOIDAL 0.75;
after: "end";
}
program { name: "horizontal_next";
signal: "horizontal,next";
source: "slideshow";
action: STATE_SET "horizontal_next_init" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "horizontal_next_2";
}
program { name: "horizontal_next_2";
action: STATE_SET "horizontal_next" 0.0;
target: "elm.image.1";
target: "elm.image.2";
transition: SINUSOIDAL 1.5;
after: "end";
}
program { name: "horizontal_previous";
signal: "horizontal,previous";
source: "slideshow";
action: STATE_SET "horizontal_prev_init" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "horizontal_previous_2";
}
program { name: "horizontal_previous_2";
action: STATE_SET "horizontal_prev" 0.0;
target: "elm.image.1";
target: "elm.image.2";
transition: SINUSOIDAL 1.5;
after: "end";
}
program { name: "vertical_next";
signal: "vertical,next";
source: "slideshow";
action: STATE_SET "vertical_next_init" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "vertical_next_2";
}
program { name: "vertical_next_2";
action: STATE_SET "vertical_next" 0.0;
target: "elm.image.1";
target: "elm.image.2";
transition: SINUSOIDAL 1.5;
after: "end";
}
program { name: "vertical_previous";
signal: "vertical,previous";
source: "slideshow";
action: STATE_SET "vertical_prev_init" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "vertical_previous_2";
}
program { name: "vertical_previous_2";
action: STATE_SET "vertical_prev" 0.0;
target: "elm.image.1";
target: "elm.image.2";
transition: SINUSOIDAL 1.5;
after: "end";
}
program { name: "square_next";
signal: "square,next";
source: "slideshow";
action: STATE_SET "square_prev_next_init" 0.0;
target: "elm.image.2";
after: "square_next_2";
}
program { name: "square_next_2";
action: STATE_SET "square_prev_next" 0.0;
target: "elm.image.2";
transition: SINUSOIDAL 1.5;
after: "end";
}
program { name: "square_previous";
signal: "square,previous";
source: "slideshow";
action: STATE_SET "square_prev_next_init" 0.0;
target: "elm.image.2";
after: "square_next_2";
}
program { name: "end";
action: STATE_SET "default" 0.0;
target: "elm.image.1";
target: "elm.image.2";
after: "end_signal";
}
program { name: "end_signal";
action: SIGNAL_EMIT "end" "slideshow";
}
}
}
///////////////////////////////////////////////////////////////////////////////
group { name: "elm/win/inwin/default";
images {

View File

@ -61,7 +61,8 @@ test_index.c \
test_photocam.c \
test_photo.c \
test_icon_desktops.c \
test_notify.c
test_notify.c \
test_slideshow.c
elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la
elementary_test_LDFLAGS =

View File

@ -50,6 +50,7 @@ void test_photocam(void *data, Evas_Object *obj, void *event_info);
void test_photo(void *data, Evas_Object *obj, void *event_info);
void test_icon_desktops(void *data, Evas_Object *obj, void *event_info);
void test_notify(void *data, Evas_Object *obj, void *event_info);
void test_slideshow(void *data, Evas_Object *obj, void *event_info);
static void
my_win_del(void *data, Evas_Object *obj, void *event_info)
@ -182,6 +183,8 @@ my_win_main(void)
elm_list_item_append(li, "Photo", NULL, NULL, test_photo, NULL);
elm_list_item_append(li, "Icon Desktops", NULL, NULL, test_icon_desktops, NULL);
elm_list_item_append(li, "Notify", NULL, NULL, test_notify, NULL);
elm_list_item_append(li, "Slideshow", NULL, NULL, test_slideshow, NULL);
elm_list_go(li);

View File

@ -791,6 +791,17 @@ extern "C" {
/* smart callbacks called:
*/
EAPI Evas_Object *elm_slideshow_add(Evas_Object *parent);
EAPI void elm_slideshow_image_add(Evas_Object *obj, const char *file, const char *group);
EAPI void elm_slideshow_goto(Evas_Object *obj, int pos);
EAPI void elm_slideshow_next(Evas_Object *obj);
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 *);
/* smart callbacks called:
*/
EAPI Evas_Object *elm_fileselector_add(Evas_Object *parent);
EAPI void elm_fileselector_is_save_set(Evas_Object *obj, Eina_Bool is_save);
EAPI Eina_Bool elm_fileselector_is_save_get(Evas_Object *obj);

View File

@ -61,6 +61,7 @@ elm_spinner.c \
elm_index.c \
elm_photocam.c \
elm_notify.c \
elm_slideshow.c \
\
elc_notepad.c \
elc_anchorview.c \

View File

@ -397,39 +397,6 @@ _sizing_eval(Evas_Object *obj)
evas_object_size_hint_max_set(obj, maxw, maxh);
}
static Eina_List *
_stringlist_get(const char *str)
{
Eina_List *list = NULL;
const char *s, *b;
if (!str) return NULL;
for (b = s = str; 1; s++)
{
if ((*s == ' ') || (*s == 0))
{
char *t = malloc(s - b + 1);
if (t)
{
strncpy(t, b, s - b);
t[s - b] = 0;
list = eina_list_append(list, eina_stringshare_add(t));
free(t);
}
b = s + 1;
}
if (*s == 0) break;
}
return list;
}
static void
_stringlist_free(Eina_List *list)
{
const char *s;
EINA_LIST_FREE(list, s)
eina_stringshare_del(s);
}
static void
_item_hilight(Elm_Genlist_Item *it)
{

View File

@ -20,6 +20,7 @@
#include "els_icon.h"
// FIXME: totally disorganised. clean this up!
// Why EAPI in a private header ?
typedef enum _Elm_Engine
{
@ -110,6 +111,10 @@ EAPI const char *elm_widget_style_get(const Evas_Object *obj);
EAPI void elm_widget_type_set(Evas_Object *obj, const char *type);
EAPI const char *elm_widget_type_get(const Evas_Object *obj);
EAPI Eina_List *_stringlist_get(const char *str);
EAPI void _stringlist_free(Eina_List *list);
extern char *_elm_appname;
extern Elm_Config *_elm_config;
extern const char *_elm_data_dir;

View File

@ -0,0 +1,314 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include <Elementary.h>
#include "elm_priv.h"
/**
* @defgroup Slideshow slideshow
*
* This object display a list of images and some actions like
* next/previous are used to naviguate. The animations are defined in the theme,
* consequently new animations can be added without having to update the
* applications.
*
*/
typedef struct _Widget_Data Widget_Data;
typedef struct _Subinfo Subinfo;
typedef struct _Node Node;
struct _Node
{
const char *file;
const char *group;
};
struct _Widget_Data
{
Evas_Object *slideshow;
Evas_Object *img1, *img2;
// list of char*
Eina_List *images;
int current;
Eina_List *transitions;
const char *transition;
};
static void _del_hook(Evas_Object *obj);
static void _theme_hook(Evas_Object *obj);
static void _sizing_eval(Evas_Object *obj);
static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _signal_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _signal_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void
_del_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
free(wd);
}
static void
_theme_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
_elm_theme_set(wd->slideshow, "slideshow", "base", "default");
edje_object_scale_set(wd->slideshow, elm_widget_scale_get(obj) * _elm_config->scale);
_sizing_eval(obj);
}
static void
_sizing_eval(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
Evas_Coord minw = -1, minh = -1;
edje_object_size_min_calc(wd->slideshow, &minw, &minh);
evas_object_size_hint_min_set(obj, minw, minh);
evas_object_size_hint_max_set(obj, minw, minh);
}
static void
_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
_sizing_eval(data);
}
static void
_sub_del(void *data, Evas_Object *obj, void *event_info)
{
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
_signal_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return;
evas_object_smart_callback_call(data, "clicked", NULL);
}
static void
_signal_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return;
evas_object_smart_callback_call(data, "move", NULL);
}
static void
_end(void *data, Evas_Object *obj, const char *emission, const char *source)
{
Node *node;
const Evas_Object *o;
Widget_Data *wd = elm_widget_data_get(data);
node = eina_list_nth(wd->images, wd->current);
if(!node) return;
o = edje_object_part_object_get(wd->slideshow, "elm.image.1");
evas_object_image_file_set((Evas_Object *)o, node->file, node->group);
}
/**
* Add a new slideshow to the parent
*
* @param parent The parent object
* @return The new object or NULL if it cannot be created
*
* @ingroup Slideshow
*/
EAPI Evas_Object *
elm_slideshow_add(Evas_Object *parent)
{
Evas_Object *obj;
Evas *e;
Widget_Data *wd;
wd = ELM_NEW(Widget_Data);
e = evas_object_evas_get(parent);
obj = elm_widget_add(e);
elm_widget_type_set(obj, "slideshow");
elm_widget_sub_object_add(parent, obj);
elm_widget_data_set(obj, wd);
elm_widget_del_hook_set(obj, _del_hook);
elm_widget_theme_hook_set(obj, _theme_hook);
wd->slideshow = edje_object_add(e);
_elm_theme_set(wd->slideshow, "slideshow", "base", "default");
elm_widget_resize_object_set(obj, wd->slideshow);
evas_object_show(wd->slideshow);
wd->transitions = _stringlist_get(edje_object_data_get(wd->slideshow, "transitions"));
if(eina_list_count(wd->transitions) > 0)
wd->transition = eina_stringshare_add(eina_list_data_get(wd->transitions));
edje_object_signal_callback_add(wd->slideshow, "end", "slideshow", _end, obj);
evas_object_event_callback_add(wd->slideshow, EVAS_CALLBACK_MOUSE_DOWN, _signal_clicked, obj);
evas_object_event_callback_add(wd->slideshow, EVAS_CALLBACK_MOUSE_MOVE, _signal_move, obj);
evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
_sizing_eval(obj);
return obj;
}
/**
* Add an image in the list
*
* @param obj The slideshow object
* @param file The image file
* @param group The edje group if the image is in an eet file
*/
EAPI void
elm_slideshow_image_add(Evas_Object *obj, const char *file, const char *group)
{
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
Node *node = ELM_NEW(Node);
node->file = eina_stringshare_add(file);
if(group)
node->group = eina_stringshare_add(group);
wd->images = eina_list_append(wd->images, node);
if(eina_list_count(wd->images) == 1)
elm_slideshow_goto(obj, 0);
}
/**
* Go to the image number @pos
*
* @param obj The slideshow object
* @param pos The position of the image
*/
EAPI void
elm_slideshow_goto(Evas_Object *obj, int pos)
{
Node *node;
const Evas_Object *o;
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
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);
o = edje_object_part_object_get(wd->slideshow, "elm.image.1");
evas_object_image_file_set((Evas_Object *)o, node->file, node->group);
}
/**
* Go to the next image
*
* @param obj The slideshow object
*/
EAPI void
elm_slideshow_next(Evas_Object *obj)
{
char buf[1024];
const Evas_Object *o;
Node *node;
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
if(wd->current >= eina_list_count(wd->images) - 1)
return ;
node = eina_list_nth(wd->images, wd->current + 1);
_end(obj, obj, NULL, NULL);
o = edje_object_part_object_get(wd->slideshow, "elm.image.2");
evas_object_image_file_set((Evas_Object *)o, node->file, node->group);
snprintf(buf, 1024, "%s,next", wd->transition);
edje_object_signal_emit(wd->slideshow, buf, "slideshow");
wd->current++;
}
/**
* Go to the previous image
*
* @param obj The slideshow object
*/
EAPI void
elm_slideshow_previous(Evas_Object *obj)
{
char buf[1024];
const Evas_Object *o;
Node *node;
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
if(wd->current <= 0)
return ;
node = eina_list_nth(wd->images, wd->current - 1);
_end(obj, obj, NULL, NULL);
o = edje_object_part_object_get(wd->slideshow, "elm.image.2");
evas_object_image_file_set((Evas_Object *)o, node->file, node->group);
snprintf(buf, 1024, "%s,previous", wd->transition);
edje_object_signal_emit(wd->slideshow, buf, "slideshow");
wd->current--;
}
/**
* Returns the list of transitions available.
*
* @param obj The slideshow object
* @return Returns the list of transitions (list of char*)
*/
const Eina_List *
elm_slideshow_transitions_get(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
return wd->transitions;
}
/**
* Set the transition to use
*
* @param obj The slideshow object
* @param transition the new transition
*/
EAPI void
elm_slideshow_transition_set(Evas_Object *obj, const char *transition)
{
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
eina_stringshare_del(wd->transition);
wd->transition = eina_stringshare_add(transition);
}

View File

@ -961,3 +961,39 @@ _smart_init(void)
_e_smart = evas_smart_class_new(&sc);
}
}
Eina_List *
_stringlist_get(const char *str)
{
Eina_List *list = NULL;
const char *s, *b;
if (!str) return NULL;
for (b = s = str; 1; s++)
{
if ((*s == ' ') || (*s == 0))
{
char *t = malloc(s - b + 1);
if (t)
{
strncpy(t, b, s - b);
t[s - b] = 0;
list = eina_list_append(list, eina_stringshare_add(t));
free(t);
}
b = s + 1;
}
if (*s == 0) break;
}
return list;
}
void
_stringlist_free(Eina_List *list)
{
const char *s;
EINA_LIST_FREE(list, s)
eina_stringshare_del(s);
}