New flip mode called ELM_FLIP_CROSS_FADE

Summary: Added new flip mode called ELM_FLIP_CROSS_FADE, which causes one content to fade in while the other fades out. Updated test_flip.c program to include a button for testing the new flip mode.

Test Plan: Run the elementary_test program, and open the Flip test. There is a new button labelled "9" that will activate the new cross-fade flip mode.

Reviewers: Hermet, bu5hm4n, raster

Reviewed By: bu5hm4n

Subscribers: bu5hm4n, cedric, jpeg

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D4314
This commit is contained in:
Markus Svilans 2016-10-21 14:12:58 +09:00 committed by Carsten Haitzler (Rasterman)
parent 8040d20f90
commit 8e2f33381d
4 changed files with 108 additions and 4 deletions

View File

@ -59,6 +59,13 @@ my_fl_8(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
elm_flip_go(fl, ELM_FLIP_CUBE_DOWN);
}
void
my_fl_9(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *fl = data;
elm_flip_go(fl, ELM_FLIP_CROSS_FADE);
}
void
my_fl_front(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
@ -203,6 +210,22 @@ test_flip(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info
elm_box_pack_end(bx, bx2);
evas_object_show(bx2);
bx2 = elm_box_add(win);
elm_box_horizontal_set(bx2, EINA_TRUE);
evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0.0);
bt = elm_button_add(win);
elm_object_text_set(bt, "9");
evas_object_smart_callback_add(bt, "clicked", my_fl_9, fl);
evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
elm_box_pack_end(bx2, bt);
evas_object_show(bt);
elm_box_pack_end(bx, bx2);
evas_object_show(bx2);
evas_object_resize(win, 320, 480);
evas_object_show(win);
}

View File

@ -872,6 +872,41 @@ _state_update(Evas_Object *obj)
return 1;
}
static void
_cross_fade_update(Evas_Object *obj, double t)
{
int ca, cb;
Evas_Object *aclip, *bclip;
Eina_Bool front;
double s;
EFL_UI_FLIP_DATA_GET(obj, sd);
front = sd->next_state;
s = sin(t * M_PI_2); // fade in sinusoidally
t = s * s;
ca = 255 * t;
if (ca < 0) ca = 0;
if (ca > 255) ca = 255;
cb = sqrt(255 * 255 - ca * ca);
if (cb < 0) cb = 0;
if (cb > 255) cb = 255;
if (front)
{
aclip = sd->front.clip;
bclip = sd->back.clip;
}
else
{
aclip = sd->back.clip;
bclip = sd->front.clip;
}
evas_object_color_set(aclip, ca, ca, ca, ca);
evas_object_color_set(bclip, cb, cb, cb, cb);
}
static void
_state_end(Efl_Ui_Flip_Data *sd)
{
@ -1308,6 +1343,13 @@ _flip(Evas_Object *obj)
_flip_show_hide(obj);
_state_update(obj);
}
else if (sd->mode == ELM_FLIP_CROSS_FADE)
{
sd->dir = 0;
sd->started = EINA_TRUE;
sd->pageflip = EINA_FALSE;
_cross_fade_update(obj, t);
}
else
_flip_do(obj, t, sd->mode, 0, 0);
}
@ -1337,6 +1379,14 @@ _flip(Evas_Object *obj)
sd->state = sd->next_state;
_configure(obj);
_flip_show_hide(obj);
if (sd->mode == ELM_FLIP_CROSS_FADE)
{
// Make the content fully opaque again
evas_object_color_set(sd->front.clip, 255, 255, 255, 255);
evas_object_color_set(sd->back.clip, 255, 255, 255, 255);
}
efl_event_callback_legacy_call(obj, EFL_UI_FLIP_EVENT_ANIMATE_DONE, NULL);
// update the new front and back object.
@ -1905,7 +1955,6 @@ _internal_elm_flip_go_to(Evas_Object *obj,
Elm_Flip_Mode mode)
{
if (!sd->animator) sd->animator = ecore_animator_add(_animate, obj);
_flip_show_hide(obj);
sd->mode = mode;
sd->start = ecore_loop_time_get();
@ -1919,6 +1968,33 @@ _internal_elm_flip_go_to(Evas_Object *obj,
sd->pageflip = EINA_TRUE;
// force calc to contents are the right size before transition
evas_smart_objects_calculate(evas_object_evas_get(obj));
if (sd->mode == ELM_FLIP_CROSS_FADE)
{
// Convention: a is fading in, b is fading out
Evas_Object *a, *b;
if (front)
{
a = sd->front.content;
b = sd->back.content;
}
else
{
a = sd->back.content;
b = sd->front.content;
}
// Stack fade-in content on top of fade-out content
if (a && b) evas_object_stack_above(a, b);
evas_object_show(sd->front.clip);
evas_object_show(sd->back.clip);
}
else
{
_flip_show_hide(obj);
}
_flip(obj);
// FIXME: hack around evas rendering bug (only fix makes evas bitch-slow)
evas_object_map_enable_set(sd->front.content, EINA_FALSE);
@ -1928,6 +2004,7 @@ _internal_elm_flip_go_to(Evas_Object *obj,
evas_smart_objects_calculate(evas_object_evas_get(obj));
_configure(obj);
// FIXME: end hack
efl_event_callback_legacy_call(obj, EFL_UI_FLIP_EVENT_ANIMATE_BEGIN, NULL);
// set focus to the content object when flip go to is called

View File

@ -13,7 +13,8 @@ enum Efl.Ui.Flip.Mode
page_left,
page_right,
page_up,
page_down
page_down,
cross_fade,
}
enum Efl.Ui.Flip.Interaction
@ -159,9 +160,11 @@ class Efl.Ui.Flip (Elm.Widget, Efl.Pack.Linear, Efl.Part)
right s if the flip was a book, the other content is shown as the
page below that), #ELM_FLIP_PAGE_UP (move the currently visible
content up as if the flip was a book, the other content is shown
as the page below that) and #ELM_FLIP_PAGE_DOWN (move the
as the page below that), #ELM_FLIP_PAGE_DOWN (move the
currently visible content down as if the flip was a book, the
other content is shown as the page below that).
other content is shown as the page below that) and #ELM_FLIP_CROSS_FADE
(fade out the currently visible content, while fading in the
invisible content).
]]
/* FIXME-doc
* @image html elm_flip.png

View File

@ -22,6 +22,7 @@ typedef Efl_Ui_Flip_Mode Elm_Flip_Mode;
#define ELM_FLIP_PAGE_RIGHT EFL_UI_FLIP_PAGE_RIGHT
#define ELM_FLIP_PAGE_UP EFL_UI_FLIP_PAGE_UP
#define ELM_FLIP_PAGE_DOWN EFL_UI_FLIP_PAGE_DOWN
#define ELM_FLIP_CROSS_FADE EFL_UI_FLIP_CROSS_FADE
typedef enum
{