diff Framework/Viewport/WidgetViewport.cpp @ 457:3b4df9925db6 am-touch-events

added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
author Alain Mazy <alain@mazy.be>
date Thu, 24 Jan 2019 16:42:27 +0100
parents b70e9be013e4
children 1201b12eb9f8
line wrap: on
line diff
--- a/Framework/Viewport/WidgetViewport.cpp	Wed Jan 23 13:58:51 2019 +0100
+++ b/Framework/Viewport/WidgetViewport.cpp	Thu Jan 24 16:42:27 2019 +0100
@@ -137,18 +137,36 @@
     return true;
   }
 
+  void WidgetViewport::TouchStart(const std::vector<Touch>& displayTouches)
+  {
+    MouseDown(MouseButton_Left, (int)displayTouches[0].x, (int)displayTouches[0].y, KeyboardModifiers_None, displayTouches); // one touch is equivalent to a mouse tracker without left button -> set the mouse coordinates to the first touch coordinates
+  }
+      
+  void WidgetViewport::TouchMove(const std::vector<Touch>& displayTouches)
+  {
+    MouseMove((int)displayTouches[0].x, (int)displayTouches[0].y, displayTouches); // one touch is equivalent to a mouse tracker without left button -> set the mouse coordinates to the first touch coordinates
+  }
+      
+  void WidgetViewport::TouchEnd(const std::vector<Touch>& displayTouches)
+  {
+    // note: TouchEnd is not triggered when a single touch gesture ends (it is only triggered when
+    // going from 2 touches to 1 touch, ...)
+    MouseUp();
+  }
 
   void WidgetViewport::MouseDown(MouseButton button,
                                  int x,
                                  int y,
-                                 KeyboardModifiers modifiers)
+                                 KeyboardModifiers modifiers,
+                                 const std::vector<Touch>& displayTouches
+                                 )
   {
     lastMouseX_ = x;
     lastMouseY_ = y;
 
     if (centralWidget_.get() != NULL)
     {
-      mouseTracker_.reset(centralWidget_->CreateMouseTracker(button, x, y, modifiers));
+      mouseTracker_.reset(centralWidget_->CreateMouseTracker(button, x, y, modifiers, displayTouches));
     }
     else
     {
@@ -171,7 +189,8 @@
 
 
   void WidgetViewport::MouseMove(int x, 
-                                 int y) 
+                                 int y,
+                                 const std::vector<Touch>& displayTouches)
   {
     if (centralWidget_.get() == NULL)
     {
@@ -185,7 +204,7 @@
     
     if (mouseTracker_.get() != NULL)
     {
-      mouseTracker_->MouseMove(x, y);
+      mouseTracker_->MouseMove(x, y, displayTouches);
       repaint = true;
     }
     else