12.1. 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.

  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.

Example 12.1, “ SoDragGestureEvent.h shows the code for the drag gesture event include file.

Example 12.1.  SoDragGestureEvent.h

#include <Inventor/events/SoSubEvent.h>
#include <Inventor/gestures/events/SoGestureEvent.h>

class INVENTOR_API SoDragGestureEvent : public SoGestureEvent {

public :
  virtual ~SoDragGestureEvent();
  SbVec2f getDraggedDistance() const;

SoINTERNAL public:
  static void initClass();
  static void exitClass();
  void setDraggedDistance(SbVec2f r);

private :
  SbVec2f m_draggedDistance;