]> Creatis software - cpPlugins.git/commitdiff
double click example updates
authorjose guzman <jose@gmail.com>
Fri, 2 Oct 2015 08:18:35 +0000 (10:18 +0200)
committerjose guzman <jose@gmail.com>
Fri, 2 Oct 2015 08:18:35 +0000 (10:18 +0200)
appli/examples/example_Test_DoubleClick.cxx

index bf357d2252b0a2417d254a2507e35208a9fa3d80..db795e508cfd05583fb3642afc73e4967e7cd208 100644 (file)
 #else
 #endif
 
+#if __cplusplus > 199711L
+#include <chrono>
+#endif
+
 // Define interaction style
 class MouseInteractorStyleDoubleClick : public vtkInteractorStyleTrackballCamera
 {
@@ -43,10 +47,25 @@ public:
                if (this->NumberOfClicks > 1)
                {
                        this->LastClickTime = this->CurrentClickTime;
-                       this->CurrentClickTime = time(0);
-               } else
+#if __cplusplus <= 199711L
+                       this->CurrentClickTime = time(0) * 1000;
+#else
+                       this->CurrentClickTime = std::chrono::duration_cast<std::chrono::milliseconds>(
+                               std::chrono::system_clock::now().time_since_epoch()
+                               );
+#endif
+
+               }
+               else
                {
-                       this->CurrentClickTime = time(0);
+#if __cplusplus <= 199711L
+                       this->CurrentClickTime = time(0) * 1000;
+#else
+                       this->CurrentClickTime = std::chrono::duration_cast<std::chrono::milliseconds>(
+                               std::chrono::system_clock::now().time_since_epoch()
+                               );
+
+#endif
                }
 
                //std::cout << "NumberOfClicks = " << this->NumberOfClicks << std::endl;
@@ -70,29 +89,43 @@ public:
 
                if (this->NumberOfClicks == 2)
                {
-                       double  seconds = difftime(this->CurrentClickTime, this->LastClickTime);
-                       if (seconds * 1000 <= this->DoubleClickTolerance)
+                       double  seconds;
+#if __cplusplus <= 199711L
+                       seconds = difftime(this->CurrentClickTime, this->LastClickTime);
+#else
+                       seconds = this->CurrentClickTime - this->LastClickTime;
+#endif
+                       
+                       if (seconds <= this->DoubleClickTolerance)
                        {
                                std::cout << "Double clicked. with " << seconds << " of diference" << std::endl;
                                this->NumberOfClicks = 0;
-                       } else
+                       }
+                       else
                        {
                                std::cout << "Too slow to be considered as a double click" << std::endl;
                                this->NumberOfClicks = 1;
-                       }                       
-                       
+                       }
                }
                // forward events
                vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
        }
 
+
+
 private:
        unsigned int NumberOfClicks;
        int PreviousPosition[2];
        int ResetPixelDistance;
        double DoubleClickTolerance; // time in miliseconds
+
+#if __cplusplus <= 199711L     
        time_t LastClickTime;
        time_t CurrentClickTime;
+#else
+       std::chrono::milliseconds LastClickTime;
+       std::chrono::milliseconds CurrentClickTime;
+#endif
 };
 vtkStandardNewMacro(MouseInteractorStyleDoubleClick);