From: Leonardo Florez-Valencia Date: Wed, 7 Oct 2015 03:02:22 +0000 (-0500) Subject: Double-click dominated... It does not compile yet though X-Git-Tag: v0.1~344^2~1 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=58cd905dfd2cb77ebaef6857ca558dad4df02093;p=cpPlugins.git Double-click dominated... It does not compile yet though --- diff --git a/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx b/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx index bf395a8..8eb3fee 100644 --- a/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx +++ b/lib/cpExtensions/Visualization/BaseInteractorStyle.cxx @@ -1,23 +1,21 @@ #include -/* - 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 - #include // ------------------------------------------------------------------------- -/* - 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; diff --git a/lib/cpExtensions/Visualization/BaseInteractorStyle.h b/lib/cpExtensions/Visualization/BaseInteractorStyle.h index 849e386..f10a9bb 100644 --- a/lib/cpExtensions/Visualization/BaseInteractorStyle.h +++ b/lib/cpExtensions/Visualization/BaseInteractorStyle.h @@ -103,6 +103,7 @@ namespace cpExtensions Self& operator=( const Self& ); protected: + static const long MAX_DOUBLE_CLICK; ButtonID LastButton; long LastButtonUp; long LastButtonHeld;