OpenWalnut  1.5.0dev
WUIViewEventHandler.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WUIVIEWEVENTHANDLER_H
26 #define WUIVIEWEVENTHANDLER_H
27 
28 #include <boost/signals2/signal.hpp>
29 
30 #include <osgGA/GUIEventAdapter>
31 #include <osgGA/GUIEventHandler>
32 
33 #include "../common/math/linearAlgebra/WVectorFixed.h"
34 #include "../common/WLogger.h"
35 #include "WUIViewWidget.h"
36 
37 /**
38  * An event handler for a custom widget which eases interaction with GUIEvents within your module. Without you need to write your
39  * own event handler and register it. However if you still need your own event handler you might consider subclassing from this
40  * one. Basically there are two ways of getting notified of GUIEvents. First you can connect a member function to events or you
41  * can overwrite member functions of this class to handle specific events.
42  *
43  * Use boost::bind and the subscribeXY methods to connect a member function of your module to a specific GUIEvent. Please note
44  * that this is now called in context of the GUI thread and that you need to take care of threadsafety by yourself.
45  *
46  * Use the corresponding handleXY() member functions if you still need a custom event handler. But take care that you may need to
47  * set the WUIViewEventHandler::m_preselection event-mask accordingly within the constructor then.
48  *
49  * In case you might not know what the specific parameters of the handle function represent you might have luck looking into the
50  * OpenSceneGraph documentation http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs within the GUIEventAdapter
51  * class.
52  */
53 class WUIViewEventHandler : public osgGA::GUIEventHandler
54 {
55 public:
56  /**
57  * Constructor.
58  *
59  * \param widget The custom widget for which events should be handled.
60  */
61  explicit WUIViewEventHandler( WUIViewWidget::SPtr widget );
62 
63  /**
64  * The OSG calls this function whenever a new event has occured.
65  *
66  * \param ea Event class for storing GUI events such as mouse or keyboard interation etc.
67  *
68  * \return true if the event was handled.
69  */
70  bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa */ );
71 
72  /**
73  * Short hand type for signal signature of PUSH, RELEASE and DOUBLECLICK event.
74  */
75  typedef boost::signals2::signal< void ( WVector2f, int ) > ButtonSignalType;
76 
77  /**
78  * Short hand type for signal signature of DRAG event.
79  */
80  typedef boost::signals2::signal< void ( WVector2f, unsigned int ) > DragSignalType;
81 
82  /**
83  * Short hand type for signal signature of MOVE event.
84  */
85  typedef boost::signals2::signal< void ( WVector2f ) > MoveSignalType;
86 
87  /**
88  * Short hand type for signal signature of SCROLL event.
89  */
90  typedef boost::signals2::signal< void ( GUIEvents::ScrollingMotion, float, float ) > ScrollSignalType;
91 
92  /**
93  * Short hand type for signal signature of FRAME, PEN_PROXIMITY_ENTER, -LEAVE, CLOSE_WINDOW, QUIT_APPLICATION and USER event.
94  */
95  typedef boost::signals2::signal< void ( void ) > TriggerSignalType;
96 
97  /**
98  * Short hand type for signal signature of KEYDOWN and KEYUP event.
99  */
100  typedef boost::signals2::signal< void ( int, unsigned int ) > KeySignalType;
101 
102  /**
103  * Short hand type for signal signature of RESIZE event.
104  */
105  typedef boost::signals2::signal< void ( int, int, int, int ) > ResizeSignalType;
106 
107  /**
108  * Short hand type for signal signature of PEN_PRESSURE event.
109  */
110  typedef boost::signals2::signal< void ( float ) > PenPressureSignalType;
111 
112  /**
113  * Short hand type for signal signature of PEN_ORIENTATION event.
114  */
115  typedef boost::signals2::signal< void ( const osg::Matrix ) > PenOrientationSignalType;
116 
117  /**
118  * Registers a function slot to PUSH events. Whenever the event occurs, the slot is called with current parameters.
119  *
120  * \param slot Function object having the appropriate signature according to the used SignalType.
121  */
122  virtual void subscribePush( ButtonSignalType::slot_type slot );
123 
124  /**
125  * Registers a function slot to RELEASE events. Whenever the event occurs, the slot is called with current parameters.
126  * \copydetails subscribePush()
127  */
128  virtual void subscribeRelease( ButtonSignalType::slot_type slot );
129 
130  /**
131  * Registers a function slot to DOUBLECLICK events.
132  * \copydetails subscribePush()
133  */
134  virtual void subscribeDoubleclick( ButtonSignalType::slot_type slot );
135 
136  /**
137  * Registers a function slot to DRAG events.
138  * \copydetails subscribePush()
139  */
140  virtual void subscribeDrag( DragSignalType::slot_type slot );
141 
142  /**
143  * Registers a function slot to MOVE events.
144  *
145  * \copydetails subscribePush()
146  */
147  virtual void subscribeMove( MoveSignalType::slot_type slot );
148 
149  /**
150  * Registers a function slot to KEYDOWN events.
151  *
152  * \copydetails subscribePush()
153  */
154  virtual void subscribeKeydown( KeySignalType::slot_type slot );
155 
156  /**
157  * Registers a function slot to KEYUP events.
158  *
159  * \copydetails subscribePush()
160  */
161  virtual void subscribeKeyup( KeySignalType::slot_type slot );
162 
163  /**
164  * Registers a function slot to FRAME events.
165  *
166  * \copydetails subscribePush()
167  */
168  virtual void subscribeFrame( TriggerSignalType::slot_type );
169 
170  /**
171  * Registers a function slot to RESIZE events.
172  *
173  * \copydetails subscribePush()
174  */
175  virtual void subscribeResize( ResizeSignalType::slot_type slot );
176 
177  /**
178  * Registers a function slot to SCROLL events.
179  *
180  * \copydetails subscribePush()
181  */
182  virtual void subscribeScroll( ScrollSignalType::slot_type slot );
183 
184  /**
185  * Registers a function slot to PEN_PRESSURE events.
186  *
187  * \copydetails subscribePush()
188  */
189  virtual void subscribePenPressure( PenPressureSignalType::slot_type slot );
190 
191  /**
192  * Registers a function slot to PEN_ORIENTATION events.
193  *
194  * \copydetails subscribePush()
195  */
196  virtual void subscribePenOrientation( PenOrientationSignalType::slot_type slot );
197 
198  /**
199  * Registers a function slot to PEN_PROXIMITY_ENTER events.
200  *
201  * \copydetails subscribePush()
202  */
203  virtual void subscribePenProximityEnter( TriggerSignalType::slot_type slot );
204 
205  /**
206  * Registers a function slot to PEN_PROXIMITY_LEAVE events.
207  *
208  * \copydetails subscribePush()
209  */
210  virtual void subscribePenProximityLeave( TriggerSignalType::slot_type slot );
211 
212  /**
213  * Registers a function slot to CLOSE_WINDOW events.
214  *
215  * \copydetails subscribePush()
216  */
217  virtual void subscribeCloseWindow( TriggerSignalType::slot_type slot );
218 
219  /**
220  * Registers a function slot to QUIT_APPLICATION events.
221  * \copydetails subscribePush()
222  */
223  virtual void subscribeQuitApplication( TriggerSignalType::slot_type slot );
224 
225  /**
226  * Registers a function slot to USER events.
227  * \copydetails subscribePush()
228  */
229  virtual void subscribeUser( TriggerSignalType::slot_type slot );
230 
231  /**
232  * Called whenever the PUSH event occurs.
233  *
234  * \param mousePos Current mouse position in X and Y.
235  * \param button The involved mouse button. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs
236  * GUIEventAdapter class for values.
237  */
238  virtual void handlePush( WVector2f mousePos, int button );
239 
240  /**
241  * Called whenever the RELEASE event occurs.
242  * \copydetails handlePush()
243  */
244  virtual void handleRelease( WVector2f mousePos, int button );
245 
246  /**
247  * Called whenever the DOUBLECLICK event occurs.
248  * \copydetails handlePush()
249  */
250  virtual void handleDoubleclick( WVector2f mousePos, int button );
251 
252  /**
253  * Called whenever the DRAG event occurs.
254  *
255  * \param mousePos Current mouse position in X and Y.
256  * \param buttonMask The pushed mouse buttons as a mask. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs
257  * GUIEventAdapter class for values.
258  */
259  virtual void handleDrag( WVector2f mousePos, int buttonMask );
260 
261  /**
262  * Called whenever the MOVE event occurs.
263  *
264  * \param mousePos Current mouse position in X and Y.
265  */
266  virtual void handleMove( WVector2f mousePos );
267 
268  /**
269  * Called whenever the KEYDOWN event occurs.
270  *
271  * \param keyID The pressed key. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs GUIEventAdapter
272  * class for values.
273  * \param modKeyMask Additional function keys pressed.
274  */
275  virtual void handleKeydown( int keyID, unsigned int modKeyMask );
276 
277  /**
278  * Called whenever the KEYUP event occurs.
279  *
280  * \param keyID The released key. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs GUIEventAdapter
281  * class for values.
282  * \param modKeyMask Additional function keys pressed.
283  */
284  virtual void handleKeyup( int keyID, unsigned int modKeyMask );
285 
286  /**
287  * Called whenever the FRAME event occurs. This is every new frame.
288  */
289  virtual void handleFrame();
290 
291  /**
292  * Called whenever the widget has resized.
293  *
294  * \param xPos Position in X.
295  * \param yPos Position in Y.
296  * \param width Width of the widget.
297  * \param height Height of the widget.
298  */
299  virtual void handleResize( int xPos, int yPos, int width, int height );
300 
301  /**
302  * Called whenever the SCROLL event occurs.
303  *
304  * \param motion Scrolling motion. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs GUIEventAdapter class for values.
305  * \param deltaX Delta in X.
306  * \param deltaY Delta in Y.
307  */
308  virtual void handleScroll( GUIEvents::ScrollingMotion motion, float deltaX, float deltaY );
309 
310  /**
311  * Called whenever the PEN_PRESSURE event occurs.
312  *
313  * \param pressure pressure of the pen.
314  */
315  virtual void handlePenPressure( float pressure );
316 
317  /**
318  * Called whenever the PEN_ORIENTATION event occurs.
319  *
320  * \param orientation the orientation of the pen.
321  */
322  virtual void handlePenOrientation( const osg::Matrix orientation );
323 
324  /**
325  * Called whenever the PEN_PROXIMITY_ENTER event occurs.
326  */
327  virtual void handlePenProximityEnter();
328 
329  /**
330  * Called whenever the PEN_PROXIMITY_LEAVE event occurs.
331  */
332  virtual void handlePenProximityLeave();
333 
334  /**
335  * Called whenever the CLOSE_WINDOW event occurs.
336  */
337  virtual void handleCloseWindow();
338 
339  /**
340  * Called whenever the QUIT_APPLICATION event occurs.
341  */
342  virtual void handleQuitApplication();
343 
344  /**
345  * Called whenever the USER event occurs.
346  */
347  virtual void handleUser();
348 
349 protected:
350  /**
351  * Signal used for notification of the PUSH event.
352  */
354 
355  /**
356  * Signal used for notification of the RELEASE event.
357  */
359 
360  /**
361  * Signal used for notification of the DOUBLECLICK event.
362  */
364 
365  /**
366  * Signal used for notification of the DRAG event.
367  */
369 
370  /**
371  * Signal used for notification of the MOVE event.
372  */
374 
375  /**
376  * Signal used for notification of the KEYDOWN event.
377  */
379 
380  /**
381  * Signal used for notification of the KEYUP event.
382  */
384 
385  /**
386  * Signal used for notification of the FRAME event.
387  */
389 
390  /**
391  * Signal used for notification of the RESIZE event.
392  */
394 
395  /**
396  * Signal used for notification of the SCROLL event.
397  */
399 
400  /**
401  * Signal used for notification of the PEN_PRESSURE event.
402  */
404 
405  /**
406  * Signal used for notification of the PEN_ORIENTATION event.
407  */
409 
410  /**
411  * Signal used for notification of the PEN_PROXIMITY_ENTER event.
412  */
414 
415  /**
416  * Signal used for notification of the PEN_PROXIMITY_LEAVE event.
417  */
419 
420  /**
421  * Signal used for notification of the CLOSE_WINDOW event.
422  */
424 
425  /**
426  * Signal used for notification of the QUIT_APPLICATION event.
427  */
429 
430  /**
431  * Signal used for notification of the USER event.
432  */
434 
435  /**
436  * Reference to the WUIViewWidget for which event handling should performed.
437  */
439 
440  /**
441  * Binary mask describing which events should be used for notification or subscription.
442  */
443  unsigned int m_preselection;
444 
445  /**
446  * Logger instance for comfortable error logging. Simply use errorLog() << "my error".
447  *
448  * \return the logger stream.
449  */
451 };
452 
453 #endif // WUIVIEWEVENTHANDLER_H
A fixed size matrix class.
Definition: WMatrixFixed.h:150
An event handler for a custom widget which eases interaction with GUIEvents within your module.
virtual void handleKeyup(int keyID, unsigned int modKeyMask)
Called whenever the KEYUP event occurs.
TriggerSignalType m_sigQuitApplication
Signal used for notification of the QUIT_APPLICATION event.
DragSignalType m_sigDrag
Signal used for notification of the DRAG event.
virtual void handlePush(WVector2f mousePos, int button)
Called whenever the PUSH event occurs.
virtual void handleScroll(GUIEvents::ScrollingMotion motion, float deltaX, float deltaY)
Called whenever the SCROLL event occurs.
TriggerSignalType m_sigPenProximityLeave
Signal used for notification of the PEN_PROXIMITY_LEAVE event.
TriggerSignalType m_sigUser
Signal used for notification of the USER event.
virtual void handlePenPressure(float pressure)
Called whenever the PEN_PRESSURE event occurs.
boost::signals2::signal< void(void) > TriggerSignalType
Short hand type for signal signature of FRAME, PEN_PROXIMITY_ENTER, -LEAVE, CLOSE_WINDOW,...
virtual void subscribePenOrientation(PenOrientationSignalType::slot_type slot)
Registers a function slot to PEN_ORIENTATION events.
MoveSignalType m_sigMove
Signal used for notification of the MOVE event.
ButtonSignalType m_sigDoubleclick
Signal used for notification of the DOUBLECLICK event.
boost::signals2::signal< void(float) > PenPressureSignalType
Short hand type for signal signature of PEN_PRESSURE event.
boost::signals2::signal< void(const osg::Matrix) > PenOrientationSignalType
Short hand type for signal signature of PEN_ORIENTATION event.
virtual void subscribeMove(MoveSignalType::slot_type slot)
Registers a function slot to MOVE events.
WUIViewEventHandler(WUIViewWidget::SPtr widget)
Constructor.
virtual void handleQuitApplication()
Called whenever the QUIT_APPLICATION event occurs.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
virtual void handlePenProximityEnter()
Called whenever the PEN_PROXIMITY_ENTER event occurs.
virtual void handlePenProximityLeave()
Called whenever the PEN_PROXIMITY_LEAVE event occurs.
virtual void handleRelease(WVector2f mousePos, int button)
Called whenever the RELEASE event occurs.
virtual void subscribePenProximityLeave(TriggerSignalType::slot_type slot)
Registers a function slot to PEN_PROXIMITY_LEAVE events.
virtual void subscribeQuitApplication(TriggerSignalType::slot_type slot)
Registers a function slot to QUIT_APPLICATION events.
virtual void handleResize(int xPos, int yPos, int width, int height)
Called whenever the widget has resized.
virtual void handleCloseWindow()
Called whenever the CLOSE_WINDOW event occurs.
virtual void handleUser()
Called whenever the USER event occurs.
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &)
The OSG calls this function whenever a new event has occured.
ButtonSignalType m_sigPush
Signal used for notification of the PUSH event.
virtual void subscribePenPressure(PenPressureSignalType::slot_type slot)
Registers a function slot to PEN_PRESSURE events.
boost::signals2::signal< void(int, int, int, int) > ResizeSignalType
Short hand type for signal signature of RESIZE event.
ButtonSignalType m_sigRelease
Signal used for notification of the RELEASE event.
KeySignalType m_sigKeydown
Signal used for notification of the KEYDOWN event.
unsigned int m_preselection
Binary mask describing which events should be used for notification or subscription.
PenOrientationSignalType m_sigPenOrientation
Signal used for notification of the PEN_ORIENTATION event.
virtual void subscribeFrame(TriggerSignalType::slot_type)
Registers a function slot to FRAME events.
ResizeSignalType m_sigResize
Signal used for notification of the RESIZE event.
virtual void subscribeKeydown(KeySignalType::slot_type slot)
Registers a function slot to KEYDOWN events.
virtual void handleDrag(WVector2f mousePos, int buttonMask)
Called whenever the DRAG event occurs.
virtual void subscribeCloseWindow(TriggerSignalType::slot_type slot)
Registers a function slot to CLOSE_WINDOW events.
boost::signals2::signal< void(WVector2f, unsigned int) > DragSignalType
Short hand type for signal signature of DRAG event.
virtual void handlePenOrientation(const osg::Matrix orientation)
Called whenever the PEN_ORIENTATION event occurs.
boost::signals2::signal< void(WVector2f, int) > ButtonSignalType
Short hand type for signal signature of PUSH, RELEASE and DOUBLECLICK event.
virtual void subscribeKeyup(KeySignalType::slot_type slot)
Registers a function slot to KEYUP events.
virtual void subscribeDrag(DragSignalType::slot_type slot)
Registers a function slot to DRAG events.
virtual void subscribePenProximityEnter(TriggerSignalType::slot_type slot)
Registers a function slot to PEN_PROXIMITY_ENTER events.
boost::signals2::signal< void(GUIEvents::ScrollingMotion, float, float) > ScrollSignalType
Short hand type for signal signature of SCROLL event.
virtual void subscribeDoubleclick(ButtonSignalType::slot_type slot)
Registers a function slot to DOUBLECLICK events.
virtual void handleKeydown(int keyID, unsigned int modKeyMask)
Called whenever the KEYDOWN event occurs.
boost::signals2::signal< void(WVector2f) > MoveSignalType
Short hand type for signal signature of MOVE event.
virtual void handleFrame()
Called whenever the FRAME event occurs.
virtual void subscribeResize(ResizeSignalType::slot_type slot)
Registers a function slot to RESIZE events.
KeySignalType m_sigKeyup
Signal used for notification of the KEYUP event.
WUIViewWidget::SPtr m_widget
Reference to the WUIViewWidget for which event handling should performed.
virtual void subscribeScroll(ScrollSignalType::slot_type slot)
Registers a function slot to SCROLL events.
ScrollSignalType m_sigScroll
Signal used for notification of the SCROLL event.
virtual void subscribePush(ButtonSignalType::slot_type slot)
Registers a function slot to PUSH events.
boost::signals2::signal< void(int, unsigned int) > KeySignalType
Short hand type for signal signature of KEYDOWN and KEYUP event.
PenPressureSignalType m_sigPenPressure
Signal used for notification of the PEN_PRESSURE event.
TriggerSignalType m_sigCloseWindow
Signal used for notification of the CLOSE_WINDOW event.
TriggerSignalType m_sigFrame
Signal used for notification of the FRAME event.
virtual void subscribeUser(TriggerSignalType::slot_type slot)
Registers a function slot to USER events.
TriggerSignalType m_sigPenProximityEnter
Signal used for notification of the PEN_PROXIMITY_ENTER event.
virtual void handleMove(WVector2f mousePos)
Called whenever the MOVE event occurs.
virtual void subscribeRelease(ButtonSignalType::slot_type slot)
Registers a function slot to RELEASE events.
virtual void handleDoubleclick(WVector2f mousePos, int button)
Called whenever the DOUBLECLICK event occurs.
std::shared_ptr< WUIViewWidget > SPtr
Abbreviation for a shared pointer on a instance of this class.
Definition: WUIViewWidget.h:72
Resource class for streamed logging.
Definition: WLogger.h:180