Add Touch source type for gesture
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-recognizer.h
index f76326d..0bc013d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_GESTURE_RECOGNIZER_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // EXTERNAL INCLUDES
+#include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/internal/event/events/gesture-event.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/events/gesture.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/object/ref-object.h>
-#include <dali/internal/event/events/gesture-event.h>
 
 namespace Dali
 {
-
 namespace Integration
 {
 struct TouchEvent;
@@ -38,16 +38,16 @@ namespace Internal
 struct GestureRequest;
 class Scene;
 
-template< typename T>
+template<typename T>
 class RecognizerObserver
 {
 public:
-  virtual void Process( Scene& scene, const T& event ) = 0;
+  virtual void Process(Scene& scene, const T& event) = 0;
 
-  virtual ~RecognizerObserver(){};
+  virtual ~RecognizerObserver() = default;
+  ;
 };
 
-
 /**
  * Abstract Base class for all adaptor gesture detectors.
  *
@@ -56,7 +56,6 @@ public:
 class GestureRecognizer : public RefObject
 {
 public:
-
   /**
    * Called when it gets a touch event.  The gesture recognizer should
    * evaluate this event along with previously received events to determine
@@ -75,30 +74,74 @@ public:
    * Returns the type of gesture detector.
    * @return Type of gesture detector.
    */
-  GestureType::Value GetType() const { return mType; }
+  GestureType::Value GetType() const
+  {
+    return mType;
+  }
 
   /**
    * Called when we get a touch event.
    * @param[in]  scene  The scene the touch event has occurred on
    * @param[in]  event  The latest touch event
    */
-  void SendEvent( Scene& scene, const Integration::TouchEvent& event )
+  void SendEvent(Scene& scene, const Integration::TouchEvent& event)
   {
     mScene = &scene;
-    SendEvent( event );
+    if(event.GetPointCount() > 0)
+    {
+      const Integration::Point& point       = event.points[0];
+      MouseButton::Type         mouseButton = point.GetMouseButton();
+      if(mouseButton != MouseButton::INVALID)
+      {
+        Device::Class::Type type = point.GetDeviceClass();
+        if(type == Device::Class::Type::MOUSE)
+        {
+          mSourceType = GestureSourceType::MOUSE;
+        }
+        else if(type == Device::Class::Type::TOUCH)
+        {
+          mSourceType = GestureSourceType::TOUCH;
+        }
+        switch(mouseButton)
+        {
+          case MouseButton::PRIMARY:
+          {
+            mSourceData = GestureSourceData::MOUSE_PRIMARY;
+            break;
+          }
+          case MouseButton::SECONDARY:
+          {
+            mSourceData = GestureSourceData::MOUSE_SECONDARY;
+            break;
+          }
+          case MouseButton::TERTIARY:
+          {
+            mSourceData = GestureSourceData::MOUSE_TERTIARY;
+            break;
+          }
+          default:
+          {
+            mSourceData = GestureSourceData::INVALID;
+            break;
+          }
+        }
+      }
+    }
+    SendEvent(event);
   }
 
 protected:
-
   /**
    * Protected Constructor. Should only be able to create derived class objects.
    * @param[in]  screenSize    The size of the screen.
    * @param[in]  detectorType  The type of gesture detector.
    */
-  GestureRecognizer( Vector2 screenSize, GestureType::Value detectorType )
-  : mScreenSize( screenSize ),
-    mType( detectorType ),
-    mScene( nullptr )
+  GestureRecognizer(Vector2 screenSize, GestureType::Value detectorType)
+  : mScreenSize(screenSize),
+    mType(detectorType),
+    mScene(nullptr),
+    mSourceType(GestureSourceType::INVALID),
+    mSourceData(GestureSourceData::INVALID)
   {
   }
 
@@ -108,23 +151,25 @@ protected:
    * Use this constructor with the screen size is not used in the dereived class.
    * @param[in]  detectorType  The type of gesture detector.
    */
-  GestureRecognizer( GestureType::Value detectorType )
-  : GestureRecognizer( Vector2::ZERO, detectorType )
+  GestureRecognizer(GestureType::Value detectorType)
+  : GestureRecognizer(Vector2::ZERO, detectorType)
   {
   }
 
   /**
    * Virtual destructor.
    */
-  virtual ~GestureRecognizer() {}
+  ~GestureRecognizer() override = default;
 
 protected:
-  Vector2 mScreenSize;
+  Vector2            mScreenSize;
   GestureType::Value mType;
-  Scene* mScene;
+  Scene*             mScene;
+  GestureSourceType  mSourceType; /// < Gesture input source type.
+  GestureSourceData  mSourceData; /// < Gesture input source data.
 };
 
-typedef IntrusivePtr<GestureRecognizer> GestureRecognizerPtr;
+using GestureRecognizerPtr = IntrusivePtr<GestureRecognizer>;
 
 } // namespace Internal