Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
f6c53650
Commit
f6c53650
authored
Apr 12, 2013
by
Mathias Goldau
Browse files
[FORGOT
#274
] Some important files I've forgotten to checkin, sorry
parent
65dc2738
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
786 additions
and
0 deletions
+786
-0
src/core/gui/WCustomWidgetEventHandler.cpp
src/core/gui/WCustomWidgetEventHandler.cpp
+332
-0
src/core/gui/WCustomWidgetEventHandler.h
src/core/gui/WCustomWidgetEventHandler.h
+454
-0
No files found.
src/core/gui/WCustomWidgetEventHandler.cpp
0 → 100644
View file @
f6c53650
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "../common/WLogger.h"
#include "WCustomWidgetEventHandler.h"
WCustomWidgetEventHandler
::
WCustomWidgetEventHandler
(
WCustomWidget
::
SPtr
widget
)
:
m_widget
(
widget
),
m_preselection
(
GUIEvents
::
NONE
)
{
}
bool
WCustomWidgetEventHandler
::
handle
(
const
osgGA
::
GUIEventAdapter
&
ea
,
osgGA
::
GUIActionAdapter
&
/* aa */
)
{
GUIEvents
::
EventType
et
=
ea
.
getEventType
();
if
(
et
&
m_preselection
)
{
switch
(
et
)
{
case
(
GUIEvents
::
NONE
)
:
{
break
;
// Nothing todo for NONE events
}
case
(
GUIEvents
::
PUSH
):
{
m_sigPush
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButton
()
);
handlePush
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButton
()
);
break
;
}
case
(
GUIEvents
::
RELEASE
):
{
m_sigRelease
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButton
()
);
handleRelease
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButton
()
);
break
;
}
case
(
GUIEvents
::
DOUBLECLICK
):
{
m_sigDoubleclick
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButton
()
);
handleDoubleclick
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButton
()
);
break
;
}
case
(
GUIEvents
::
DRAG
):
{
m_sigDrag
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButtonMask
()
);
handleDrag
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
),
ea
.
getButtonMask
()
);
break
;
}
case
(
GUIEvents
::
MOVE
):
{
m_sigMove
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
)
);
handleMove
(
WVector2f
(
ea
.
getX
(),
ea
.
getY
()
)
);
break
;
}
case
(
GUIEvents
::
KEYDOWN
):
{
m_sigKeydown
(
ea
.
getKey
(),
ea
.
getModKeyMask
()
);
handleKeydown
(
ea
.
getKey
(),
ea
.
getModKeyMask
()
);
break
;
}
case
(
GUIEvents
::
KEYUP
):
{
m_sigKeyup
(
ea
.
getKey
(),
ea
.
getModKeyMask
()
);
handleKeyup
(
ea
.
getKey
(),
ea
.
getModKeyMask
()
);
break
;
}
case
(
GUIEvents
::
FRAME
):
// every frame triggered!
{
m_sigFrame
();
handleFrame
();
break
;
}
case
(
GUIEvents
::
RESIZE
):
{
m_sigResize
(
ea
.
getWindowX
(),
ea
.
getWindowY
(),
ea
.
getWindowWidth
(),
ea
.
getWindowHeight
()
);
handleResize
(
ea
.
getWindowX
(),
ea
.
getWindowY
(),
ea
.
getWindowWidth
(),
ea
.
getWindowHeight
()
);
break
;
}
case
(
GUIEvents
::
SCROLL
):
{
m_sigScroll
(
ea
.
getScrollingMotion
(),
ea
.
getScrollingDeltaX
(),
ea
.
getScrollingDeltaY
()
);
handleScroll
(
ea
.
getScrollingMotion
(),
ea
.
getScrollingDeltaX
(),
ea
.
getScrollingDeltaY
()
);
break
;
}
case
(
GUIEvents
::
PEN_PRESSURE
):
{
m_sigPenPressure
(
ea
.
getPenPressure
()
);
handlePenPressure
(
ea
.
getPenPressure
()
);
break
;
}
case
(
GUIEvents
::
PEN_ORIENTATION
):
{
m_sigPenOrientation
(
ea
.
getPenOrientation
()
);
handlePenOrientation
(
ea
.
getPenOrientation
()
);
break
;
}
case
(
GUIEvents
::
PEN_PROXIMITY_ENTER
):
{
m_sigPenProximityEnter
();
handlePenProximityEnter
();
break
;
}
case
(
GUIEvents
::
PEN_PROXIMITY_LEAVE
):
{
m_sigPenProximityLeave
();
handlePenProximityLeave
();
break
;
}
case
(
GUIEvents
::
CLOSE_WINDOW
):
{
m_sigCloseWindow
();
handleCloseWindow
();
break
;
}
case
(
GUIEvents
::
QUIT_APPLICATION
):
{
m_sigQuitApplication
();
handleQuitApplication
();
break
;
}
case
(
GUIEvents
::
USER
):
{
m_sigUser
();
handleUser
();
break
;
}
default:
errorLog
()
<<
"Unkown GUI Event: "
<<
et
;
return
false
;
}
return
true
;
}
return
false
;
// There was no subscription to this event
}
wlog
::
WStreamedLogger
WCustomWidgetEventHandler
::
errorLog
()
const
{
return
wlog
::
error
(
"CustomWidgetEventHandler"
)
<<
m_widget
->
getTitle
()
<<
": "
;
}
void
WCustomWidgetEventHandler
::
subscribePush
(
ButtonSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
PUSH
;
m_sigPush
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeRelease
(
ButtonSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
RELEASE
;
m_sigRelease
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeDoubleclick
(
ButtonSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
DOUBLECLICK
;
m_sigDoubleclick
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeDrag
(
DragSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
DRAG
;
m_sigDrag
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeMove
(
MoveSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
MOVE
;
m_sigMove
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeFrame
(
TriggerSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
FRAME
;
m_sigFrame
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeKeydown
(
KeySignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
KEYDOWN
;
m_sigKeydown
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeKeyup
(
KeySignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
KEYUP
;
m_sigKeyup
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeResize
(
ResizeSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
RESIZE
;
m_sigResize
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeScroll
(
ScrollSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
SCROLL
;
m_sigScroll
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribePenPressure
(
PenPressureSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
PEN_PRESSURE
;
m_sigPenPressure
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribePenOrientation
(
PenOrientationSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
PEN_ORIENTATION
;
m_sigPenOrientation
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribePenProximityEnter
(
TriggerSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
PEN_PROXIMITY_ENTER
;
m_sigPenProximityEnter
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribePenProximityLeave
(
TriggerSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
PEN_PROXIMITY_LEAVE
;
m_sigPenProximityLeave
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeCloseWindow
(
TriggerSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
CLOSE_WINDOW
;
m_sigCloseWindow
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeQuitApplication
(
TriggerSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
QUIT_APPLICATION
;
m_sigQuitApplication
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
subscribeUser
(
TriggerSignalType
::
slot_type
slot
)
{
m_preselection
|=
GUIEvents
::
USER
;
m_sigUser
.
connect
(
slot
);
}
void
WCustomWidgetEventHandler
::
handlePush
(
WVector2f
/* mousePos */
,
int
/* button */
)
{
}
void
WCustomWidgetEventHandler
::
handleRelease
(
WVector2f
/* mousePos */
,
int
/* button */
)
{
}
void
WCustomWidgetEventHandler
::
handleDoubleclick
(
WVector2f
/* mousePos */
,
int
/* button */
)
{
}
void
WCustomWidgetEventHandler
::
handleDrag
(
WVector2f
/* mousePos */
,
int
/* buttonMask */
)
{
}
void
WCustomWidgetEventHandler
::
handleMove
(
WVector2f
/* mousePos */
)
{
}
void
WCustomWidgetEventHandler
::
handleKeydown
(
int
/* keyID */
,
unsigned
int
/* modKeyMask */
)
{
}
void
WCustomWidgetEventHandler
::
handleKeyup
(
int
/* keyID */
,
unsigned
int
/* modKeyMask */
)
{
}
void
WCustomWidgetEventHandler
::
handleFrame
()
{
}
void
WCustomWidgetEventHandler
::
handleResize
(
int
/* xPos */
,
int
/* yPos */
,
int
/* width */
,
int
/* height */
)
{
}
void
WCustomWidgetEventHandler
::
handleScroll
(
GUIEvents
::
ScrollingMotion
/* motion */
,
float
/* deltaX */
,
float
/* deltaY */
)
{
}
void
WCustomWidgetEventHandler
::
handlePenPressure
(
float
/* pressure */
)
{
}
void
WCustomWidgetEventHandler
::
handlePenOrientation
(
const
osg
::
Matrix
/* orientation */
)
{
}
void
WCustomWidgetEventHandler
::
handlePenProximityEnter
()
{
}
void
WCustomWidgetEventHandler
::
handlePenProximityLeave
()
{
}
void
WCustomWidgetEventHandler
::
handleCloseWindow
()
{
}
void
WCustomWidgetEventHandler
::
handleQuitApplication
()
{
}
void
WCustomWidgetEventHandler
::
handleUser
()
{
}
src/core/gui/WCustomWidgetEventHandler.h
0 → 100644
View file @
f6c53650
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WCUSTOMWIDGETEVENTHANDLER_H
#define WCUSTOMWIDGETEVENTHANDLER_H
#include <boost/signals2/signal.hpp>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIEventHandler>
#include "../common/math/linearAlgebra/WVectorFixed.h"
#include "../common/WLogger.h"
#include "WCustomWidget.h"
/**
* An event handler for a custom widget which eases interaction with GUIEvents within your module. Without you need to write your
* own event handler and register it. However if you still need your own event handler you might consider subclassing from this
* one. Basically there are two ways of getting notified of GUIEvents. First you can connect a member function to events or you
* can overwrite member functions of this class to handle specific events.
*
* Use boost::bind and the subscribeXY methods to connect a member function of your module to a specific GUIEvent. Please note
* that this is now called in context of the GUI thread and that you need to take care of threadsafety by yourself.
*
* Use the corresponding handleXY() member functions if you still need a custom event handler. But take care that you may need to
* set the WCustomWidgetEventHandler::m_preselection event-mask accordingly within the constructor then.
*
* In case you might not know what the specific parameters of the handle function represent you might have luck looking into the
* OpenSceneGraph documentation http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs within the GUIEventAdapter
* class.
*/
class
WCustomWidgetEventHandler
:
public
osgGA
::
GUIEventHandler
{
public:
/**
* Constructor.
*
* \param widget The custom widget for which events should be handled.
*/
explicit
WCustomWidgetEventHandler
(
WCustomWidget
::
SPtr
widget
);
/**
* The OSG calls this function whenever a new event has occured.
*
* \param ea Event class for storing GUI events such as mouse or keyboard interation etc.
*
* \return true if the event was handled.
*/
bool
handle
(
const
osgGA
::
GUIEventAdapter
&
ea
,
osgGA
::
GUIActionAdapter
&
/* aa */
);
/**
* Short hand type for signal signature of PUSH, RELEASE and DOUBLECLICK event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
WVector2f
,
int
)
>
ButtonSignalType
;
/**
* Short hand type for signal signature of DRAG event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
WVector2f
,
unsigned
int
)
>
DragSignalType
;
/**
* Short hand type for signal signature of MOVE event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
WVector2f
)
>
MoveSignalType
;
/**
* Short hand type for signal signature of SCROLL event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
GUIEvents
::
ScrollingMotion
,
float
,
float
)
>
ScrollSignalType
;
/**
* Short hand type for signal signature of FRAME, PEN_PROXIMITY_ENTER, -LEAVE, CLOSE_WINDOW, QUIT_APPLICATION and USER event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
void
)
>
TriggerSignalType
;
/**
* Short hand type for signal signature of KEYDOWN and KEYUP event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
int
,
unsigned
int
)
>
KeySignalType
;
/**
* Short hand type for signal signature of RESIZE event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
int
,
int
,
int
,
int
)
>
ResizeSignalType
;
/**
* Short hand type for signal signature of PEN_PRESSURE event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
float
)
>
PenPressureSignalType
;
/**
* Short hand type for signal signature of PEN_ORIENTATION event.
*/
typedef
boost
::
signals2
::
signal
<
void
(
const
osg
::
Matrix
)
>
PenOrientationSignalType
;
/**
* Registers a function slot to PUSH events. Whenever the event occurs, the slot is called with current parameters.
*
* \param slot Function object having the appropriate signature according to the used SignalType.
*/
virtual
void
subscribePush
(
ButtonSignalType
::
slot_type
slot
);
/**
* Registers a function slot to RELEASE events. Whenever the event occurs, the slot is called with current parameters.
* \copydetails subscribePush()
*/
virtual
void
subscribeRelease
(
ButtonSignalType
::
slot_type
slot
);
/**
* Registers a function slot to DOUBLECLICK events.
* \copydetails subscribePush()
*/
virtual
void
subscribeDoubleclick
(
ButtonSignalType
::
slot_type
slot
);
/**
* Registers a function slot to DRAG events.
* \copydetails subscribePush()
*/
virtual
void
subscribeDrag
(
DragSignalType
::
slot_type
slot
);
/**
* Registers a function slot to MOVE events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribeMove
(
MoveSignalType
::
slot_type
slot
);
/**
* Registers a function slot to KEYDOWN events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribeKeydown
(
KeySignalType
::
slot_type
slot
);
/**
* Registers a function slot to KEYUP events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribeKeyup
(
KeySignalType
::
slot_type
slot
);
/**
* Registers a function slot to FRAME events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribeFrame
(
TriggerSignalType
::
slot_type
);
/**
* Registers a function slot to RESIZE events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribeResize
(
ResizeSignalType
::
slot_type
slot
);
/**
* Registers a function slot to SCROLL events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribeScroll
(
ScrollSignalType
::
slot_type
slot
);
/**
* Registers a function slot to PEN_PRESSURE events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribePenPressure
(
PenPressureSignalType
::
slot_type
slot
);
/**
* Registers a function slot to PEN_ORIENTATION events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribePenOrientation
(
PenOrientationSignalType
::
slot_type
slot
);
/**
* Registers a function slot to PEN_PROXIMITY_ENTER events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribePenProximityEnter
(
TriggerSignalType
::
slot_type
slot
);
/**
* Registers a function slot to PEN_PROXIMITY_LEAVE events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribePenProximityLeave
(
TriggerSignalType
::
slot_type
slot
);
/**
* Registers a function slot to CLOSE_WINDOW events.
*
* \copydetails subscribePush()
*/
virtual
void
subscribeCloseWindow
(
TriggerSignalType
::
slot_type
slot
);
/**
* Registers a function slot to QUIT_APPLICATION events.
* \copydetails subscribePush()
*/
virtual
void
subscribeQuitApplication
(
TriggerSignalType
::
slot_type
slot
);
/**
* Registers a function slot to USER events.
* \copydetails subscribePush()
*/
virtual
void
subscribeUser
(
TriggerSignalType
::
slot_type
slot
);
/**
* Called whenever the PUSH event occurs.
*
* \param mousePos Current mouse position in X and Y.
* \param button The involved mouse button. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs
* GUIEventAdapter class for values.
*/
virtual
void
handlePush
(
WVector2f
mousePos
,
int
button
);
/**
* Called whenever the RELEASE event occurs.
* \copydetails handlePush()
*/
virtual
void
handleRelease
(
WVector2f
mousePos
,
int
button
);
/**
* Called whenever the DOUBLECLICK event occurs.
* \copydetails handlePush()
*/
virtual
void
handleDoubleclick
(
WVector2f
mousePos
,
int
button
);
/**
* Called whenever the DRAG event occurs.
*
* \param mousePos Current mouse position in X and Y.
* \param buttonMask The pushed mouse buttons as a mask. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs
* GUIEventAdapter class for values.
*/
virtual
void
handleDrag
(
WVector2f
mousePos
,
int
buttonMask
);
/**
* Called whenever the MOVE event occurs.
*
* \param mousePos Current mouse position in X and Y.
*/
virtual
void
handleMove
(
WVector2f
mousePos
);
/**
* Called whenever the KEYDOWN event occurs.
*
* \param keyID The pressed key. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs GUIEventAdapter
* class for values.
* \param modKeyMask Additional function keys pressed.
*/
virtual
void
handleKeydown
(
int
keyID
,
unsigned
int
modKeyMask
);
/**
* Called whenever the KEYUP event occurs.
*
* \param keyID The released key. See http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs GUIEventAdapter
* class for values.
* \param modKeyMask Additional function keys pressed.
*/
virtual
void
handleKeyup
(
int
keyID
,
unsigned
int
modKeyMask
);