summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-12-11 11:37:04 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-12-11 15:02:20 +0900
commit9a438f8ac9e5f0cb6a16aef01a5e7de6b703b6ea (patch)
treea76c30175480395a030ce277fbc495bbf7e8682d
parente735e52c3258a7698b884c0dc2af866e37af6996 (diff)
Flip: Fix confusion with hitsize and direction
Elm Flip has some confusing API (and documentation as well) regarding flip directions and hitsize. Basically, it works just as expected when everything is set to 1 (all hitsizes are 100% and all directions are enabled), like in the elm example file :) BUT, it's not actually possible to restrict the hitsize for one direction. Example: You want to flip to left only. Set direction enabled LEFT. Then, you must set the hitsize for... RIGHT because that's where the finger interaction will start from (right to left!). BUT since RIGHT interaction is not enabled, the histize parameter on RIGHT will have NO effect on the flip. Here's what this commit fixes: - Clear up a bit of the confusion between direction and hit area, through documentation - Separate hit area position and direction (bugfix) - Allow for negative hitsize values to DISABLE a specific area (define previously undefined behaviour) So, it will be possible for example: - Enable left/right interactions - Only on the top 10% of the widget NOTE: This breaks behaviour! API/ABI are not quite broken but undefined behaviour just got defined and fixed.
-rw-r--r--src/lib/elm_flip.c98
-rw-r--r--src/lib/elm_flip_legacy.h16
2 files changed, 62 insertions, 52 deletions
diff --git a/src/lib/elm_flip.c b/src/lib/elm_flip.c
index c24e25da9..36f2fdd32 100644
--- a/src/lib/elm_flip.c
+++ b/src/lib/elm_flip.c
@@ -1689,7 +1689,6 @@ _move_cb(void *data,
1689 if (((dx * dx) + (dy * dy)) > 1689 if (((dx * dx) + (dy * dy)) >
1690 (_elm_config->finger_size * _elm_config->finger_size / 4)) 1690 (_elm_config->finger_size * _elm_config->finger_size / 4))
1691 { 1691 {
1692 sd->dir = ELM_FLIP_DIRECTION_LEFT;
1693 if ((sd->x > (w / 2)) && 1692 if ((sd->x > (w / 2)) &&
1694 (dx < 0) && (abs(dx) > abs(dy))) 1693 (dx < 0) && (abs(dx) > abs(dy)))
1695 { 1694 {
@@ -1712,6 +1711,7 @@ _move_cb(void *data,
1712 sd->dir = ELM_FLIP_DIRECTION_DOWN; 1711 sd->dir = ELM_FLIP_DIRECTION_DOWN;
1713 if (!sd->dir_enabled[ELM_FLIP_DIRECTION_DOWN]) return; 1712 if (!sd->dir_enabled[ELM_FLIP_DIRECTION_DOWN]) return;
1714 } 1713 }
1714 else return;
1715 1715
1716 sd->started = EINA_TRUE; 1716 sd->started = EINA_TRUE;
1717 if (sd->intmode == ELM_FLIP_INTERACTION_PAGE) 1717 if (sd->intmode == ELM_FLIP_INTERACTION_PAGE)
@@ -2035,6 +2035,31 @@ elm_flip_interaction_set(Evas_Object *obj,
2035} 2035}
2036 2036
2037static void 2037static void
2038_event_rect_create(Eo *obj, Elm_Flip_Smart_Data *sd, int i)
2039{
2040 Evas_Object *clip;
2041 Evas *e;
2042
2043 if (sd->event[i]) return;
2044
2045 e = evas_object_evas_get(obj);
2046 sd->event[i] = evas_object_rectangle_add(e);
2047
2048 clip = evas_object_clip_get(obj);
2049 evas_object_data_set(sd->event[i], "_elm_leaveme", obj);
2050 evas_object_clip_set(sd->event[i], clip);
2051 evas_object_color_set(sd->event[i], 0, 0, 0, 0);
2052 evas_object_show(sd->event[i]);
2053 evas_object_smart_member_add(sd->event[i], obj);
2054 evas_object_event_callback_add
2055 (sd->event[i], EVAS_CALLBACK_MOUSE_DOWN, _down_cb, obj);
2056 evas_object_event_callback_add
2057 (sd->event[i], EVAS_CALLBACK_MOUSE_UP, _up_cb, obj);
2058 evas_object_event_callback_add
2059 (sd->event[i], EVAS_CALLBACK_MOUSE_MOVE, _move_cb, obj);
2060}
2061
2062static void
2038_interaction_set(Eo *obj, void *_pd, va_list *list) 2063_interaction_set(Eo *obj, void *_pd, va_list *list)
2039{ 2064{
2040 Elm_Flip_Interaction mode = va_arg(*list, Elm_Flip_Interaction); 2065 Elm_Flip_Interaction mode = va_arg(*list, Elm_Flip_Interaction);
@@ -2045,37 +2070,15 @@ _interaction_set(Eo *obj, void *_pd, va_list *list)
2045 if (sd->intmode == mode) return; 2070 if (sd->intmode == mode) return;
2046 sd->intmode = mode; 2071 sd->intmode = mode;
2047 2072
2048 Evas *e = evas_object_evas_get(obj);
2049 Evas_Object *clip = evas_object_clip_get(obj);
2050
2051 for (i = 0; i < 4; i++) 2073 for (i = 0; i < 4; i++)
2052 { 2074 {
2053 if (sd->intmode == ELM_FLIP_INTERACTION_NONE) 2075 if (sd->intmode == ELM_FLIP_INTERACTION_NONE)
2076 ELM_SAFE_FREE(sd->event[i], evas_object_del);
2077 else if (sd->dir_enabled[i])
2054 { 2078 {
2055 if (sd->event[i]) 2079 int area = (i & 0x2) | (i ^ 0x1);
2056 { 2080 if (sd->dir_hitsize[area] >= 0.0)
2057 evas_object_del(sd->event[i]); 2081 _event_rect_create(obj, sd, area);
2058 sd->event[i] = NULL;
2059 }
2060 }
2061 else
2062 {
2063 if ((sd->dir_enabled[i]) && (!sd->event[i]))
2064 {
2065 sd->event[i] = evas_object_rectangle_add(e);
2066
2067 evas_object_data_set(sd->event[i], "_elm_leaveme", obj);
2068 evas_object_clip_set(sd->event[i], clip);
2069 evas_object_color_set(sd->event[i], 0, 0, 0, 0);
2070 evas_object_show(sd->event[i]);
2071 evas_object_smart_member_add(sd->event[i], obj);
2072 evas_object_event_callback_add
2073 (sd->event[i], EVAS_CALLBACK_MOUSE_DOWN, _down_cb, obj);
2074 evas_object_event_callback_add
2075 (sd->event[i], EVAS_CALLBACK_MOUSE_UP, _up_cb, obj);
2076 evas_object_event_callback_add
2077 (sd->event[i], EVAS_CALLBACK_MOUSE_MOVE, _move_cb, obj);
2078 }
2079 } 2082 }
2080 } 2083 }
2081 2084
@@ -2115,6 +2118,7 @@ _interaction_direction_enabled_set(Eo *obj, void *_pd, va_list *list)
2115 Elm_Flip_Direction dir = va_arg(*list, Elm_Flip_Direction); 2118 Elm_Flip_Direction dir = va_arg(*list, Elm_Flip_Direction);
2116 Eina_Bool enabled = va_arg(*list, int); 2119 Eina_Bool enabled = va_arg(*list, int);
2117 int i = (int) dir; 2120 int i = (int) dir;
2121 int area;
2118 2122
2119 Elm_Flip_Smart_Data *sd = _pd; 2123 Elm_Flip_Smart_Data *sd = _pd;
2120 2124
@@ -2122,27 +2126,14 @@ _interaction_direction_enabled_set(Eo *obj, void *_pd, va_list *list)
2122 if (sd->dir_enabled[i] == enabled) return; 2126 if (sd->dir_enabled[i] == enabled) return;
2123 sd->dir_enabled[i] = enabled; 2127 sd->dir_enabled[i] = enabled;
2124 if (sd->intmode == ELM_FLIP_INTERACTION_NONE) return; 2128 if (sd->intmode == ELM_FLIP_INTERACTION_NONE) return;
2125 if ((sd->dir_enabled[i]) && (!sd->event[i])) 2129
2126 { 2130 area = (i & 0x2) | (i ^ 0x1); // up <-> down, left <-> right
2127 sd->event[i] = evas_object_rectangle_add(evas_object_evas_get(obj)); 2131 if (enabled && (sd->dir_hitsize[area] >= 0.0))
2128 2132 _event_rect_create(obj, sd, area);
2129 evas_object_data_set(sd->event[i], "_elm_leaveme", obj); 2133 else if (!enabled && (sd->dir_hitsize[area] <= 0.0))
2130 evas_object_clip_set(sd->event[i], evas_object_clip_get(obj)); 2134 // Delete this hit area as it has the default hitsize (0)
2131 evas_object_color_set(sd->event[i], 0, 0, 0, 0); 2135 ELM_SAFE_FREE(sd->event[area], evas_object_del);
2132 evas_object_show(sd->event[i]); 2136
2133 evas_object_smart_member_add(sd->event[i], obj);
2134 evas_object_event_callback_add(sd->event[i], EVAS_CALLBACK_MOUSE_DOWN,
2135 _down_cb, obj);
2136 evas_object_event_callback_add(sd->event[i], EVAS_CALLBACK_MOUSE_UP,
2137 _up_cb, obj);
2138 evas_object_event_callback_add(sd->event[i], EVAS_CALLBACK_MOUSE_MOVE,
2139 _move_cb, obj);
2140 }
2141 else if (!(sd->dir_enabled[i]) && (sd->event[i]))
2142 {
2143 evas_object_del(sd->event[i]);
2144 sd->event[i] = NULL;
2145 }
2146 _sizing_eval(obj); 2137 _sizing_eval(obj);
2147 _configure(obj); 2138 _configure(obj);
2148} 2139}
@@ -2186,12 +2177,19 @@ _interaction_direction_hitsize_set(Eo *obj, void *_pd, va_list *list)
2186 2177
2187 Elm_Flip_Smart_Data *sd = _pd; 2178 Elm_Flip_Smart_Data *sd = _pd;
2188 2179
2189 if (hitsize < 0.0) hitsize = 0.0; 2180 if (hitsize < 0.0)
2181 hitsize = -1.0;
2190 else if (hitsize > 1.0) 2182 else if (hitsize > 1.0)
2191 hitsize = 1.0; 2183 hitsize = 1.0;
2192 2184
2193 if (sd->dir_hitsize[i] == hitsize) return; 2185 if (sd->dir_hitsize[i] == hitsize) return;
2194 sd->dir_hitsize[i] = hitsize; 2186 sd->dir_hitsize[i] = hitsize;
2187
2188 if (hitsize >= 0.0)
2189 _event_rect_create(obj, sd, i);
2190 else
2191 ELM_SAFE_FREE(sd->event[i], evas_object_del);
2192
2195 _sizing_eval(obj); 2193 _sizing_eval(obj);
2196 _configure(obj); 2194 _configure(obj);
2197} 2195}
diff --git a/src/lib/elm_flip_legacy.h b/src/lib/elm_flip_legacy.h
index 3e463dcd6..6fcf15e1c 100644
--- a/src/lib/elm_flip_legacy.h
+++ b/src/lib/elm_flip_legacy.h
@@ -188,6 +188,10 @@ EAPI Elm_Flip_Interaction elm_flip_interaction_get(const Evas_Object *obj);
188 * desired directions for flipping if you need interactive flipping. You must 188 * desired directions for flipping if you need interactive flipping. You must
189 * call this function once for each direction that should be enabled. 189 * call this function once for each direction that should be enabled.
190 * 190 *
191 * You can also set the appropriate hit area size by calling
192 * @c elm_flip_interaction_direction_hitsize_set(). By default, a minimum
193 * hit area will be created on the opposite edge of the flip.
194 *
191 * @see elm_flip_interaction_set() 195 * @see elm_flip_interaction_set()
192 * 196 *
193 * @ingroup Flip 197 * @ingroup Flip
@@ -213,13 +217,21 @@ EAPI Eina_Bool elm_flip_interaction_direction_enabled_get(Evas_Object
213 * @brief Set the amount of the flip that is sensitive to interactive flip 217 * @brief Set the amount of the flip that is sensitive to interactive flip
214 * 218 *
215 * @param obj The flip object 219 * @param obj The flip object
216 * @param dir The direction to modify 220 * @param dir The hit area to set
217 * @param hitsize The amount of that dimension (0.0 to 1.0) to use 221 * @param hitsize The amount of that dimension (0.0 to 1.0) to use
218 * 222 *
219 * Set the amount of the flip that is sensitive to interactive flip, with 0 223 * Set the amount of the flip that is sensitive to interactive flip, with 0
220 * representing no area in the flip and 1 representing the entire flip. There 224 * representing no area in the flip and 1 representing the entire flip. There
221 * is however a consideration to be made in that the area will never be 225 * is however a consideration to be made in that the area will never be
222 * smaller than the finger size set(as set in your Elementary configuration). 226 * smaller than the finger size set (as set in your Elementary configuration),
227 * and dragging must always start from the opposite half of the flip (eg. right
228 * half of the flip when dragging to the left).
229 *
230 * Note that the @c dir parameter is not actually related to the direction of
231 * the drag, it only refers to the area in the flip where interaction can
232 * occur (top, bottom, left, right).
233 *
234 * Negative values of @c hitsize will disable this hit area.
223 * 235 *
224 * @see elm_flip_interaction_set() 236 * @see elm_flip_interaction_set()
225 * 237 *