1 #ifndef __CPEXTENSIONS__INTERACTION__BASEINTERACTORSTYLE__H__
2 #define __CPEXTENSIONS__INTERACTION__BASEINTERACTORSTYLE__H__
4 #include <cpExtensions/cpExtensions_Export.h>
10 #include <vtkInteractorStyle.h>
12 /* =========================================================================
13 * Double click algorithm inspired from:
14 * http://www.autohotkey.com/board/topic/56493-easiest-way-to-detect-double-clicks/
15 * =========================================================================
18 // -------------------------------------------------------------------------
19 #define cpExtensions_BaseInteractorStyle_Commands( C ) \
21 std::map< T##C##Command, void* > m_##C##Commands; \
23 inline void Add##C##Command( T##C##Command c, void* d ) \
27 this->m_##C##Commands[ c ] = d; \
31 inline void Remove##C##Command( T##C##Command c ) \
33 std::map< T##C##Command, void* >::iterator i = \
34 this->m_##C##Commands.find( c ); \
35 if( i != this->m_##C##Commands.end( ) ) \
37 this->m_##C##Commands.erase( i ); \
42 // -------------------------------------------------------------------------
43 #define BaseInteractorStyle_DIFF_TIME \
44 std::chrono::duration_cast< std::chrono::milliseconds >( \
45 std::chrono::system_clock::now( ).time_since_epoch( ) \
48 namespace cpExtensions
54 class cpExtensions_EXPORT BaseInteractorStyle
55 : public vtkInteractorStyle
58 typedef BaseInteractorStyle Self;
59 vtkTypeMacro( BaseInteractorStyle, vtkInteractorStyle );
70 typedef void ( *TMouseCommand )(
71 void*, const ButtonID&, int*, double*, bool, bool, bool
73 typedef void ( *TMouseWheelCommand )( void*, const int&, bool, bool, bool );
74 typedef void ( *TKeyCommand )( void*, const char& );
75 typedef void ( *TVoidCommand )( void* );
76 typedef TMouseCommand TMouseMoveCommand;
77 typedef TMouseCommand TMouseClickCommand;
78 typedef TMouseCommand TMouseDoubleClickCommand;
79 typedef TVoidCommand TExposeCommand;
80 typedef TVoidCommand TConfigureCommand;
81 typedef TVoidCommand TEnterCommand;
82 typedef TVoidCommand TLeaveCommand;
84 // Associate callbacks for each event
85 cpExtensions_BaseInteractorStyle_Commands( MouseMove );
86 cpExtensions_BaseInteractorStyle_Commands( MouseClick );
87 cpExtensions_BaseInteractorStyle_Commands( MouseDoubleClick );
88 cpExtensions_BaseInteractorStyle_Commands( MouseWheel );
89 cpExtensions_BaseInteractorStyle_Commands( Key );
90 cpExtensions_BaseInteractorStyle_Commands( Expose );
91 cpExtensions_BaseInteractorStyle_Commands( Configure );
92 cpExtensions_BaseInteractorStyle_Commands( Enter );
93 cpExtensions_BaseInteractorStyle_Commands( Leave );
96 static void SetSetDoubleClickDelay( long delay );
97 void DelegateTDxEvent( unsigned long event, void* calldata );
99 // Possible mouse motion events
100 virtual void OnMouseMove( );
101 virtual void OnMouseWheelForward( );
102 virtual void OnMouseWheelBackward( );
104 // Possible mouse click-related events
105 inline ButtonID GetButtonID( ) const
107 return( this->m_ActiveButton );
110 virtual void OnLeftButtonDown( );
111 virtual void OnLeftButtonUp( );
112 virtual void OnMiddleButtonDown( );
113 virtual void OnMiddleButtonUp( );
114 virtual void OnRightButtonDown( );
115 virtual void OnRightButtonUp( );
117 virtual void OnLeftClick( );
118 virtual void OnLeftDoubleClick( );
119 virtual void OnMiddleClick( );
120 virtual void OnMiddleDoubleClick( );
121 virtual void OnRightClick( );
122 virtual void OnRightDoubleClick( );
124 // Keyboard-related events
125 virtual void OnChar( );
126 virtual void OnKeyDown( ) { }
127 virtual void OnKeyUp( ) { }
128 virtual void OnKeyPress( ) { }
129 virtual void OnKeyRelease( ) { }
132 virtual void OnExpose( );
133 virtual void OnConfigure( );
134 virtual void OnEnter( );
135 virtual void OnLeave( );
137 virtual void Dolly( );
141 BaseInteractorStyle( );
142 virtual ~BaseInteractorStyle( );
144 virtual void _Dolly( double factor );
146 // Extension interface
147 virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] ) = 0;
149 // Main event callback
150 static void _ProcessEvents(
158 // Purposely not implemented
159 BaseInteractorStyle( const Self& );
160 Self& operator=( const Self& );
163 double m_MotionFactor;
168 struct _TMouseButtonEvent
170 static long MaxDoubleClick;
172 long m_LastButtonHeld;
173 long m_LastButtonDown;
175 inline _TMouseButtonEvent( )
179 this->m_LastButtonUp = 0;
180 this->m_LastButtonHeld = 0;
181 this->m_LastButtonDown = -1;
183 inline void Release( )
185 long c = BaseInteractorStyle_DIFF_TIME;
186 this->m_LastButtonUp = c;
187 this->m_LastButtonHeld = c - this->m_LastButtonDown;
188 this->m_LastButtonDown = -1;
190 inline unsigned char Clicks( )
193 long c = BaseInteractorStyle_DIFF_TIME;
195 this->m_LastButtonHeld < MaxDoubleClick &&
196 ( c - this->m_LastButtonUp ) < MaxDoubleClick
204 if( this->m_LastButtonDown < 0 )
205 this->m_LastButtonDown = c;
209 _TMouseButtonEvent m_LeftButtonEvent;
210 _TMouseButtonEvent m_MiddleButtonEvent;
211 _TMouseButtonEvent m_RightButtonEvent;
212 ButtonID m_ActiveButton;
219 #endif // __CPEXTENSIONS__INTERACTION__BASEINTERACTORSTYLE__H__