OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #include "../common/WLogger.h" 00026 #include "WCustomWidgetEventHandler.h" 00027 00028 00029 WCustomWidgetEventHandler::WCustomWidgetEventHandler( WCustomWidget::SPtr widget ) 00030 : m_widget( widget ), 00031 m_preselection( GUIEvents::NONE ) 00032 { 00033 } 00034 00035 bool WCustomWidgetEventHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa */ ) 00036 { 00037 GUIEvents::EventType et = ea.getEventType(); 00038 if( et & m_preselection ) 00039 { 00040 switch( et ) 00041 { 00042 case( GUIEvents::NONE ) : 00043 { 00044 break; // Nothing todo for NONE events 00045 } 00046 case( GUIEvents::PUSH ): 00047 { 00048 m_sigPush( WVector2f( ea.getX(), ea.getY() ), ea.getButton() ); 00049 handlePush( WVector2f( ea.getX(), ea.getY() ), ea.getButton() ); 00050 break; 00051 } 00052 case( GUIEvents::RELEASE ): 00053 { 00054 m_sigRelease( WVector2f( ea.getX(), ea.getY() ), ea.getButton() ); 00055 handleRelease( WVector2f( ea.getX(), ea.getY() ), ea.getButton() ); 00056 break; 00057 } 00058 case( GUIEvents::DOUBLECLICK ): 00059 { 00060 m_sigDoubleclick( WVector2f( ea.getX(), ea.getY() ), ea.getButton() ); 00061 handleDoubleclick( WVector2f( ea.getX(), ea.getY() ), ea.getButton() ); 00062 break; 00063 } 00064 case( GUIEvents::DRAG ): 00065 { 00066 m_sigDrag( WVector2f( ea.getX(), ea.getY() ), ea.getButtonMask() ); 00067 handleDrag( WVector2f( ea.getX(), ea.getY() ), ea.getButtonMask() ); 00068 break; 00069 } 00070 case( GUIEvents::MOVE ): 00071 { 00072 m_sigMove( WVector2f( ea.getX(), ea.getY() ) ); 00073 handleMove( WVector2f( ea.getX(), ea.getY() ) ); 00074 break; 00075 } 00076 case( GUIEvents::KEYDOWN ): 00077 { 00078 m_sigKeydown( ea.getKey(), ea.getModKeyMask() ); 00079 handleKeydown( ea.getKey(), ea.getModKeyMask() ); 00080 break; 00081 } 00082 case( GUIEvents::KEYUP ): 00083 { 00084 m_sigKeyup( ea.getKey(), ea.getModKeyMask() ); 00085 handleKeyup( ea.getKey(), ea.getModKeyMask() ); 00086 break; 00087 } 00088 case( GUIEvents::FRAME ): // every frame triggered! 00089 { 00090 m_sigFrame(); 00091 handleFrame(); 00092 break; 00093 } 00094 case( GUIEvents::RESIZE ): 00095 { 00096 m_sigResize( ea.getWindowX(), ea.getWindowY(), ea.getWindowWidth(), ea.getWindowHeight() ); 00097 handleResize( ea.getWindowX(), ea.getWindowY(), ea.getWindowWidth(), ea.getWindowHeight() ); 00098 break; 00099 } 00100 case( GUIEvents::SCROLL ): 00101 { 00102 m_sigScroll( ea.getScrollingMotion(), ea.getScrollingDeltaX(), ea.getScrollingDeltaY() ); 00103 handleScroll( ea.getScrollingMotion(), ea.getScrollingDeltaX(), ea.getScrollingDeltaY() ); 00104 break; 00105 } 00106 case( GUIEvents::PEN_PRESSURE ): 00107 { 00108 m_sigPenPressure( ea.getPenPressure() ); 00109 handlePenPressure( ea.getPenPressure() ); 00110 break; 00111 } 00112 case( GUIEvents::PEN_ORIENTATION ): 00113 { 00114 m_sigPenOrientation( ea.getPenOrientation() ); 00115 handlePenOrientation( ea.getPenOrientation() ); 00116 break; 00117 } 00118 case( GUIEvents::PEN_PROXIMITY_ENTER ): 00119 { 00120 m_sigPenProximityEnter(); 00121 handlePenProximityEnter(); 00122 break; 00123 } 00124 case( GUIEvents::PEN_PROXIMITY_LEAVE ): 00125 { 00126 m_sigPenProximityLeave(); 00127 handlePenProximityLeave(); 00128 break; 00129 } 00130 case( GUIEvents::CLOSE_WINDOW ): 00131 { 00132 m_sigCloseWindow(); 00133 handleCloseWindow(); 00134 break; 00135 } 00136 case( GUIEvents::QUIT_APPLICATION ): 00137 { 00138 m_sigQuitApplication(); 00139 handleQuitApplication(); 00140 break; 00141 } 00142 case( GUIEvents::USER ): 00143 { 00144 m_sigUser(); 00145 handleUser(); 00146 break; 00147 } 00148 default: 00149 errorLog() << "Unknown GUI Event: " << et; 00150 return false; 00151 } 00152 00153 return true; 00154 } 00155 00156 return false; // There was no subscription to this event 00157 } 00158 00159 wlog::WStreamedLogger WCustomWidgetEventHandler::errorLog() const 00160 { 00161 return wlog::error( "CustomWidgetEventHandler" ) << m_widget->getTitle() << ": "; 00162 } 00163 00164 void WCustomWidgetEventHandler::subscribePush( ButtonSignalType::slot_type slot ) 00165 { 00166 m_preselection |= GUIEvents::PUSH; 00167 m_sigPush.connect( slot ); 00168 } 00169 00170 void WCustomWidgetEventHandler::subscribeRelease( ButtonSignalType::slot_type slot ) 00171 { 00172 m_preselection |= GUIEvents::RELEASE; 00173 m_sigRelease.connect( slot ); 00174 } 00175 00176 void WCustomWidgetEventHandler::subscribeDoubleclick( ButtonSignalType::slot_type slot ) 00177 { 00178 m_preselection |= GUIEvents::DOUBLECLICK; 00179 m_sigDoubleclick.connect( slot ); 00180 } 00181 00182 void WCustomWidgetEventHandler::subscribeDrag( DragSignalType::slot_type slot ) 00183 { 00184 m_preselection |= GUIEvents::DRAG; 00185 m_sigDrag.connect( slot ); 00186 } 00187 00188 void WCustomWidgetEventHandler::subscribeMove( MoveSignalType::slot_type slot ) 00189 { 00190 m_preselection |= GUIEvents::MOVE; 00191 m_sigMove.connect( slot ); 00192 } 00193 00194 void WCustomWidgetEventHandler::subscribeFrame( TriggerSignalType::slot_type slot ) 00195 { 00196 m_preselection |= GUIEvents::FRAME; 00197 m_sigFrame.connect( slot ); 00198 } 00199 00200 void WCustomWidgetEventHandler::subscribeKeydown( KeySignalType::slot_type slot ) 00201 { 00202 m_preselection |= GUIEvents::KEYDOWN; 00203 m_sigKeydown.connect( slot ); 00204 } 00205 00206 void WCustomWidgetEventHandler::subscribeKeyup( KeySignalType::slot_type slot ) 00207 { 00208 m_preselection |= GUIEvents::KEYUP; 00209 m_sigKeyup.connect( slot ); 00210 } 00211 00212 void WCustomWidgetEventHandler::subscribeResize( ResizeSignalType::slot_type slot ) 00213 { 00214 m_preselection |= GUIEvents::RESIZE; 00215 m_sigResize.connect( slot ); 00216 } 00217 00218 void WCustomWidgetEventHandler::subscribeScroll( ScrollSignalType::slot_type slot ) 00219 { 00220 m_preselection |= GUIEvents::SCROLL; 00221 m_sigScroll.connect( slot ); 00222 } 00223 00224 void WCustomWidgetEventHandler::subscribePenPressure( PenPressureSignalType::slot_type slot ) 00225 { 00226 m_preselection |= GUIEvents::PEN_PRESSURE; 00227 m_sigPenPressure.connect( slot ); 00228 } 00229 00230 void WCustomWidgetEventHandler::subscribePenOrientation( PenOrientationSignalType::slot_type slot ) 00231 { 00232 m_preselection |= GUIEvents::PEN_ORIENTATION; 00233 m_sigPenOrientation.connect( slot ); 00234 } 00235 00236 void WCustomWidgetEventHandler::subscribePenProximityEnter( TriggerSignalType::slot_type slot ) 00237 { 00238 m_preselection |= GUIEvents::PEN_PROXIMITY_ENTER; 00239 m_sigPenProximityEnter.connect( slot ); 00240 } 00241 00242 void WCustomWidgetEventHandler::subscribePenProximityLeave( TriggerSignalType::slot_type slot ) 00243 { 00244 m_preselection |= GUIEvents::PEN_PROXIMITY_LEAVE; 00245 m_sigPenProximityLeave.connect( slot ); 00246 } 00247 00248 void WCustomWidgetEventHandler::subscribeCloseWindow( TriggerSignalType::slot_type slot ) 00249 { 00250 m_preselection |= GUIEvents::CLOSE_WINDOW; 00251 m_sigCloseWindow.connect( slot ); 00252 } 00253 00254 void WCustomWidgetEventHandler::subscribeQuitApplication( TriggerSignalType::slot_type slot ) 00255 { 00256 m_preselection |= GUIEvents::QUIT_APPLICATION; 00257 m_sigQuitApplication.connect( slot ); 00258 } 00259 00260 void WCustomWidgetEventHandler::subscribeUser( TriggerSignalType::slot_type slot ) 00261 { 00262 m_preselection |= GUIEvents::USER; 00263 m_sigUser.connect( slot ); 00264 } 00265 00266 void WCustomWidgetEventHandler::handlePush( WVector2f /* mousePos */, int /* button */ ) 00267 { 00268 } 00269 00270 void WCustomWidgetEventHandler::handleRelease( WVector2f /* mousePos */, int /* button */ ) 00271 { 00272 } 00273 00274 void WCustomWidgetEventHandler::handleDoubleclick( WVector2f /* mousePos */, int /* button */ ) 00275 { 00276 } 00277 00278 void WCustomWidgetEventHandler::handleDrag( WVector2f /* mousePos */, int /* buttonMask */ ) 00279 { 00280 } 00281 00282 void WCustomWidgetEventHandler::handleMove( WVector2f /* mousePos */ ) 00283 { 00284 } 00285 00286 void WCustomWidgetEventHandler::handleKeydown( int /* keyID */, unsigned int /* modKeyMask */ ) 00287 { 00288 } 00289 00290 void WCustomWidgetEventHandler::handleKeyup( int /* keyID */, unsigned int /* modKeyMask */ ) 00291 { 00292 } 00293 00294 void WCustomWidgetEventHandler::handleFrame() 00295 { 00296 } 00297 00298 void WCustomWidgetEventHandler::handleResize( int /* xPos */, int /* yPos */, int /* width */, int /* height */ ) 00299 { 00300 } 00301 00302 void WCustomWidgetEventHandler::handleScroll( GUIEvents::ScrollingMotion /* motion */, float /* deltaX */, float /* deltaY */ ) 00303 { 00304 } 00305 00306 void WCustomWidgetEventHandler::handlePenPressure( float /* pressure */ ) 00307 { 00308 } 00309 00310 void WCustomWidgetEventHandler::handlePenOrientation( const osg::Matrix /* orientation */ ) 00311 { 00312 } 00313 00314 void WCustomWidgetEventHandler::handlePenProximityEnter() 00315 { 00316 } 00317 00318 void WCustomWidgetEventHandler::handlePenProximityLeave() 00319 { 00320 } 00321 00322 void WCustomWidgetEventHandler::handleCloseWindow() 00323 { 00324 } 00325 00326 void WCustomWidgetEventHandler::handleQuitApplication() 00327 { 00328 } 00329 00330 void WCustomWidgetEventHandler::handleUser() 00331 { 00332 }