X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fexamples%2Fexample_Test_DoubleClick.cxx;h=db795e508cfd05583fb3642afc73e4967e7cd208;hb=ef8b6e12859181d3faa8019ce7319c539c0f86ec;hp=bf357d2252b0a2417d254a2507e35208a9fa3d80;hpb=37bb879eecf9a8ce60f5cc71fb5aeb5878c1d645;p=cpPlugins.git 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);