Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
Creating a Gesture Event

This section describes creating a new gesture event. It describes the steps to recognize a drag gesture and release the corresponding event.

The SO_EVENT_HEADER() macro declares type identifiers and naming variables and methods that all event classes must support.

Creating the new gesture event requires these steps:

  1. Create new gesture event class and derive it from SoGestureEvent.
  2. Define an initClass() and exitClass(). Use the SO_EVENT_INIT_CLASS() macro in initClass and SO_EVENT_EXIT_CLASS in exitClass().
  3. Define a constructor and destructor.
  4. Implement set() and get() methods for the additional information. In our case, SoDragGestureEvent contains the dragged distance. User just needs to know this vector and not to modify its value. SoDragGestureEvent.h shows the code for the drag gesture event include file.

Example : SoDragGestureEvent.h

#include <Inventor/events/SoSubEvent.h>
#include <Inventor/gestures/events/SoGestureEvent.h>
class SoDragGestureEvent : public SoGestureEvent
{
SO_EVENT_HEADER();
public:
SoDragGestureEvent();
virtual ~SoDragGestureEvent();
SbVec2f getDraggedDistance() const;
private: static void initClass();
static void exitClass();
void setDraggedDistance( SbVec2f r );
private:
SbVec2f m_draggedDistance;
};