OpenWalnut  1.5.0dev
WUIViewEventHandler.cpp
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 #include "../common/WLogger.h"
26 #include "WUIViewEventHandler.h"
27 
28 
30  : m_widget( widget ),
31  m_preselection( GUIEvents::NONE )
32 {
33 }
34 
35 bool WUIViewEventHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa */ )
36 {
37  GUIEvents::EventType et = ea.getEventType();
38  if( et & m_preselection )
39  {
40  switch( et )
41  {
42  case( GUIEvents::NONE ) :
43  {
44  break; // Nothing todo for NONE events
45  }
46  case( GUIEvents::PUSH ):
47  {
48  m_sigPush( WVector2f( ea.getX(), ea.getY() ), ea.getButton() );
49  handlePush( WVector2f( ea.getX(), ea.getY() ), ea.getButton() );
50  break;
51  }
52  case( GUIEvents::RELEASE ):
53  {
54  m_sigRelease( WVector2f( ea.getX(), ea.getY() ), ea.getButton() );
55  handleRelease( WVector2f( ea.getX(), ea.getY() ), ea.getButton() );
56  break;
57  }
58  case( GUIEvents::DOUBLECLICK ):
59  {
60  m_sigDoubleclick( WVector2f( ea.getX(), ea.getY() ), ea.getButton() );
61  handleDoubleclick( WVector2f( ea.getX(), ea.getY() ), ea.getButton() );
62  break;
63  }
64  case( GUIEvents::DRAG ):
65  {
66  m_sigDrag( WVector2f( ea.getX(), ea.getY() ), ea.getButtonMask() );
67  handleDrag( WVector2f( ea.getX(), ea.getY() ), ea.getButtonMask() );
68  break;
69  }
70  case( GUIEvents::MOVE ):
71  {
72  m_sigMove( WVector2f( ea.getX(), ea.getY() ) );
73  handleMove( WVector2f( ea.getX(), ea.getY() ) );
74  break;
75  }
76  case( GUIEvents::KEYDOWN ):
77  {
78  m_sigKeydown( ea.getKey(), ea.getModKeyMask() );
79  handleKeydown( ea.getKey(), ea.getModKeyMask() );
80  break;
81  }
82  case( GUIEvents::KEYUP ):
83  {
84  m_sigKeyup( ea.getKey(), ea.getModKeyMask() );
85  handleKeyup( ea.getKey(), ea.getModKeyMask() );
86  break;
87  }
88  case( GUIEvents::FRAME ): // every frame triggered!
89  {
90  m_sigFrame();
91  handleFrame();
92  break;
93  }
94  case( GUIEvents::RESIZE ):
95  {
96  m_sigResize( ea.getWindowX(), ea.getWindowY(), ea.getWindowWidth(), ea.getWindowHeight() );
97  handleResize( ea.getWindowX(), ea.getWindowY(), ea.getWindowWidth(), ea.getWindowHeight() );
98  break;
99  }
100  case( GUIEvents::SCROLL ):
101  {
102  m_sigScroll( ea.getScrollingMotion(), ea.getScrollingDeltaX(), ea.getScrollingDeltaY() );
103  handleScroll( ea.getScrollingMotion(), ea.getScrollingDeltaX(), ea.getScrollingDeltaY() );
104  break;
105  }
106  case( GUIEvents::PEN_PRESSURE ):
107  {
108  m_sigPenPressure( ea.getPenPressure() );
109  handlePenPressure( ea.getPenPressure() );
110  break;
111  }
112  case( GUIEvents::PEN_ORIENTATION ):
113  {
114  m_sigPenOrientation( ea.getPenOrientation() );
115  handlePenOrientation( ea.getPenOrientation() );
116  break;
117  }
118  case( GUIEvents::PEN_PROXIMITY_ENTER ):
119  {
122  break;
123  }
124  case( GUIEvents::PEN_PROXIMITY_LEAVE ):
125  {
128  break;
129  }
130  case( GUIEvents::CLOSE_WINDOW ):
131  {
134  break;
135  }
136  case( GUIEvents::QUIT_APPLICATION ):
137  {
140  break;
141  }
142  case( GUIEvents::USER ):
143  {
144  m_sigUser();
145  handleUser();
146  break;
147  }
148  default:
149  errorLog() << "Unknown GUI Event: " << et;
150  return false;
151  }
152 
153  return true;
154  }
155 
156  return false; // There was no subscription to this event
157 }
158 
160 {
161  return wlog::error( "CustomViewEventHandler" ) << m_widget->getTitle() << ": ";
162 }
163 
164 void WUIViewEventHandler::subscribePush( ButtonSignalType::slot_type slot )
165 {
166  m_preselection |= GUIEvents::PUSH;
167  m_sigPush.connect( slot );
168 }
169 
170 void WUIViewEventHandler::subscribeRelease( ButtonSignalType::slot_type slot )
171 {
172  m_preselection |= GUIEvents::RELEASE;
173  m_sigRelease.connect( slot );
174 }
175 
176 void WUIViewEventHandler::subscribeDoubleclick( ButtonSignalType::slot_type slot )
177 {
178  m_preselection |= GUIEvents::DOUBLECLICK;
179  m_sigDoubleclick.connect( slot );
180 }
181 
182 void WUIViewEventHandler::subscribeDrag( DragSignalType::slot_type slot )
183 {
184  m_preselection |= GUIEvents::DRAG;
185  m_sigDrag.connect( slot );
186 }
187 
188 void WUIViewEventHandler::subscribeMove( MoveSignalType::slot_type slot )
189 {
190  m_preselection |= GUIEvents::MOVE;
191  m_sigMove.connect( slot );
192 }
193 
194 void WUIViewEventHandler::subscribeFrame( TriggerSignalType::slot_type slot )
195 {
196  m_preselection |= GUIEvents::FRAME;
197  m_sigFrame.connect( slot );
198 }
199 
200 void WUIViewEventHandler::subscribeKeydown( KeySignalType::slot_type slot )
201 {
202  m_preselection |= GUIEvents::KEYDOWN;
203  m_sigKeydown.connect( slot );
204 }
205 
206 void WUIViewEventHandler::subscribeKeyup( KeySignalType::slot_type slot )
207 {
208  m_preselection |= GUIEvents::KEYUP;
209  m_sigKeyup.connect( slot );
210 }
211 
212 void WUIViewEventHandler::subscribeResize( ResizeSignalType::slot_type slot )
213 {
214  m_preselection |= GUIEvents::RESIZE;
215  m_sigResize.connect( slot );
216 }
217 
218 void WUIViewEventHandler::subscribeScroll( ScrollSignalType::slot_type slot )
219 {
220  m_preselection |= GUIEvents::SCROLL;
221  m_sigScroll.connect( slot );
222 }
223 
224 void WUIViewEventHandler::subscribePenPressure( PenPressureSignalType::slot_type slot )
225 {
226  m_preselection |= GUIEvents::PEN_PRESSURE;
227  m_sigPenPressure.connect( slot );
228 }
229 
230 void WUIViewEventHandler::subscribePenOrientation( PenOrientationSignalType::slot_type slot )
231 {
232  m_preselection |= GUIEvents::PEN_ORIENTATION;
233  m_sigPenOrientation.connect( slot );
234 }
235 
236 void WUIViewEventHandler::subscribePenProximityEnter( TriggerSignalType::slot_type slot )
237 {
238  m_preselection |= GUIEvents::PEN_PROXIMITY_ENTER;
239  m_sigPenProximityEnter.connect( slot );
240 }
241 
242 void WUIViewEventHandler::subscribePenProximityLeave( TriggerSignalType::slot_type slot )
243 {
244  m_preselection |= GUIEvents::PEN_PROXIMITY_LEAVE;
245  m_sigPenProximityLeave.connect( slot );
246 }
247 
248 void WUIViewEventHandler::subscribeCloseWindow( TriggerSignalType::slot_type slot )
249 {
250  m_preselection |= GUIEvents::CLOSE_WINDOW;
251  m_sigCloseWindow.connect( slot );
252 }
253 
254 void WUIViewEventHandler::subscribeQuitApplication( TriggerSignalType::slot_type slot )
255 {
256  m_preselection |= GUIEvents::QUIT_APPLICATION;
257  m_sigQuitApplication.connect( slot );
258 }
259 
260 void WUIViewEventHandler::subscribeUser( TriggerSignalType::slot_type slot )
261 {
262  m_preselection |= GUIEvents::USER;
263  m_sigUser.connect( slot );
264 }
265 
266 void WUIViewEventHandler::handlePush( WVector2f /* mousePos */, int /* button */ )
267 {
268 }
269 
270 void WUIViewEventHandler::handleRelease( WVector2f /* mousePos */, int /* button */ )
271 {
272 }
273 
274 void WUIViewEventHandler::handleDoubleclick( WVector2f /* mousePos */, int /* button */ )
275 {
276 }
277 
278 void WUIViewEventHandler::handleDrag( WVector2f /* mousePos */, int /* buttonMask */ )
279 {
280 }
281 
283 {
284 }
285 
286 void WUIViewEventHandler::handleKeydown( int /* keyID */, unsigned int /* modKeyMask */ )
287 {
288 }
289 
290 void WUIViewEventHandler::handleKeyup( int /* keyID */, unsigned int /* modKeyMask */ )
291 {
292 }
293 
295 {
296 }
297 
298 void WUIViewEventHandler::handleResize( int /* xPos */, int /* yPos */, int /* width */, int /* height */ )
299 {
300 }
301 
302 void WUIViewEventHandler::handleScroll( GUIEvents::ScrollingMotion /* motion */, float /* deltaX */, float /* deltaY */ )
303 {
304 }
305 
306 void WUIViewEventHandler::handlePenPressure( float /* pressure */ )
307 {
308 }
309 
310 void WUIViewEventHandler::handlePenOrientation( const osg::Matrix /* orientation */ )
311 {
312 }
313 
315 {
316 }
317 
319 {
320 }
321 
323 {
324 }
325 
327 {
328 }
329 
331 {
332 }
Is just a short hand to the long name "osgGA::GUIEventAdapter".
Definition: WUIViewWidget.h:42
A fixed size matrix class.
Definition: WMatrixFixed.h:150
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.
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.
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.
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.
virtual void handlePenOrientation(const osg::Matrix orientation)
Called whenever the PEN_ORIENTATION event occurs.
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.
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.
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.
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
WStreamedLogger error(const std::string &source)
Logging an error message.
Definition: WLogger.h:298