NVidia Gameworks
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

NvGestureEvent.h

Go to the documentation of this file.
00001 // TAGRELEASE: PUBLIC
00002 
00003 #ifndef __EVENT_H_
00004 #define __EVENT_H_
00005 
00006 #include <NvFoundation.h>
00007 
00013 /* a predefined value for an invalid gesture UID. */
00014 #define NV_GESTURE_UID_INVALID              0xFFFFFFFF
00015 #define NV_GESTURE_UID_MAX                  0xFFFFEEEE
00016 typedef uint32_t NvGestureUID;
00017 
00018 // mouse/stylus (accurate) vs finger (inaccurate).
00019 // these are used as array indices + max size!
00024 struct NvInputEventClass {
00025     enum Enum {
00026         NONE = 0, 
00027         MOUSE, 
00028         TOUCH, 
00029         STYLUS,  
00030     };
00031 };
00032 
00034 struct NvInputEventType {
00035     enum Enum {
00036         HOVER = 0, 
00037         DOWN, 
00038         MOVE, 
00039         UP, 
00040     };
00041 };
00042 
00043 
00044 /* this says we're building the system with "MAYBE" gesture support */
00045 #define HANDLE_MAYBE_GESTURES
00046 /* this says we're building the system with 'plus' support
00047     which means that events from maybe->press==press_plus */
00048 //#define HANDLE_PLUS_GESTURES
00049 
00050 
00052 struct NvGestureKind {
00053     enum Enum
00054     {
00057         MASK_BASE =           0x00FF, 
00058         MASK_HELD =           0x0100, 
00059         MASK_RELEASED =       0x0200, 
00060         MASK_MOVED =          0x0400, 
00061         MASK_MULTI =          0x0800, 
00062 #ifdef HANDLE_MAYBE_GESTURES
00063         MASK_MAYBE =          0x1000, 
00064 #endif
00065         MASK_REPEAT_DOUBLE =  0x2000, 
00066         MASK_REPEAT_TRIPLE =  0x4000, 
00072         INVALID          = -1,
00073 
00075         NONE             = 0,
00077         HOVER            = 1,
00079         PRESS            = 3,
00081         HOLD             = 4 | MASK_HELD, 
00082         // !!!!TBD TODO: possible addition, the pointer being kept down even longer */
00083         // /** Pointer has been kept down past a longer timeout */
00084         // LONG_HOLD      = 5, 
00086         RELEASE          = 6 | MASK_RELEASED,
00087 
00088     #ifdef HANDLE_MAYBE_GESTURES
00089 
00090         MAYBE_TAP        = 8 | MASK_RELEASED | MASK_MAYBE,
00091     #endif
00092 
00093         TAP              = 9 | MASK_RELEASED, 
00095         DRAG             = 10 | MASK_MOVED,
00097         FLICK            = 11 | MASK_MOVED | MASK_RELEASED,
00098 
00099     #ifdef HANDLE_PLUS_GESTURES
00100 
00101         TAP_PLUS_PRESS   = 12, /* this is an 'extended' gesture, off of prior one. */
00102     #endif
00103      /*
00105         //these "tap-plus" gestures are all TBD.
00106         TAP_HOLD         = 16 | MASK_HELD,
00107         TAP_DRAG         = 17 | MASK_MOVED,
00108      */
00110         DOUBLETAP        = TAP | MASK_REPEAT_DOUBLE,
00111     /*
00113         TRIPLETAP        = TAP | MASK_REPEAT_TRIPLE,
00114     */
00115     #if HANDLE_MULTI_GESTURES
00116         /* !!!!TBD TODO: a tap with multiple fingers at once */
00117         MULTI_TAP        = TAP | MASK_MULTI,
00118         /* !!!!TBD TODO: a pinch/zoom of two fingers coming together, or spreading apart
00119          * (note I declared it drag+multi for convenience, it will likely
00120          * want/need to change it before locking in the specification) */
00121         MULTI_ZOOM       = DRAG | MASK_MULTI,
00122     #endif
00123 
00124     };
00125 };
00126 
00127 //typedef uint16_t NvGestureKindSlot;
00128 
00130 class NvGestureEvent
00131 {
00132 public:
00133     NvGestureUID uid; 
00134     NvGestureKind::Enum kind; 
00135         NvInputEventClass::Enum type; 
00137     /* new fields, matching the user input struct, for button index and other flags */
00138     uint8_t    index; 
00139     //uint8_t    flags;
00140     
00141     float   x; 
00142     float   y; 
00144     /* these are overloaded, different gestures will interpret as different values.
00145         could be things like:
00146          * DRAG: delta position
00147          * FLICK: velocities
00148          * ZOOM: second finger */
00149     float   dx; 
00150     float   dy; 
00152     /* no timestamp embedded at the moment.  does anyone need it?  could do a
00153      *  8.8 fixedpoint elapsed seconds dt or something like that. */
00154 
00161         NvGestureEvent(NvInputEventClass::Enum intype, NvGestureKind::Enum inkind, float inx, float iny)
00162         {
00163         if (inkind == NvGestureKind::PRESS) // change UID only at press
00164                 uid = InternalGetNextUID();
00165         else // keep existing ID
00166             uid = lastID;
00167                 kind = inkind;
00168                 type = intype;
00169                 index = 0;
00170                 //flags = 0;
00171                 x = inx;
00172                 y = iny;
00173                 dx = 0;
00174                 dy = 0;
00175         };
00176 
00177 private:
00178         static NvGestureUID lastID;
00179 
00180         static NvGestureUID InternalGetNextUID()
00181         {
00182                 lastID++;
00183                 if (lastID > NV_GESTURE_UID_MAX) // some arbitrary cap...
00184                         lastID = 1; // do NOT reset to 0, it's special...
00185                 return lastID;
00186         };
00187 };
00188 
00189 #endif 
00190 
Generated on Sat Mar 8 14:58:35 2014 for NVIDIA GameWorks OpenGL App Framework and Libraries by Doxygen
©2014 NVIDIA Corporation.