From: jose guzman Date: Fri, 2 Oct 2015 08:18:35 +0000 (+0200) Subject: double click example updates X-Git-Tag: v0.1~356 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=defc13fb606caed80a67ebddadcb72f5dfbc9c53;p=cpPlugins.git double click example updates --- diff --git a/appli/examples/example_Test_DoubleClick.cxx b/appli/examples/example_Test_DoubleClick.cxx index bf357d2..db795e5 100644 --- a/appli/examples/example_Test_DoubleClick.cxx +++ b/appli/examples/example_Test_DoubleClick.cxx @@ -15,6 +15,10 @@ #else #endif +#if __cplusplus > 199711L +#include +#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::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::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);