kuuko pushed a commit to branch master.
commit 35c3f99d5f44087ff71584f5cd1c3362f23944d5
Author: Kai Huuhko <[email protected]>
Date: Sat Apr 13 15:58:43 2013 +0000
Elementary: Complete the API for Gesture layer.
---
efl/elementary/gesture_layer.pxd | 30 +-
efl/elementary/gesture_layer.pyx | 509 ++++++++++++++++++++++++++++-
examples/elementary/images/pol_shadow.png | Bin 0 -> 1997 bytes
examples/elementary/images/pol_sky.png | Bin 0 -> 121518 bytes
examples/elementary/images/pol_twofish.png | Bin 0 -> 149724 bytes
examples/elementary/postit_ent.edc | 26 ++
examples/elementary/postit_ent.edj | Bin 0 -> 5191 bytes
examples/elementary/test_gesture_layer.py | 331 +++++++++++++++++++
8 files changed, 879 insertions(+), 17 deletions(-)
diff --git a/efl/elementary/gesture_layer.pxd b/efl/elementary/gesture_layer.pxd
index b411a9a..bf9a35d 100644
--- a/efl/elementary/gesture_layer.pxd
+++ b/efl/elementary/gesture_layer.pxd
@@ -1,4 +1,4 @@
-from efl.evas cimport Eina_Bool, Evas_Object, Evas_Coord, Evas_Event_Flags
+from efl.evas cimport Eina_Bool, Evas_Object, const_Evas_Object, Evas_Coord,
Evas_Event_Flags
from enums cimport Elm_Gesture_State, Elm_Gesture_Type
cdef extern from "Elementary.h":
@@ -21,17 +21,17 @@ cdef extern from "Elementary.h":
unsigned int n
- ctypedef struct _Elm_Gesture_Line_Info:
+ ctypedef struct Elm_Gesture_Line_Info:
Elm_Gesture_Momentum_Info momentum
double angle
- ctypedef struct _Elm_Gesture_Zoom_Info:
+ ctypedef struct Elm_Gesture_Zoom_Info:
Evas_Coord x, y
Evas_Coord radius
double zoom
double momentum
- ctypedef struct _Elm_Gesture_Rotate_Info:
+ ctypedef struct Elm_Gesture_Rotate_Info:
Evas_Coord x, y
Evas_Coord radius
double base_angle
@@ -51,3 +51,25 @@ cdef extern from "Elementary.h":
Eina_Bool elm_gesture_layer_attach(Evas_Object *obj,
Evas_Object *target)
Evas_Object *elm_gesture_layer_add(Evas_Object *parent)
+ void elm_gesture_layer_line_min_length_set(Evas_Object *obj, int
line_min_length)
+ int elm_gesture_layer_line_min_length_get(const_Evas_Object *obj)
+ void elm_gesture_layer_zoom_distance_tolerance_set(Evas_Object *obj,
Evas_Coord zoom_distance_tolerance)
+ Evas_Coord elm_gesture_layer_zoom_distance_tolerance_get(const_Evas_Object
*obj)
+ void elm_gesture_layer_line_distance_tolerance_set(Evas_Object *obj,
Evas_Coord line_distance_tolerance)
+ Evas_Coord elm_gesture_layer_line_distance_tolerance_get(const_Evas_Object
*obj)
+ void elm_gesture_layer_line_angular_tolerance_set(Evas_Object *obj, double
line_angular_tolerance)
+ double elm_gesture_layer_line_angular_tolerance_get(const_Evas_Object *obj)
+ void elm_gesture_layer_zoom_wheel_factor_set(Evas_Object *obj, double
zoom_wheel_factor)
+ double elm_gesture_layer_zoom_wheel_factor_get(const_Evas_Object *obj)
+ void elm_gesture_layer_zoom_finger_factor_set(Evas_Object *obj, double
zoom_finger_factor)
+ double elm_gesture_layer_zoom_finger_factor_get(const_Evas_Object *obj)
+ void elm_gesture_layer_rotate_angular_tolerance_set(Evas_Object *obj,
double rotate_angular_tolerance)
+ double elm_gesture_layer_rotate_angular_tolerance_get(const_Evas_Object
*obj)
+ void elm_gesture_layer_flick_time_limit_ms_set(Evas_Object *obj, unsigned
int flick_time_limit_ms)
+ unsigned int elm_gesture_layer_flick_time_limit_ms_get(const_Evas_Object
*obj)
+ void elm_gesture_layer_long_tap_start_timeout_set(Evas_Object *obj, double
long_tap_start_timeout)
+ double elm_gesture_layer_long_tap_start_timeout_get(const_Evas_Object *obj)
+ void elm_gesture_layer_continues_enable_set(Evas_Object *obj, Eina_Bool
continues_enable)
+ Eina_Bool elm_gesture_layer_continues_enable_get(const_Evas_Object *obj)
+ void elm_gesture_layer_double_tap_timeout_set(Evas_Object *obj, double
double_tap_timeout)
+ double elm_gesture_layer_double_tap_timeout_get(const_Evas_Object *obj)
diff --git a/efl/elementary/gesture_layer.pyx b/efl/elementary/gesture_layer.pyx
index 2e1f3f0..5a873c9 100644
--- a/efl/elementary/gesture_layer.pyx
+++ b/efl/elementary/gesture_layer.pyx
@@ -84,6 +84,8 @@ behavior so gesture starts when user touches (a *DOWN* event)
touch-surface and ends when no fingers touches surface (a *UP* event).
+.. _Elm_Gesture_State:
+
.. rubric:: Gesture states
.. data:: ELM_GESTURE_STATE_UNDEFINED
@@ -107,6 +109,8 @@ touch-surface and ends when no fingers touches surface (a
*UP* event).
Ongoing gesture was aborted
+.. _Elm_Gesture_Type:
+
.. rubric:: Gesture types
.. data:: ELM_GESTURE_N_TAPS
@@ -174,14 +178,328 @@ ELM_GESTURE_ZOOM = enums.ELM_GESTURE_ZOOM
ELM_GESTURE_ROTATE = enums.ELM_GESTURE_ROTATE
ELM_GESTURE_LAST = enums.ELM_GESTURE_LAST
-cdef Evas_Event_Flags _gesture_layer_event_cb(void *data, void *event_info)
with gil:
- (callback, args, kwargs) = <object>data
+
+cdef class GestureTapsInfo(object):
+
+ """Holds taps info for user"""
+
+ cdef Elm_Gesture_Taps_Info *info
+
+ property x:
+ """Holds center point between fingers
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.x
+
+ property y:
+ """Holds center point between fingers
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.y
+
+ property n:
+ """Number of fingers tapped
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.n
+
+ property timestamp:
+ """Event timestamp
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.timestamp
+
+cdef class GestureMomentumInfo(object):
+
+ """
+
+ Holds momentum info for user
+ x1 and y1 are not necessarily in sync
+ x1 holds x value of x direction starting point
+ and same holds for y1.
+ This is noticeable when doing V-shape movement
+
+ """
+
+ cdef Elm_Gesture_Momentum_Info *info
+
+ property x1:
+ """Final-swipe direction starting point on X
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.x1
+
+ property y1:
+ """Final-swipe direction starting point on Y
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.y1
+
+ property x2:
+ """Final-swipe direction ending point on X
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.x2
+
+ property y2:
+ """Final-swipe direction ending point on Y
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.y2
+
+ property tx:
+ """Timestamp of start of final x-swipe
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.tx
+
+ property ty:
+ """Timestamp of start of final y-swipe
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.ty
+
+ property mx:
+ """Momentum on X
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.mx
+
+ property my:
+ """Momentum on Y
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.my
+
+ property n:
+ """Number of fingers
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.n
+
+cdef class GestureLineInfo(object):
+
+ """Holds line info for user"""
+
+ cdef Elm_Gesture_Line_Info *info
+
+ property momentum:
+ """Line momentum info
+
+ :type: GestureMomentumInfo
+
+ """
+ def __get__(self):
+ cdef GestureMomentumInfo ret =
GestureMomentumInfo.__new__(GestureMomentumInfo)
+ ret.info = &self.info.momentum
+ return ret
+
+ property angle:
+ """Angle (direction) of lines
+
+ :type: double
+
+ """
+ def __get__(self):
+ return self.info.angle
+
+cdef class GestureZoomInfo(object):
+
+ """Holds zoom info for user"""
+
+ cdef Elm_Gesture_Zoom_Info *info
+
+ property x:
+ """Holds zoom center point reported to user
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.x
+
+ property y:
+ """Holds zoom center point reported to user
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.y
+
+ property radius:
+ """Holds radius between fingers reported to user
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.radius
+
+ property zoom:
+ """Zoom value: 1.0 means no zoom
+
+ :type: double
+
+ """
+ def __get__(self):
+ return self.info.zoom
+
+ property momentum:
+ """Zoom momentum: zoom growth per second (NOT YET SUPPORTED)
+
+ :type: double
+
+ """
+ def __get__(self):
+ return self.info.momentum
+
+cdef class GestureRotateInfo(object):
+
+ """Holds rotation info for user"""
+
+ cdef Elm_Gesture_Rotate_Info *info
+
+ property x:
+ """Holds zoom center point reported to user
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.x
+
+ property y:
+ """Holds zoom center point reported to user
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.y
+
+ property radius:
+ """Holds radius between fingers reported to user
+
+ :type: int
+
+ """
+ def __get__(self):
+ return self.info.radius
+
+ property base_angle:
+ """Holds start-angle
+
+ :type: double
+
+ """
+ def __get__(self):
+ return self.info.base_angle
+
+ property angle:
+ """Rotation value: 0.0 means no rotation
+
+ :type: double
+
+ """
+ def __get__(self):
+ return self.info.angle
+
+ property momentum:
+ """Rotation momentum: rotation done per second (NOT YET SUPPORTED)
+
+ :type: double
+
+ """
+ def __get__(self):
+ return self.info.momentum
+
+cdef Evas_Event_Flags _gesture_layer_taps_event_cb(void *data, void
*event_info) with gil:
+ callback, args, kwargs = <object>data
+ cdef GestureTapsInfo ei = GestureTapsInfo.__new__(GestureTapsInfo)
+ ei.info = <Elm_Gesture_Taps_Info *>event_info
try:
- ret = callback(args, kwargs)
- if ret is not None:
- return <Evas_Event_Flags>ret
- else:
- return EVAS_EVENT_FLAG_NONE
+ ret = callback(ei, *args, **kwargs)
+ return <Evas_Event_Flags>ret if ret is not None else
EVAS_EVENT_FLAG_NONE
+ except Exception as e:
+ traceback.print_exc()
+
+cdef Evas_Event_Flags _gesture_layer_momentum_event_cb(void *data, void
*event_info) with gil:
+ callback, args, kwargs = <object>data
+ cdef GestureMomentumInfo ei =
GestureMomentumInfo.__new__(GestureMomentumInfo)
+ ei.info = <Elm_Gesture_Momentum_Info *>event_info
+ try:
+ ret = callback(ei, *args, **kwargs)
+ return <Evas_Event_Flags>ret if ret is not None else
EVAS_EVENT_FLAG_NONE
+ except Exception as e:
+ traceback.print_exc()
+
+cdef Evas_Event_Flags _gesture_layer_line_event_cb(void *data, void
*event_info) with gil:
+ callback, args, kwargs = <object>data
+ cdef GestureLineInfo ei = GestureLineInfo.__new__(GestureLineInfo)
+ ei.info = <Elm_Gesture_Line_Info *>event_info
+ try:
+ ret = callback(ei, *args, **kwargs)
+ return <Evas_Event_Flags>ret if ret is not None else
EVAS_EVENT_FLAG_NONE
+ except Exception as e:
+ traceback.print_exc()
+
+cdef Evas_Event_Flags _gesture_layer_zoom_event_cb(void *data, void
*event_info) with gil:
+ callback, args, kwargs = <object>data
+ cdef GestureZoomInfo ei = GestureZoomInfo.__new__(GestureZoomInfo)
+ ei.info = <Elm_Gesture_Zoom_Info *>event_info
+ try:
+ ret = callback(ei, *args, **kwargs)
+ return <Evas_Event_Flags>ret if ret is not None else
EVAS_EVENT_FLAG_NONE
+ except Exception as e:
+ traceback.print_exc()
+
+cdef Evas_Event_Flags _gesture_layer_rotate_event_cb(void *data, void
*event_info) with gil:
+ callback, args, kwargs = <object>data
+ cdef GestureRotateInfo ei = GestureRotateInfo.__new__(GestureRotateInfo)
+ ei.info = <Elm_Gesture_Rotate_Info *>event_info
+ try:
+ ret = callback(ei, *args, **kwargs)
+ return <Evas_Event_Flags>ret if ret is not None else
EVAS_EVENT_FLAG_NONE
except Exception as e:
traceback.print_exc()
@@ -208,8 +526,8 @@ cdef class GestureLayer(Object):
"""
self._set_obj(elm_gesture_layer_add(parent.obj))
- def cb_set(self, Elm_Gesture_Type idx, callback, Elm_Gesture_State
cb_type, *args, **kwargs):
- """cb_set(Elm_Gesture_Type idx, callback, Elm_Gesture_State cb_type,
*args, **kwargs)
+ def cb_set(self, Elm_Gesture_Type idx, Elm_Gesture_State cb_type,
callback, *args, **kwargs):
+ """cb_set(Elm_Gesture_Type idx, Elm_Gesture_State cb_type, callback,
*args, **kwargs)
Use this function to set callbacks to be notified about change of
state of gesture. When a user registers a callback with this function
@@ -218,15 +536,19 @@ cdef class GestureLayer(Object):
When ALL callbacks for a gesture are set to None it means user isn't
interested in gesture-state and it will not be tested.
+ The signature for the callbacks is::
+
+ func(event_info, *args, **kwargs)
+
.. note:: You should return either EVAS_EVENT_FLAG_NONE or
EVAS_EVENT_FLAG_ON_HOLD from this callback.
:param idx: The gesture you would like to track its state.
- :type idx: Elm_Gesture_Type
+ :type idx: :ref:`Gesture type <Elm_Gesture_Type>`
+ :param cb_type: what event this callback tracks: START, MOVE, END,
ABORT.
+ :type cb_type: :ref:`Gesture state <Elm_Gesture_State>`
:param callback: Callback function.
:type callback: function
- :param cb_type: what event this callback tracks: START, MOVE, END,
ABORT.
- :type cb_type: Elm_Gesture_State
"""
cdef Elm_Gesture_Event_Cb cb = NULL
@@ -234,9 +556,26 @@ cdef class GestureLayer(Object):
if callback:
if not callable(callback):
raise TypeError("callback is not callable")
- cb = _gesture_layer_event_cb
+
+ if idx == enums.ELM_GESTURE_N_TAPS or \
+ idx == enums.ELM_GESTURE_N_LONG_TAPS or \
+ idx == enums.ELM_GESTURE_N_DOUBLE_TAPS or \
+ idx == enums.ELM_GESTURE_N_TRIPLE_TAPS:
+ cb = _gesture_layer_taps_event_cb
+ elif idx == enums.ELM_GESTURE_MOMENTUM:
+ cb = _gesture_layer_momentum_event_cb
+ elif idx == enums.ELM_GESTURE_N_LINES or \
+ idx == enums.ELM_GESTURE_N_FLICKS:
+ cb = _gesture_layer_line_event_cb
+ elif idx == enums.ELM_GESTURE_ZOOM:
+ cb = _gesture_layer_zoom_event_cb
+ elif idx == enums.ELM_GESTURE_ROTATE:
+ cb = _gesture_layer_rotate_event_cb
+ else:
+ raise TypeError("Unknown gesture type")
data = (callback, args, kwargs)
+ Py_INCREF(data)
elm_gesture_layer_cb_set( self.obj,
idx,
@@ -304,4 +643,148 @@ cdef class GestureLayer(Object):
return bool(elm_gesture_layer_attach(self.obj, target.obj))
+ property line_min_length:
+ """Gesture layer line min length of an object
+
+ :type: int
+ :since: 1.8
+
+ """
+ def __set__(self, int line_min_length):
+ elm_gesture_layer_line_min_length_set(self.obj, line_min_length)
+
+ def __get__(self):
+ return elm_gesture_layer_line_min_length_get(self.obj)
+
+ property zoom_distance_tolerance:
+ """Gesture layer zoom distance tolerance of an object
+
+ :type: int
+ :since: 1.8
+
+ """
+ def __set__(self, int zoom_distance_tolerance):
+ elm_gesture_layer_zoom_distance_tolerance_set(self.obj,
zoom_distance_tolerance)
+
+ def __get__(self):
+ return elm_gesture_layer_zoom_distance_tolerance_get(self.obj)
+
+ property line_distance_tolerance:
+ """Gesture layer line distance tolerance of an object
+
+ :type: int
+ :since: 1.8
+
+ """
+ def __set__(self, int line_distance_tolerance):
+ elm_gesture_layer_line_distance_tolerance_set(self.obj,
line_distance_tolerance)
+
+ def __get__(self):
+ return elm_gesture_layer_line_distance_tolerance_get(self.obj)
+
+ property line_angular_tolerance:
+ """Gesture layer line angular tolerance of an object
+
+ :since: 1.8
+ :type: double
+
+ """
+ def __set__(self, double line_angular_tolerance):
+ elm_gesture_layer_line_angular_tolerance_set(self.obj,
line_angular_tolerance)
+
+ def __get__(self):
+ return elm_gesture_layer_line_angular_tolerance_get(self.obj)
+
+ property zoom_wheel_factor:
+ """Gesture layer zoom wheel factor of an object
+
+ :type: double
+ :since: 1.8
+
+ """
+ def __set__(self, double zoom_wheel_factor):
+ elm_gesture_layer_zoom_wheel_factor_set(self.obj,
zoom_wheel_factor)
+
+ def __get__(self):
+ return elm_gesture_layer_zoom_wheel_factor_get(self.obj)
+
+ property zoom_finger_factor:
+ """Gesture layer zoom finger factor of an object
+
+ :type: double
+ :since: 1.8
+
+ """
+ def __set__(self, double zoom_finger_factor):
+ elm_gesture_layer_zoom_finger_factor_set(self.obj,
zoom_finger_factor)
+
+ def __get__(self):
+ return elm_gesture_layer_zoom_finger_factor_get(self.obj)
+
+ property rotate_angular_tolerance:
+ """Gesture layer rotate angular tolerance of an object
+
+ :type: double
+ :since: 1.8
+
+ """
+ def __set__(self, double rotate_angular_tolerance):
+ elm_gesture_layer_rotate_angular_tolerance_set(self.obj,
rotate_angular_tolerance)
+
+ def __get__(self):
+ return elm_gesture_layer_rotate_angular_tolerance_get(self.obj)
+
+ property flick_time_limit_ms:
+ """Gesture layer flick time limit (in ms) of an object
+
+ :type: int
+ :since: 1.8
+
+ """
+ def __set__(self, unsigned int flick_time_limit_ms):
+ elm_gesture_layer_flick_time_limit_ms_set(self.obj,
flick_time_limit_ms)
+
+ def __get__(self):
+ return elm_gesture_layer_flick_time_limit_ms_get(self.obj)
+
+ property long_tap_start_timeout:
+ """Gesture layer long tap start timeout of an object
+
+ :type: double
+ :since: 1.8
+
+ """
+ def __set__(self, double long_tap_start_timeout):
+ elm_gesture_layer_long_tap_start_timeout_set(self.obj,
long_tap_start_timeout)
+
+ def __get__(self):
+ return elm_gesture_layer_long_tap_start_timeout_get(self.obj)
+
+ property continues_enable:
+ """Gesture layer continues enable of an object
+
+ :type: bool
+ :since: 1.8
+
+ """
+ def __set__(self, continues_enable):
+ elm_gesture_layer_continues_enable_set(self.obj, continues_enable)
+
+ def __get__(self):
+ return bool(elm_gesture_layer_continues_enable_get(self.obj))
+
+ property double_tap_timeout:
+ """Gesture layer double tap timeout of an object
+
+ :type: double
+ :since: 1.8
+
+ """
+ def __set__(self, double double_tap_timeout):
+ elm_gesture_layer_double_tap_timeout_set(self.obj,
double_tap_timeout)
+
+ def __get__(self):
+ return elm_gesture_layer_double_tap_timeout_get(self.obj)
+
+
_object_mapping_register("elm_gesture_layer", GestureLayer)
diff --git a/examples/elementary/images/pol_shadow.png
b/examples/elementary/images/pol_shadow.png
new file mode 100644
index 0000000..9038699
Binary files /dev/null and b/examples/elementary/images/pol_shadow.png differ
diff --git a/examples/elementary/images/pol_sky.png
b/examples/elementary/images/pol_sky.png
new file mode 100644
index 0000000..99251c7
Binary files /dev/null and b/examples/elementary/images/pol_sky.png differ
diff --git a/examples/elementary/images/pol_twofish.png
b/examples/elementary/images/pol_twofish.png
new file mode 100644
index 0000000..2520ba0
Binary files /dev/null and b/examples/elementary/images/pol_twofish.png differ
diff --git a/examples/elementary/postit_ent.edc
b/examples/elementary/postit_ent.edc
new file mode 100644
index 0000000..9968907
--- /dev/null
+++ b/examples/elementary/postit_ent.edc
@@ -0,0 +1,26 @@
+collections {
+ group {
+ name: "main";
+ images {
+// image: "1.png" COMP;
+ }
+ parts {
+ part {
+ name: "bg";
+ type: RECT;
+ description {
+ state: "default" 0.0;
+ color: 247 239 132 255;
+ }
+ }
+ part {
+ name: "ent";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ }
+ }
+ }
+ }
+}
+
diff --git a/examples/elementary/postit_ent.edj
b/examples/elementary/postit_ent.edj
new file mode 100644
index 0000000..1ed9061
Binary files /dev/null and b/examples/elementary/postit_ent.edj differ
diff --git a/examples/elementary/test_gesture_layer.py
b/examples/elementary/test_gesture_layer.py
new file mode 100644
index 0000000..4f5d0cd
--- /dev/null
+++ b/examples/elementary/test_gesture_layer.py
@@ -0,0 +1,331 @@
+from efl import elementary
+from efl import evas
+
+from efl.elementary.window import Window, ELM_WIN_BASIC
+from efl.elementary.transit import Transit
+from efl.elementary.gesture_layer import GestureLayer, ELM_GESTURE_ZOOM, \
+ ELM_GESTURE_MOMENTUM, ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE, \
+ ELM_GESTURE_STATE_END, ELM_GESTURE_STATE_ABORT, ELM_GESTURE_STATE_START
+from efl.elementary.background import Background
+from efl.elementary.layout import Layout
+from efl.elementary.entry import Entry, ELM_WRAP_MIXED
+from efl.elementary.icon import Icon
+
+from efl.evas import Map, EVAS_HINT_EXPAND, EVAS_EVENT_FLAG_NONE
+
+#We zoom out to this value so we'll be able to use map and have a nice
+#resolution when zooming in.
+BASE_ZOOM = 0.5
+#The amount of zoom to do when "lifting" objects.
+LIFT_FACTOR = 1.3
+#The base size of the shadow image.
+SHADOW_W = 118
+SHADOW_H = 118
+
+zoom_out_animation_duration = 0.4
+
+class Photo_Object(object):
+ ic = None
+ shadow = None
+ hit = None
+ gl = None
+ zoom_out = None
+ # bx, by - current wanted coordinates of the photo object.
+ # bw, bh - original size of the "ic" object.
+ # dx, dy - Used to indicate the distance between the center point
+ # where we put down our fingers (when started moving the item) to
+ # the coords of the object, so we'll be able to calculate movement
+ # correctly.
+ bx, by, bw, bh, dx, dy = None, None, None, None, None, None
+ # Because gesture layer only knows the amount of rotation/zoom we do
+ # per gesture, we have to keep the current rotate/zoom factor and the
+ # one that was before we started the gesture.
+ base_rotate, rotate = None, None
+ base_zoom, zoom = None, None
+ shadow_zoom = None
+
+def apply_changes(po):
+ """
+ This function applies the information from the Photo_Object to the actual
+ evas objects. Zoom/rotate factors and etc.
+ """
+
+ map = evas.Map(4)
+ map.point_coord_set(0, po.bx, po.by, 0)
+ map.point_coord_set(1, po.bx + po.bw, po.by, 0)
+ map.point_coord_set(2, po.bx + po.bw, po.by + po.bh, 0)
+ map.point_coord_set(3, po.bx, po.by + po.bh, 0)
+ map.point_image_uv_set(0, 0, 0)
+ map.point_image_uv_set(1, po.bw, 0)
+ map.point_image_uv_set(2, po.bw, po.bh)
+ map.point_image_uv_set(3, 0, po.bh)
+ map.util_rotate(po.rotate, po.bx + po.bw / 2, po.by + po.bh /2)
+ map.util_zoom(po.zoom, po.zoom, po.bx + po.bw / 2, po.by + po.bh /2)
+ po.ic.map_enabled = True
+ po.ic.map = map
+
+ shadow_map = Map(4)
+ shadow_map.point_coord_set(0, po.bx, po.by, 0)
+ shadow_map.point_coord_set(1, po.bx + po.bw, po.by, 0)
+ shadow_map.point_coord_set(2, po.bx + po.bw, po.by + po.bh, 0)
+ shadow_map.point_coord_set(3, po.bx, po.by + po.bh, 0)
+ shadow_map.point_image_uv_set(0, 0, 0)
+ shadow_map.point_image_uv_set(1, SHADOW_W, 0)
+ shadow_map.point_image_uv_set(2, SHADOW_W, SHADOW_H)
+ shadow_map.point_image_uv_set(3, 0, SHADOW_H)
+ shadow_map.util_rotate(po.rotate, po.bx + po.bw / 2, po.by + po.bh /2)
+ shadow_map.util_zoom(po.zoom * po.shadow_zoom,
+ po.zoom * po.shadow_zoom,
+ po.bx + (po.bw / 2), po.by + (po.bh / 2))
+ po.shadow.map_enabled = True
+ po.shadow.map = shadow_map
+ #evas_map_free(shadow_map);
+
+ # Update the position of the hit box
+ po.hit.points_clear()
+ minx, miny, minz = map.point_coord_get(0)
+ maxx = minx
+ maxy = miny
+ po.hit.point_add(minx, miny)
+ for i in range(1, 3):
+ x, y, z = map.point_coord_get(i)
+ po.hit.point_add(x, y)
+ if x < minx:
+ minx = x
+ elif x > maxx:
+ maxx = x
+
+ if y < miny:
+ miny = y
+ elif y > maxy:
+ maxy = y
+
+ po.shadow.raise_()
+ po.ic.raise_()
+ po.hit.raise_()
+ #evas_map_free(map);
+
+def zoom_out_animation_operation(transit, *args, **kwargs):
+ """Zoom out animation"""
+ po, progress = args
+ po.zoom = BASE_ZOOM + ((po.base_zoom - BASE_ZOOM) * (1.0 - progress))
+ apply_changes(po)
+
+def zoom_out_animation_end(transit, *args, **kwargs):
+ po = args[0]
+
+ po.base_zoom = po.zoom = BASE_ZOOM
+ apply_changes(po)
+
+ po.zoom_out = None
+
+def rotate_move(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("rotate move <%d,%d> base=<%f> <%f>" % (p.x, p.y, p.base_angle,
p.angle))
+ po.rotate = po.base_rotate + p.angle - p.base_angle
+ if po.rotate < 0:
+ po.rotate += 360
+ apply_changes(po)
+ return EVAS_EVENT_FLAG_NONE
+
+def rotate_end(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("rotate end/abort <%d,%d> base=<%f> <%f>" % (p.x, p.y, p.base_angle,
p.angle))
+ po.base_rotate += p.angle - p.base_angle
+ if po.rotate < 0:
+ po.rotate += 360
+ return EVAS_EVENT_FLAG_NONE
+
+def zoom_start(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("zoom start <%d,%d> <%f>" % (p.x, p.y, p.zoom))
+
+ # If there's an active animator, stop it
+ if po.zoom_out:
+ elm_transit_del(po.zoom_out)
+ po.zoom_out = None
+
+ # Give it a "lift" effect right from the start
+ po.base_zoom = BASE_ZOOM * LIFT_FACTOR
+ po.zoom = po.base_zoom
+ po.shadow_zoom = 1.7
+
+ apply_changes(po)
+ return EVAS_EVENT_FLAG_NONE
+
+def zoom_move(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("zoom move <%d,%d> <%f>" % (p.x, p.y, p.zoom))
+ po.zoom = po.base_zoom * p.zoom
+ apply_changes(po);
+ return EVAS_EVENT_FLAG_NONE
+
+def zoom_end(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("zoom end/abort <%d,%d> <%f>" % (p.x, p.y, p.zoom))
+
+ # Apply the zoom out animator
+ po.shadow_zoom = 1.3
+ po.base_zoom = po.zoom
+ po.zoom_out = Transit()
+ po.zoom_out.duration = zoom_out_animation_duration
+ po.zoom_out.effect_add(zoom_out_animation_operation, po,
zoom_out_animation_end)
+ po.zoom_out.go()
+ return EVAS_EVENT_FLAG_NONE
+
+def momentum_start(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("momentum_start <%d,%d>" % (p.x2, p.y2))
+
+ po.dx = p.x2 - po.bx
+ po.dy = p.y2 - po.by
+ apply_changes(po)
+
+ return EVAS_EVENT_FLAG_NONE
+
+def momentum_move(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("momentum move <%d,%d>" % (p.x2, p.y2))
+
+ po.bx = p.x2 - po.dx
+ po.by = p.y2 - po.dy
+ apply_changes(po)
+
+ return EVAS_EVENT_FLAG_NONE
+
+def momentum_end(event_info, *args, **kwargs):
+ po = args[0]
+ p = event_info
+
+ print("momentum end/abort <%d,%d> <%d,%d>" % (p.x2, p.y2, p.mx, p.my))
+ #(void) po;
+ #(void) p;
+
+ # Make sure middle is in the screen, if not, fix it.
+ # FIXME: Use actual window sizes instead of the hardcoded
+ # values
+ mx = po.bx + (po.bw / 2)
+ my = po.by + (po.bh / 2)
+ if mx < 0:
+ po.bx = 0 - (po.bw / 2)
+ elif mx > 480:
+ po.bx = 480 - (po.bw / 2)
+
+ if my < 0:
+ po.by = 0 - (po.bw / 2)
+ elif my > 800:
+ po.by = 800 - (po.bh / 2)
+
+ apply_changes(po)
+
+ return EVAS_EVENT_FLAG_NONE
+
+def photo_object_add(parent, ic, icon, x, y, w, h, angle):
+ po = Photo_Object()
+ po.base_zoom = po.zoom = BASE_ZOOM
+
+ if ic:
+ po.ic = ic
+ else:
+ po.ic = Icon(parent)
+ po.ic.file = icon
+
+ po.bx = x
+ po.by = y
+ po.bw = w
+ po.bh = h
+
+ # Add shadow
+ po.shadow = Icon(po.ic)
+ po.shadow.file = "images/pol_shadow.png"
+ po.shadow.size = SHADOW_W, SHADOW_H
+ po.shadow.show()
+
+ po.hit = evas.Polygon(parent.evas)
+ po.hit.precise_is_inside = True
+ po.hit.repeat_events = True
+ po.hit.color = 0, 0, 0, 0
+
+ po.ic.pos = 0, 0
+ po.ic.size = po.bw, po.bh
+ po.ic.show()
+
+ po.hit.show()
+
+ po.gl = GestureLayer(po.ic)
+ po.gl.hold_events = True
+ po.gl.attach(po.hit)
+
+ # FIXME: Add a po.rotate start so we take the first angle!!!!
+ po.gl.cb_set(ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_MOVE, rotate_move, po)
+ po.gl.cb_set(ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_END, rotate_end, po)
+ po.gl.cb_set(ELM_GESTURE_ROTATE, ELM_GESTURE_STATE_ABORT, rotate_end, po)
+ po.gl.cb_set(ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START, zoom_start, po)
+ po.gl.cb_set(ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE, zoom_move, po)
+ po.gl.cb_set(ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_END, zoom_end, po)
+ po.gl.cb_set(ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_ABORT, zoom_end, po)
+ po.gl.cb_set(ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_START,
momentum_start, po)
+ po.gl.cb_set(ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_MOVE, momentum_move,
po)
+ po.gl.cb_set(ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_END, momentum_end, po)
+ po.gl.cb_set(ELM_GESTURE_MOMENTUM, ELM_GESTURE_STATE_ABORT, momentum_end,
po)
+
+ po.rotate = po.base_rotate = angle
+ po.shadow_zoom = 1.3
+
+ apply_changes(po)
+ return po
+
+def gesture_layer_clicked(obj):
+ w = 480
+ h = 800
+
+ win = Window("gesture-layer", ELM_WIN_BASIC)
+ win.title = "Gesture Layer"
+ win.autodel = True
+ win.size = w, h
+
+ bg = Background(win)
+ bg.file = "images/wood_01.jpg"
+ bg.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
+ win.resize_object_add(bg)
+ bg.show()
+
+ photos = []
+
+ photos.append(photo_object_add(win, None, "images/pol_sky.png", 200, 200,
365, 400, 0))
+ photos.append(photo_object_add(win, None, "images/pol_twofish.png", 40,
300, 365, 400, 45))
+
+ en = Entry(win)
+ en.text = "You can use whatever object you want, even entries like this."
+ en.line_wrap = ELM_WRAP_MIXED
+
+ postit = Layout(win)
+ postit.file = "postit_ent.edj", "main"
+ postit.part_content_set("ent", en)
+
+ photos.append(photo_object_add(win, postit, None, 50, 50, 382, 400, 355))
+
+ win.callback_delete_request_add(lambda o: elementary.exit())
+ win.show()
+
+if __name__ == "__main__":
+ elementary.init()
+
+ gesture_layer_clicked(None)
+
+ elementary.run()
+ elementary.shutdown()
--
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter