DART  6.7.3
dart::gui::osg::DefaultEventHandler Class Reference

#include <DefaultEventHandler.hpp>

Inheritance diagram for dart::gui::osg::DefaultEventHandler:
dart::common::Subject dart::common::Observer

Public Member Functions

 DefaultEventHandler (Viewer *_viewer)
 Constructor takes in a pointer to a viewer. More...
 
virtual ~DefaultEventHandler ()
 Destructor. More...
 
MouseButtonEvent getButtonEvent (MouseButton button) const
 Returns the last event performed by a mouse button. More...
 
int getModKeyMask () const
 Returns the last modkey mask. More...
 
double getWindowCursorX () const
 Get the last x value of the cursor in Window coordinates. More...
 
double getWindowCursorY () const
 Get the last y value of the cursor in Window coordinates. More...
 
Eigen::Vector3d getDeltaCursor (const Eigen::Vector3d &_fromPosition, ConstraintType _constraint=UNCONSTRAINED, const Eigen::Vector3d &_constraintVector=Eigen::Vector3d::UnitZ()) const
 Get the change change in the cursor position with respect to some previous location in the world (_fromPosition). More...
 
void getNearAndFarPointUnderCursor (Eigen::Vector3d &near, Eigen::Vector3d &far, double distance=1.0) const
 Get two points that are under the current cursor position. More...
 
const std::vector< PickInfo > & getButtonPicks (MouseButton button, MouseButtonEvent event) const
 Get the most recent picks for the specified button and event type. More...
 
const std::vector< PickInfo > & getMovePicks () const
 Get the most recent picks for a mouse movement (click-and-drag actions do not qualify as movements) More...
 
void suppressButtonPicks (MouseButton button, MouseButtonEvent event)
 Suppress pick detection for the specified button event. More...
 
void suppressMovePicks ()
 Suppress pick detection for mouse movements. More...
 
void activateButtonPicks (MouseButton button, MouseButtonEvent event)
 Activate pick detection for the specified button event (on by default) More...
 
void activateMovePicks ()
 Activate pick detection for mouse movements (on by default) More...
 
void pick (std::vector< PickInfo > &infoVector, const ::osgGA::GUIEventAdapter &ea)
 Detect picks TODO(MXG): Consider putting this functionality in a more accessible place. More...
 
void addMouseEventHandler (MouseEventHandler *handler)
 Add a MouseEventHandler that will get invoked whenever a mouse event occurs. More...
 
const std::set< MouseEventHandler * > & getMouseEventHandlers () const
 Get the list of MouseEventHandlers that are currently held by this DefaultEventHandler. More...
 
bool handle (const ::osgGA::GUIEventAdapter &ea, ::osgGA::GUIActionAdapter &) override
 Handle incoming user input. More...
 

Protected Member Functions

void triggerMouseEventHandlers ()
 Calls update on all MouseEventHandlers. More...
 
void eventPick (const ::osgGA::GUIEventAdapter &ea)
 Gather current picks and assign them to the latest event. More...
 
void clearButtonEvents ()
 Clear out the current button events. More...
 
void handleDestructionNotification (const dart::common::Subject *_subject) override
 Called by receiveDestructionNotification(). More...
 
void sendDestructionNotification () const
 Send a destruction notification to all Observers. More...
 
void addObserver (Observer *_observer) const
 Add an Observer to the list of Observers. More...
 
void removeObserver (Observer *_observer) const
 Remove an Observer from the list of Observers. More...
 
void receiveDestructionNotification (const Subject *_subject)
 Called whenever a Subject is destroyed (or sends out a destruction notification). More...
 
void addSubject (const Subject *_subject)
 Add a Subject for this Observer. More...
 
void removeSubject (const Subject *_subject)
 Remove a Subject from this Observer. More...
 
void removeAllSubjects ()
 Remove all Subjects from this Observer. More...
 

Protected Attributes

ViewermViewer
 dart::gui::osg::Viewer that this event handler is tied to More...
 
std::set< MouseEventHandler * > mMouseEventHandlers
 Set of MouseEventHandlers that are tied to this DefaultEventHandler. More...
 
std::vector< PickInfomButtonPicks [NUM_MOUSE_BUTTONS][BUTTON_NOTHING]
 The objects that were under the cursor during the last button event. More...
 
bool mSuppressButtonPicks [NUM_MOUSE_BUTTONS][BUTTON_NOTHING]
 Suppress pick detection. More...
 
std::vector< PickInfomMovePicks
 The objects that were under the cursor during the last move. More...
 
bool mSuppressMovePicks
 Suppress pick detection for moves. More...
 
std::vector< PickInfomTempPicks
 Cache for pick data. More...
 
MouseButtonEvent mLastButtonEvent [NUM_MOUSE_BUTTONS]
 The last mouse event that was registered by the event handler. More...
 
Eigen::Vector2d mLastCursorPosition
 X/Y values of the cursor (in the window coordinates) during the last mouse event. More...
 
int mLastModKeyMask
 Storage for the last modkey mask. More...
 
std::set< Observer * > mObservers
 List of current Observers. More...
 
std::set< const Subject * > mSubjects
 List of current Subjects for this Observer. More...
 

Constructor & Destructor Documentation

◆ DefaultEventHandler()

dart::gui::osg::DefaultEventHandler::DefaultEventHandler ( Viewer _viewer)
explicit

Constructor takes in a pointer to a viewer.

◆ ~DefaultEventHandler()

dart::gui::osg::DefaultEventHandler::~DefaultEventHandler ( )
virtual

Destructor.

Member Function Documentation

◆ activateButtonPicks()

void dart::gui::osg::DefaultEventHandler::activateButtonPicks ( MouseButton  button,
MouseButtonEvent  event 
)

Activate pick detection for the specified button event (on by default)

◆ activateMovePicks()

void dart::gui::osg::DefaultEventHandler::activateMovePicks ( )

Activate pick detection for mouse movements (on by default)

◆ addMouseEventHandler()

void dart::gui::osg::DefaultEventHandler::addMouseEventHandler ( MouseEventHandler handler)

Add a MouseEventHandler that will get invoked whenever a mouse event occurs.

You never need to worry about removing a MouseEventHandler from a DefaultEventHandler, because it will get removed automatically upon deletion

◆ addObserver()

void dart::common::Subject::addObserver ( Observer _observer) const
protectedinherited

Add an Observer to the list of Observers.

◆ addSubject()

void dart::common::Observer::addSubject ( const Subject _subject)
protectedinherited

Add a Subject for this Observer.

◆ clearButtonEvents()

void dart::gui::osg::DefaultEventHandler::clearButtonEvents ( )
protected

Clear out the current button events.

◆ eventPick()

void dart::gui::osg::DefaultEventHandler::eventPick ( const ::osgGA::GUIEventAdapter &  ea)
protected

Gather current picks and assign them to the latest event.

◆ getButtonEvent()

MouseButtonEvent dart::gui::osg::DefaultEventHandler::getButtonEvent ( MouseButton  button) const

Returns the last event performed by a mouse button.

◆ getButtonPicks()

const std::vector< PickInfo > & dart::gui::osg::DefaultEventHandler::getButtonPicks ( MouseButton  button,
MouseButtonEvent  event 
) const

Get the most recent picks for the specified button and event type.

◆ getDeltaCursor()

Eigen::Vector3d dart::gui::osg::DefaultEventHandler::getDeltaCursor ( const Eigen::Vector3d &  _fromPosition,
ConstraintType  _constraint = UNCONSTRAINED,
const Eigen::Vector3d &  _constraintVector = Eigen::Vector3d::UnitZ() 
) const

Get the change change in the cursor position with respect to some previous location in the world (_fromPosition).

For the unconstrained case, this change is projected onto a plane parallel to the camera's orientation.

If _constraint is set to LINE_CONSTRAINT, the change in cursor position will be constrained to a line that passes through _fromPosition with a slope of _constraintVector.

If _constraint is set to PLANE_CONSTRAINT, the change in cursor position will be constrained to a plane that passes through _fromPosition with a normal vector of _constraintVector.

◆ getModKeyMask()

int dart::gui::osg::DefaultEventHandler::getModKeyMask ( ) const

Returns the last modkey mask.

◆ getMouseEventHandlers()

const std::set< MouseEventHandler * > & dart::gui::osg::DefaultEventHandler::getMouseEventHandlers ( ) const

Get the list of MouseEventHandlers that are currently held by this DefaultEventHandler.

◆ getMovePicks()

const std::vector< PickInfo > & dart::gui::osg::DefaultEventHandler::getMovePicks ( ) const

Get the most recent picks for a mouse movement (click-and-drag actions do not qualify as movements)

◆ getNearAndFarPointUnderCursor()

void dart::gui::osg::DefaultEventHandler::getNearAndFarPointUnderCursor ( Eigen::Vector3d &  near,
Eigen::Vector3d &  far,
double  distance = 1.0 
) const

Get two points that are under the current cursor position.

The near point will be inside the plane of the camera. The far point will have the given distance from the plane of the camera (default is 1.0).

◆ getWindowCursorX()

double dart::gui::osg::DefaultEventHandler::getWindowCursorX ( ) const

Get the last x value of the cursor in Window coordinates.

◆ getWindowCursorY()

double dart::gui::osg::DefaultEventHandler::getWindowCursorY ( ) const

Get the last y value of the cursor in Window coordinates.

◆ handle()

bool dart::gui::osg::DefaultEventHandler::handle ( const ::osgGA::GUIEventAdapter &  ea,
::osgGA::GUIActionAdapter &   
)
override

Handle incoming user input.

◆ handleDestructionNotification()

void dart::gui::osg::DefaultEventHandler::handleDestructionNotification ( const dart::common::Subject _subject)
overrideprotectedvirtual

Called by receiveDestructionNotification().

Override this function to customize your class's response to destruction notifications.

Reimplemented from dart::common::Observer.

◆ pick()

void dart::gui::osg::DefaultEventHandler::pick ( std::vector< PickInfo > &  infoVector,
const ::osgGA::GUIEventAdapter &  ea 
)

Detect picks TODO(MXG): Consider putting this functionality in a more accessible place.

◆ receiveDestructionNotification()

void dart::common::Observer::receiveDestructionNotification ( const Subject _subject)
protectedinherited

Called whenever a Subject is destroyed (or sends out a destruction notification).

Override handleDestructionNotification() in order to customize your class's response to destruction notifications.

◆ removeAllSubjects()

void dart::common::Observer::removeAllSubjects ( )
protectedinherited

Remove all Subjects from this Observer.

◆ removeObserver()

void dart::common::Subject::removeObserver ( Observer _observer) const
protectedinherited

Remove an Observer from the list of Observers.

◆ removeSubject()

void dart::common::Observer::removeSubject ( const Subject _subject)
protectedinherited

Remove a Subject from this Observer.

◆ sendDestructionNotification()

void dart::common::Subject::sendDestructionNotification ( ) const
protectedinherited

Send a destruction notification to all Observers.

This will cause all Observers to behave as if this Subject has been permanently deleted, so it should only be called when that behavior is desired.

◆ suppressButtonPicks()

void dart::gui::osg::DefaultEventHandler::suppressButtonPicks ( MouseButton  button,
MouseButtonEvent  event 
)

Suppress pick detection for the specified button event.

◆ suppressMovePicks()

void dart::gui::osg::DefaultEventHandler::suppressMovePicks ( )

Suppress pick detection for mouse movements.

◆ triggerMouseEventHandlers()

void dart::gui::osg::DefaultEventHandler::triggerMouseEventHandlers ( )
protected

Calls update on all MouseEventHandlers.

Member Data Documentation

◆ mButtonPicks

std::vector<PickInfo> dart::gui::osg::DefaultEventHandler::mButtonPicks[NUM_MOUSE_BUTTONS][BUTTON_NOTHING]
protected

The objects that were under the cursor during the last button event.

◆ mLastButtonEvent

MouseButtonEvent dart::gui::osg::DefaultEventHandler::mLastButtonEvent[NUM_MOUSE_BUTTONS]
protected

The last mouse event that was registered by the event handler.

◆ mLastCursorPosition

Eigen::Vector2d dart::gui::osg::DefaultEventHandler::mLastCursorPosition
protected

X/Y values of the cursor (in the window coordinates) during the last mouse event.

◆ mLastModKeyMask

int dart::gui::osg::DefaultEventHandler::mLastModKeyMask
protected

Storage for the last modkey mask.

◆ mMouseEventHandlers

std::set<MouseEventHandler*> dart::gui::osg::DefaultEventHandler::mMouseEventHandlers
protected

Set of MouseEventHandlers that are tied to this DefaultEventHandler.

◆ mMovePicks

std::vector<PickInfo> dart::gui::osg::DefaultEventHandler::mMovePicks
protected

The objects that were under the cursor during the last move.

◆ mObservers

std::set<Observer*> dart::common::Subject::mObservers
mutableprotectedinherited

List of current Observers.

◆ mSubjects

std::set<const Subject*> dart::common::Observer::mSubjects
protectedinherited

List of current Subjects for this Observer.

◆ mSuppressButtonPicks

bool dart::gui::osg::DefaultEventHandler::mSuppressButtonPicks[NUM_MOUSE_BUTTONS][BUTTON_NOTHING]
protected

Suppress pick detection.

◆ mSuppressMovePicks

bool dart::gui::osg::DefaultEventHandler::mSuppressMovePicks
protected

Suppress pick detection for moves.

◆ mTempPicks

std::vector<PickInfo> dart::gui::osg::DefaultEventHandler::mTempPicks
protected

Cache for pick data.

◆ mViewer

Viewer* dart::gui::osg::DefaultEventHandler::mViewer
protected

dart::gui::osg::Viewer that this event handler is tied to