1 #ifndef __cpExtensions__Interaction__BaseStyle__h__
2 #define __cpExtensions__Interaction__BaseStyle__h__
4 #include <cpExtensions/Config.h>
5 #include <cpExtensions/Utility.h>
6 #include <vtkInteractorStyle.h>
9 /* =========================================================================
10 * Double click algorithm inspired from:
11 * http://www.autohotkey.com/board/topic/56493-easiest-way-to-detect-double-clicks/
12 * =========================================================================
15 // -------------------------------------------------------------------------
16 #define cpExtensions_BaseStyle_Commands( C ) \
18 std::map< T##C##Command, void* > m_##C##Commands; \
20 inline void Add##C##Command( T##C##Command c, void* d ) \
24 this->m_##C##Commands[ c ] = d; \
28 inline void Remove##C##Command( T##C##Command c ) \
30 std::map< T##C##Command, void* >::iterator i = \
31 this->m_##C##Commands.find( c ); \
32 if( i != this->m_##C##Commands.end( ) ) \
34 this->m_##C##Commands.erase( i ); \
39 // -------------------------------------------------------------------------
40 namespace cpExtensions
46 class cpExtensions_EXPORT BaseStyle
47 : public vtkInteractorStyle
50 typedef BaseStyle Self;
51 vtkTypeMacro( BaseStyle, vtkInteractorStyle );
62 typedef void ( *TMouseCommand )(
63 void*, const ButtonID&, int*, double*, bool, bool, bool
65 typedef TMouseCommand TMouseClickCommand;
66 typedef TMouseCommand TMouseDoubleClickCommand;
68 // Associate callbacks for each event
69 cpExtensions_BaseStyle_Commands( MouseClick );
70 cpExtensions_BaseStyle_Commands( MouseDoubleClick );
73 static void SetSetDoubleClickDelay( long delay );
74 void DelegateTDxEvent( unsigned long event, void* calldata );
76 // Possible mouse motion events
77 virtual void OnMouseMove( ) cpExtensions_OVERRIDE;
78 virtual void OnMouseWheelForward( ) cpExtensions_OVERRIDE { }
79 virtual void OnMouseWheelBackward( ) cpExtensions_OVERRIDE { }
81 // Possible mouse click-related events
82 inline ButtonID GetButtonID( ) const { return( this->m_ActiveButton ); }
84 virtual void OnLeftButtonDown( ) cpExtensions_OVERRIDE;
85 virtual void OnLeftButtonUp( ) cpExtensions_OVERRIDE;
86 virtual void OnMiddleButtonDown( ) cpExtensions_OVERRIDE;
87 virtual void OnMiddleButtonUp( ) cpExtensions_OVERRIDE;
88 virtual void OnRightButtonDown( ) cpExtensions_OVERRIDE;
89 virtual void OnRightButtonUp( ) cpExtensions_OVERRIDE;
91 virtual void OnLeftClick( );
92 virtual void OnLeftDoubleClick( );
93 virtual void OnMiddleClick( );
94 virtual void OnMiddleDoubleClick( );
95 virtual void OnRightClick( );
96 virtual void OnRightDoubleClick( );
98 // Keyboard-related events
99 virtual void OnChar( ) cpExtensions_OVERRIDE { }
100 virtual void OnKeyDown( ) cpExtensions_OVERRIDE { }
101 virtual void OnKeyUp( ) cpExtensions_OVERRIDE { }
102 virtual void OnKeyPress( ) cpExtensions_OVERRIDE { }
103 virtual void OnKeyRelease( ) cpExtensions_OVERRIDE { }
106 virtual void OnExpose( ) cpExtensions_OVERRIDE { }
107 virtual void OnConfigure( ) cpExtensions_OVERRIDE { }
108 virtual void OnEnter( ) cpExtensions_OVERRIDE { }
109 virtual void OnLeave( ) cpExtensions_OVERRIDE { }
111 virtual void Dolly( ) cpExtensions_OVERRIDE;
112 virtual void Pan( ) cpExtensions_OVERRIDE;
116 virtual ~BaseStyle( );
118 virtual void _Dolly( double factor );
120 // Extension interface
121 virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] ) = 0;
123 // Main event callback
124 static void _ProcessEvents(
132 // Purposely not implemented
133 BaseStyle( const Self& );
134 Self& operator=( const Self& );
137 double m_MotionFactor;
142 struct _TMouseButtonEvent
144 static long MaxDoubleClick;
146 long m_LastButtonHeld;
147 long m_LastButtonDown;
149 inline _TMouseButtonEvent( )
153 this->m_LastButtonUp = 0;
154 this->m_LastButtonHeld = 0;
155 this->m_LastButtonDown = -1;
157 inline void Release( )
159 long c = cpExtensions_CHRONO;
160 this->m_LastButtonUp = c;
161 this->m_LastButtonHeld = c - this->m_LastButtonDown;
162 this->m_LastButtonDown = -1;
164 inline unsigned char Clicks( )
167 long c = cpExtensions_CHRONO;
169 this->m_LastButtonHeld < MaxDoubleClick &&
170 ( c - this->m_LastButtonUp ) < MaxDoubleClick
178 if( this->m_LastButtonDown < 0 )
179 this->m_LastButtonDown = c;
183 _TMouseButtonEvent m_LeftButtonEvent;
184 _TMouseButtonEvent m_MiddleButtonEvent;
185 _TMouseButtonEvent m_RightButtonEvent;
186 ButtonID m_ActiveButton;
193 #endif // __cpExtensions__Interaction__BaseStyle__h__