evas: add some functions for determining if pointer coords are inside an object
authorMike Blumenkrantz <zmike@osg.samsung.com>
Sat, 10 Jun 2017 00:16:08 +0000 (20:16 -0400)
committerMike Blumenkrantz <zmike@osg.samsung.com>
Fri, 9 Jun 2017 23:14:59 +0000 (19:14 -0400)
@feature

src/lib/evas/canvas/efl_canvas_object.eo
src/lib/evas/canvas/evas_object_main.c

index 2c8b8c2..a284a43 100644 (file)
@@ -606,6 +606,56 @@ abstract Efl.Canvas.Object (Efl.Object, Efl.Gfx, Efl.Gfx.Stack, Efl.Animator,
             enable: bool; [[Enable "no-render" mode.]]
          }
       }
+      @property pointer_inside_by_device {
+         [[Returns whether the mouse pointer is logically inside the
+           object. @since 1.20]]
+         keys {
+            dev: Efl.Input.Device; [[The pointer device.]]
+         }
+         get {}
+         values {
+            in: bool; [[$true if the pointer is inside, $false otherwise.]]
+         }
+      }
+      @property pointer_inside {
+         get {
+            [[Returns whether the default mouse pointer is logically inside the
+              object.
+
+              When this function is called it will return a value of either
+              $false or $true, depending on if event_feed_mouse_in or
+              event_feed_mouse_out have been called to feed in a mouse
+              enter event into the object.
+
+              A return value of $true indicates the mouse is logically
+              inside the object, and $false implies it is logically
+              outside the object.
+
+              If $e is not a valid object, the return value is undefined.
+            ]]
+            return: bool @warn_unused; [[$true if the mouse pointer is inside the object, $false otherwise]]
+         }
+      }
+      pointer_coords_inside_get {
+         [[Returns whether the coords are logically inside the
+           object.
+
+           When this function is called it will return a value of either
+           $false or $true, depending on if the coords are inside the object's
+           current geometry.
+
+           A return value of $true indicates the position is logically
+           inside the object, and $false implies it is logically
+           outside the object.
+
+           If $e is not a valid object, the return value is undefined.
+         ]]
+         params {
+            @in x: int; [[The canvas-relative x coordinate.]]
+            @in y: int; [[The canvas-relative y coordinate.]]
+         }
+         return: bool @warn_unused; [[$true if the coords are inside the object, $false otherwise]]
+      }
    }
    implements {
       Efl.Object.constructor;
index 48b4efe..da13fb1 100644 (file)
@@ -2370,6 +2370,46 @@ _efl_canvas_object_precise_is_inside_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Pro
    return obj->precise_is_inside;
 }
 
+EOLIAN static Eina_Bool
+_efl_canvas_object_pointer_inside_by_device_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj, Efl_Input_Device *dev)
+{
+   Evas_Pointer_Data *pdata;
+   Evas_Object_Pointer_Data *obj_pdata;
+
+   if (!obj->layer) return EINA_FALSE;
+   pdata = _evas_pointer_data_by_device_get(obj->layer->evas, dev);
+   if (!pdata) return EINA_FALSE;
+   obj_pdata = _evas_object_pointer_data_get(pdata, obj);
+   return obj_pdata ? obj_pdata->mouse_in : EINA_FALSE;
+}
+
+EOLIAN static Eina_Bool
+_efl_canvas_object_pointer_coords_inside_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj, Evas_Coord x, Evas_Coord y)
+{
+   Evas_Coord_Rectangle c;
+
+   if (obj->is_smart)
+     {
+        Evas_Coord_Rectangle bounding_box = { 0, 0, 0, 0 };
+
+        evas_object_smart_bounding_box_update(obj);
+        evas_object_smart_bounding_box_get(obj, &bounding_box, NULL);
+        c = bounding_box;
+     }
+   else
+     {
+        if (obj->clip.clipees) return EINA_FALSE;
+        c = obj->cur->geometry;
+     }
+   return RECTS_INTERSECT(x, y, 1, 1, c.x, c.y, c.w, c.h);
+}
+
+EOLIAN static Eina_Bool
+_efl_canvas_object_pointer_inside_get(Eo *eo_obj, Evas_Object_Protected_Data *obj)
+{
+   return _efl_canvas_object_pointer_inside_by_device_get(eo_obj, obj, NULL);
+}
+
 static void
 _is_frame_flag_set(Evas_Object_Protected_Data *obj, Eina_Bool is_frame)
 {