]> Creatis software - cpPlugins.git/commitdiff
Double-click dominated... It does not compile yet though
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 7 Oct 2015 03:02:22 +0000 (22:02 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 7 Oct 2015 03:02:22 +0000 (22:02 -0500)
lib/cpExtensions/Visualization/BaseInteractorStyle.cxx
lib/cpExtensions/Visualization/BaseInteractorStyle.h

index bf395a8856e728b5815f322bd1922f3c2dcee6fa..8eb3feed603cf5221df395c461cf5fcc3690389b 100644 (file)
@@ -1,23 +1,21 @@
 #include <cpExtensions/Visualization/BaseInteractorStyle.h>
 
-/*
-  Compile ITK and VTK with: cmake -DCMAKE_CXX_FLAGS="-std=c++11" /dir/to/source
+/* =========================================================================
+ * Double click algorithm taken from:
+ * http://www.autohotkey.com/board/topic/56493-easiest-way-to-detect-double-clicks/
+ * =========================================================================
 */
+
 /*
-  typedef std::chrono::time_point< std::chrono::system_clock > TTime;
-  typedef std::chrono::duration< long, std::ratio< 1, 1000 > > TTimeDiff;
+  Compile ITK and VTK with: cmake -DCMAKE_CXX_FLAGS="-std=c++11" /dir/to/source
 */
 
 #include <chrono>
-
 #include <vtkCallbackCommand.h>
 
 // -------------------------------------------------------------------------
-/*
-  const cpExtensions::Visualization::BaseInteractorStyle::TTime
-  cpExtensions::Visualization::BaseInteractorStyle::MinTime =
-  cpExtensions::Visualization::BaseInteractorStyle::TTime::min( );
-*/
+const long cpExtensions::Visualization::BaseInteractorStyle::
+MAX_DOUBLE_CLICK = 200;
 
 // -------------------------------------------------------------------------
 cpExtensions::Visualization::BaseInteractorStyle::
@@ -79,39 +77,58 @@ _ProcessEvents(
   break;
   case vtkCommand::LeftButtonPressEvent:
   {
-    /*
-    if( s->LastButton != Self::ButtonID_Left )
+    long tick_count =
+      std::chrono::duration_cast< std::chrono::milliseconds >(
+        std::chrono::system_clock::now( ).time_since_epoch( )
+        ).count( );
+    if(
+      s->LastButtonHeld < Self::MAX_DOUBLE_CLICK &&
+      ( tick_count - s->LastButtonUp ) < Self::MAX_DOUBLE_CLICK
+      )
+    {
+      std::cout << "double!!!" << std::endl;
+    }
+    else
     {
+      std::cout << "single!!!" << std::endl;
+
+    } // fi
+    if( s->LastButtonDown < 0 )
+      s->LastButtonDown = tick_count;
+
+    /*
+      if( s->LastButton != Self::ButtonID_Left )
+      {
       s->LastButton = Self::ButtonID_Left;
       s->LastButtonClicks = 1;
       s->LastButtonTime = std::chrono::system_clock::now( );
-    }
-    else if( s->LastButton == Self::ButtonID_Left )
+      }
+      else if( s->LastButton == Self::ButtonID_Left )
       s->LastButtonClicks++;
     */
   }
   break;
   case vtkCommand::LeftButtonReleaseEvent:
   {
-    long count =
+    long tick_count =
       std::chrono::duration_cast< std::chrono::milliseconds >(
-        std::chrono::system_clock::now( )
+        std::chrono::system_clock::now( ).time_since_epoch( )
         ).count( );
-    s->LastButtonUp = count;
-    s->LastButtonHeld = count - s->LastButtonDown;
+    s->LastButtonUp = tick_count;
+    s->LastButtonHeld = tick_count - s->LastButtonDown;
     s->LastButtonDown = -1;
 
     /*
-    if( s->LastButton == Self::ButtonID_Left )
-    {
+      if( s->LastButton == Self::ButtonID_Left )
+      {
       long d = std::chrono::duration_cast< std::chrono::milliseconds >(
-        std::chrono::system_clock::now( ) - s->LastButtonTime
-        ).count( );
+      std::chrono::system_clock::now( ) - s->LastButtonTime
+      ).count( );
       if( d < 500 )
       {
       } // fi
 
-    } // fi
+      } // fi
     */
   }
   break;
index 849e386d44ea062176f48ed53dda334112657728..f10a9bb493f1a48fae532d2d7a6470028cb2a72a 100644 (file)
@@ -103,6 +103,7 @@ namespace cpExtensions
       Self& operator=( const Self& );
 
     protected:
+      static const long MAX_DOUBLE_CLICK;
       ButtonID LastButton;
       long LastButtonUp;
       long LastButtonHeld;