]> Creatis software - cpPlugins.git/blob - appli/examples/example_BaseInteractorStyle.cxx
75366b7057bf639440d6a69ee66700766a3732f4
[cpPlugins.git] / appli / examples / example_BaseInteractorStyle.cxx
1
2 #include <vtkSmartPointer.h>
3
4 #include <vtkRenderer.h>
5 #include <vtkRenderWindow.h>
6 #include <vtkRenderWindowInteractor.h>
7 #include <cpExtensions/Interaction/BaseInteractorStyle.h>
8
9 // -------------------------------------------------------------------------
10 #define example_BaseInteractorStyle_Macro( x )  \
11   virtual void On##x( )                                 \
12   { std::cout << "On" << #x << "( )" << std::endl; }
13
14 // -------------------------------------------------------------------------
15 class example_BaseInteractorStyle
16   : public cpExtensions::Interaction::BaseInteractorStyle
17 {
18 public:
19   typedef example_BaseInteractorStyle Self;
20   vtkTypeMacro(
21     example_BaseInteractorStyle,
22     cpExtensions::Interaction::BaseInteractorStyle
23     );
24
25 public:
26   static Self* New( )
27     { return( new Self ); }
28
29   // Possible events
30   example_BaseInteractorStyle_Macro( MouseMove );
31   example_BaseInteractorStyle_Macro( MouseWheelForward );
32   example_BaseInteractorStyle_Macro( MouseWheelBackward );
33   example_BaseInteractorStyle_Macro( LeftButtonDown );
34   example_BaseInteractorStyle_Macro( LeftButtonUp );
35   example_BaseInteractorStyle_Macro( LeftClick );
36   example_BaseInteractorStyle_Macro( LeftDoubleClick );
37   example_BaseInteractorStyle_Macro( MiddleButtonDown );
38   example_BaseInteractorStyle_Macro( MiddleButtonUp );
39   example_BaseInteractorStyle_Macro( MiddleClick );
40   example_BaseInteractorStyle_Macro( MiddleDoubleClick );
41   example_BaseInteractorStyle_Macro( RightButtonDown );
42   example_BaseInteractorStyle_Macro( RightButtonUp );
43   example_BaseInteractorStyle_Macro( RightClick );
44   example_BaseInteractorStyle_Macro( RightDoubleClick );
45   example_BaseInteractorStyle_Macro( Char );
46   example_BaseInteractorStyle_Macro( KeyDown );
47   example_BaseInteractorStyle_Macro( KeyUp );
48   example_BaseInteractorStyle_Macro( KeyPress );
49   example_BaseInteractorStyle_Macro( KeyRelease );
50   example_BaseInteractorStyle_Macro( Expose );
51   example_BaseInteractorStyle_Macro( Configure );
52   example_BaseInteractorStyle_Macro( Enter );
53   example_BaseInteractorStyle_Macro( Leave );
54
55 protected:
56   example_BaseInteractorStyle( )
57     : Superclass( )
58     { }
59   virtual ~example_BaseInteractorStyle( )
60     { }
61
62   virtual bool _PickPosition( int idx[ 2 ], double pos[ 3 ] )
63     {
64       return( true ); // Just testing...
65     }
66
67 private:
68   // Purposely not implemented
69   example_BaseInteractorStyle( const Self& );
70   Self& operator=( const Self& );
71 };
72
73 // -------------------------------------------------------------------------
74 int main( int argc, char* argv[] )
75 {
76   // Configure visualization objects
77   vtkSmartPointer< vtkRenderer > renderer =
78     vtkSmartPointer< vtkRenderer >::New( );
79   renderer->SetBackground( 0.1, 0.3, 0.5 );
80
81   vtkSmartPointer< vtkRenderWindow > window =
82     vtkSmartPointer< vtkRenderWindow >::New( );
83   window->AddRenderer( renderer );
84   window->SetSize( 600, 600 );
85
86   // Set up interaction style
87   vtkSmartPointer< example_BaseInteractorStyle > style =
88     vtkSmartPointer< example_BaseInteractorStyle >::New( );
89
90   // Set up the interaction
91   vtkSmartPointer< vtkRenderWindowInteractor > interactor =
92     vtkSmartPointer< vtkRenderWindowInteractor >::New( );
93   interactor->SetInteractorStyle( style );
94   window->SetInteractor( interactor );
95
96   // Begin interaction
97   window->Render( );
98   interactor->Start( );
99
100   return( 0 );
101 }
102
103 // eof - $RCSfile$