![]() |
http://www.sim.no http://www.coin3d.org |
Use SoEventCallback nodes in the scenegraph for catching user interaction events with the scenegraph's render canvas. More...
#include <Inventor/nodes/SoEventCallback.h>
Public Member Functions | |
virtual SoType | getTypeId (void) const |
SoEventCallback (void) | |
void | setPath (SoPath *path) |
const SoPath * | getPath (void) |
void | addEventCallback (SoType eventtype, SoEventCallbackCB *f, void *userdata=NULL) |
void | removeEventCallback (SoType eventtype, SoEventCallbackCB *f, void *userdata=NULL) |
SoHandleEventAction * | getAction (void) const |
const SoEvent * | getEvent (void) const |
const SoPickedPoint * | getPickedPoint (void) const |
void | setHandled (void) |
SbBool | isHandled (void) const |
void | grabEvents (void) |
void | releaseEvents (void) |
Static Public Member Functions | |
static SoType | getClassTypeId (void) |
static void | initClass (void) |
Protected Member Functions | |
virtual const SoFieldData * | getFieldData (void) const |
virtual | ~SoEventCallback () |
virtual void | handleEvent (SoHandleEventAction *action) |
Static Protected Member Functions | |
static const SoFieldData ** | getFieldDataPtr (void) |
Use SoEventCallback nodes in the scenegraph for catching user interaction events with the scenegraph's render canvas.
This is how event handling works in Coin: when the user interacts with the render canvas, for instance by using the mouse pointer or by hitting the keyboard, the GUI interface toolkit (ie SoQt, SoWin, SoXt, Sc21 ...) will catch the event and translate it from a windowsystem-specific event to a generic Coin event. (For the types of generic Coin events, see the classes derived from SoEvent.) This event will then be wrapped inside a SoHandleEventAction and applied to the scenegraph. All this happens within the So[Qt|Xt|Win|...] toolkit.
The SoHandleEventAction then traverses the scenegraph, delivering the event to any node type which "is interested" in it. The SoEventCallback nodetype catches the action and forwards the event to a callback function set up by the application programmer.
Be careful about which position in the scenegraph you insert SoEventCallback nodes if you are also using any of the built-in Coin library elements which are interested in user interaction events (like for instance the dragger and manipulator classes and the SoSelection nodes). These Coin elements might catch the event for themselves, short-circuiting the SoHandleEventAction traversal so the event will never reach the SoEventCallback node(s) you insert.
FILE FORMAT/DEFAULTS:
EventCallback { }
SoEventCallback::SoEventCallback | ( | void | ) |
Constructor.
SoEventCallback::~SoEventCallback | ( | ) | [protected, virtual] |
Destructor.
References SoBase::unref().
SoType SoEventCallback::getClassTypeId | ( | void | ) | [static] |
SoType SoEventCallback::getTypeId | ( | void | ) | const [virtual] |
Returns the type identification of an object derived from a class inheriting SoBase. This is used for run-time type checking and "downward" casting.
Usage example:
void foo(SoNode * node) { if (node->getTypeId() == SoFile::getClassTypeId()) { SoFile * filenode = (SoFile *)node; // safe downward cast, knows the type } else if (node->getTypeId().isOfType(SoGroup::getClassTypeId())) { SoGroup * group = (SoGroup *)node; // safe downward cast, knows the type } }
For application programmers wanting to extend the library with new nodes, engines, nodekits, draggers or others: this method needs to be overridden in all subclasses. This is typically done as part of setting up the full type system for extension classes, which is usually accomplished by using the pre-defined macros available through for instance Inventor/nodes/SoSubNode.h (SO_NODE_INIT_CLASS and SO_NODE_CONSTRUCTOR for node classes), Inventor/engines/SoSubEngine.h (for engine classes) and so on.
For more information on writing Coin extensions, see the class documentation of the toplevel superclasses for the various class groups.
Implements SoBase.
const SoFieldData ** SoEventCallback::getFieldDataPtr | ( | void | ) | [static, protected] |
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
Reimplemented from SoNode.
const SoFieldData * SoEventCallback::getFieldData | ( | void | ) | const [protected, virtual] |
Returns a pointer to the class-wide field data storage object for this instance. If no fields are present, returns NULL
.
Reimplemented from SoFieldContainer.
void SoEventCallback::initClass | ( | void | ) | [static] |
Sets up initialization for data common to all instances of this class, like submitting necessary information to the Coin type system.
Reimplemented from SoNode.
void SoEventCallback::setPath | ( | SoPath * | pathptr | ) |
Sets the path that must be picked before the registered callbacks are invoked. If NULL
, callbacks will be invoked for every event that matches the callback event type.
References SoPath::copy(), SoBase::getRefCount(), SoDebugError::postWarning(), SoBase::ref(), and SoBase::unref().
const SoPath * SoEventCallback::getPath | ( | void | ) |
void SoEventCallback::addEventCallback | ( | SoType | eventtype, | |
SoEventCallbackCB * | f, | |||
void * | userdata = NULL | |||
) |
Set up a callback function f which will be invoked for the given eventtype. userdata will be given as the first argument to the function.
References SbList< Type >::append().
void SoEventCallback::removeEventCallback | ( | SoType | eventtype, | |
SoEventCallbackCB * | f, | |||
void * | userdata = NULL | |||
) |
Unregister the given callback function f.
References SbList< Type >::getLength(), SoDebugError::postWarning(), and SbList< Type >::remove().
SoHandleEventAction * SoEventCallback::getAction | ( | void | ) | const |
Returns the SoHandleEventAction instance currently traversing the scene graph with the SoEvent-derived event object.
const SoEvent * SoEventCallback::getEvent | ( | void | ) | const |
Returns a pointer to the event object which is currently being sent through the scenegraph.
If your application code handles the event, you probably want to call SoEventCallback::setHandled() to notify the SoHandleEventAction that it should stop traversing the scenegraph with the event.
References SoHandleEventAction::getEvent().
const SoPickedPoint * SoEventCallback::getPickedPoint | ( | void | ) | const |
Returns the picked point for the current handle event traversal.
This is obviously only related to events which can be considered "pick-style" events, like mousebutton presses.
References SoHandleEventAction::getPickedPoint().
void SoEventCallback::setHandled | ( | void | ) |
Use this method from a callback function to notify the node that the event has been handled.
The rest of the callbacks registered with the node will still be called, but further SoEventCallback nodes in the scene will not be notified about the event, neither will any other Coin elements in the scenegraph (like for instance SoDragger objects, SoSelection nodes or manipulators).
Since callbacks registered within the same SoEventCallback node will still be invoked after the event has been handled, it is likely that you should use SoEventCallback::isHandled() to check for this condition from your callback functions.
References SoDebugError::postWarning(), and SoHandleEventAction::setHandled().
SbBool SoEventCallback::isHandled | ( | void | ) | const |
Check whether or not the event from the SoHandleEventAction has been handled.
References SoHandleEventAction::isHandled(), and SoDebugError::postWarning().
void SoEventCallback::grabEvents | ( | void | ) |
Set up the node so all future events (until releaseEvents() is called) in Coin will be directly forwarded to this node.
References SoDebugError::postWarning(), and SoHandleEventAction::setGrabber().
void SoEventCallback::releaseEvents | ( | void | ) |
Do not grab event handling any more.
References SoDebugError::postWarning(), and SoHandleEventAction::releaseGrabber().
void SoEventCallback::handleEvent | ( | SoHandleEventAction * | action | ) | [protected, virtual] |
Invokes the registered callback functions.
Reimplemented from SoNode.
References SoPath::containsPath(), SoHandleEventAction::getEvent(), SbList< Type >::getLength(), SoPickedPoint::getPath(), SoHandleEventAction::getPickedPoint(), SoEvent::getTypeId(), SoType::isDerivedFrom(), and SoDebugError::postWarning().
Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.
Generated on Mon Feb 23 16:33:48 2009 for Coin by Doxygen. 1.5.8