HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UI_DeviceEvent.h
Go to the documentation of this file.
1 #ifndef __UI_DeviceEvent__
2 #define __UI_DeviceEvent__
3 
4 #include "UI_API.h"
5 
6 #include <RE/RE_IDType.h>
7 #include <SYS/SYS_Types.h>
8 #include <UT/UT_Array.h>
9 #include <UT/UT_StringHolder.h>
10 
11 #include "UI_EventType.h"
12 
13 /*
14  * The UI_DeviceEvent is a generic event structure which
15  * various input device drivers will generate as sub-classes
16  * of UI_EventGenerator.
17  */
18 
19 /*
20  * Note: these are flag bits since more than one button can be down:
21  */
22 #define UI_NO_BUTTON 0x0
23 #define UI_LEFT_BUTTON 0x01
24 #define UI_MIDDLE_BUTTON 0x02
25 #define UI_RIGHT_BUTTON 0x04
26 
27 #define UI_ALT_KEY 0x0001 //
28 #define UI_SHIFT_KEY 0x0002 //
29 #define UI_CTRL_KEY 0x0004 //
30 #define UI_COMMAND_KEY 0x0008 // Windows key on Win/Linux
31 #define UI_META_KEYS (UI_ALT_KEY| \
32  UI_SHIFT_KEY| \
33  UI_CTRL_KEY| \
34  UI_COMMAND_KEY)
35 #define UI_ALPHASHIFT_KEY 0x0010 // Caps-lock
36 #define UI_AUTOREPEAT 0x0020 // Auto-repeat is on for the key
37 #define UI_IME_PREEDIT 0x0040 // Key is IME pre-edit string
38 #define UI_IME_COMMIT 0x0080 // Key is IME commit string
39 #define UI_KEYPAD_KEY 0x0100 // The key came from the keypad
40 #define UI_TABLET_MOTION 0x0200 // Motion event triggered from tablet.
41 #define UI_KEYSTATE_CHANGE 0x0400 // Key state was changed by this event
42 #define UI_KEYSEQ_TRIGGER 0x0800 // Key is key sequence hotkey trigger
43 #define UI_DBLCLK 0x1000 // UI_EVENT_BUTTON is the second press of a double-click
44 
45 #if defined(MBSD)
46  #define UI_TOGGLE_SEL_MODIFIER UI_COMMAND_KEY
47 #else
48  #define UI_TOGGLE_SEL_MODIFIER UI_CTRL_KEY
49 #endif
50 
51 static inline bool
52 UIhasToggleSelModifier(short alt_flags)
53 {
54  return (alt_flags & UI_TOGGLE_SEL_MODIFIER);
55 }
56 
57 // Flags for UI_DeviceEvent::deviceFlags.
58 #define UI_TABLET_DEVICE 0x0001 // Event came from a tablet pen.
59 
60 // Default for the pen button dead zone preference below, in pixels.
61 #define UI_PEN_BUTTON_DEAD_ZONE 8
62 
63 // How far the pointer may drift while a pen button is held, before it counts
64 // as a drag. A pen tip resting on the tablet is as steady as a mouse, but the
65 // pen buttons are used while it hovers, so they need more room.
68 
69 // The dead zone to use for the device and button that sent an event, given
70 // the one that applies to a mouse.
71 static inline int
72 UIgetDragDeadZone(int dead_zone, short device_flags, int button)
73 {
74  // The tip being down steadies the hand, whatever else is held.
75  if (!(device_flags & UI_TABLET_DEVICE) || (button & UI_LEFT_BUTTON))
76  return dead_zone;
77 
78  int pen_dead_zone = UIgetPenButtonDeadZone();
79 
80  return dead_zone > pen_dead_zone ? dead_zone : pen_dead_zone;
81 }
82 
83 // Conversion from our Z value to 0..1
84 #define UI_PRESSURE_SCALE 16384.0F
85 // Conversion of T/U/V values to degrees.
86 #define UI_ANGLE_SCALE 100.0F
87 
89 {
97 };
98 #define UI_DEVICE_DIMENSIONS 7
99 
100 
102 {
103 public:
104  UI_DeviceEvent(int event_id = 0);
105 
106  /// Returns an array of Unicode code points corresponding to typed in
107  /// characters from a keyboard event.
108  bool getTypedCharacters(UT_Array<utf32> &cps) const;
109 
110  /// Scroll phase of a touchpad wheel event. Values match Qt::ScrollPhase.
112  {
113  SCROLL_NO_PHASE = 0,
114  SCROLL_BEGIN = 1,
115  SCROLL_UPDATE = 2,
116  SCROLL_END = 3,
117  SCROLL_MOMENTUM = 4
118  };
119 
120  /// Queries for a mouse wheel event that came from a touchpad. The bits
121  /// are packed into DEVICE_DIM_T by UI_QtGeneratorThread. Always false when
122  /// touchpad gestures are turned off, so every consumer falls back to plain
123  /// mouse wheel behaviour.
124  bool isTouchPad() const;
125  ScrollPhase scrollPhase() const;
126 
127  /// Master switch for touchpad gestures, set from the preference.
128  static void setTouchPadGestures(bool flag)
129  { theTouchPadGestures = flag; }
130  static bool getTouchPadGestures()
131  { return theTouchPadGestures; }
132 
133  /// Flip the direction of a touchpad scroll that pans or tumbles, and of
134  /// one that zooms. Set from the preferences.
135  static void setTouchPadInvert(bool flag)
136  { theTouchPadInvert = flag; }
137  static bool getTouchPadInvert()
138  { return theTouchPadInvert; }
139  static void setTouchPadZoomInvert(bool flag)
140  { theTouchPadZoomInvert = flag; }
141  static bool getTouchPadZoomInvert()
142  { return theTouchPadZoomInvert; }
143 
145  // NB: 4 bytes of alignment padding here
146  RE_IDType context; // Device specific context
147  double time; // Time in seconds.
148  int64 serialId; // Event specific serialization id
149 
150  exint data; // Event data (at least pointer sized)
151  int values[UI_DEVICE_DIMENSIONS]; // Usually valuator values
152  short altFlags; // Event flags
153  short deviceFlags; // Which device sent the event
154  int id; // Event identifier
155 
156  int qt_key;
157  UT_StringHolder key; // Key input for UI_EVENT_KEYBOARD
158 
159 private:
160  static bool theTouchPadGestures;
161  static bool theTouchPadInvert;
162  static bool theTouchPadZoomInvert;
163 };
164 
165 inline
167 {
168  id = event_id;
169 
171 
172  context = 0;
173  data = 0;
174  altFlags = 0;
175  deviceFlags = 0;
176  values[DEVICE_DIM_T] = 0;
177  values[DEVICE_DIM_U] = 0;
178  values[DEVICE_DIM_V] = 0;
179  values[DEVICE_DIM_W] = 0;
180  values[DEVICE_DIM_X] = 0;
181  values[DEVICE_DIM_Y] = 0;
182  values[DEVICE_DIM_Z] = 0;
183 
184  time = -1.0;
185  serialId = 0;
186  qt_key = 0;
187 }
188 
189 #endif
void * RE_IDType
Definition: RE_IDType.h:20
#define UI_TABLET_DEVICE
int64 exint
Definition: SYS_Types.h:125
UI_DeviceEvent(int event_id=0)
UT_StringHolder key
UI_EventType type
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition: glcorearb.h:108
static void setTouchPadZoomInvert(bool flag)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
RE_IDType context
static bool getTouchPadInvert()
#define UI_LEFT_BUTTON
UI_Dimension
static bool getTouchPadZoomInvert()
UI_EventType
Definition: UI_EventType.h:20
long long int64
Definition: SYS_Types.h:116
ScrollPhase
Scroll phase of a touchpad wheel event. Values match Qt::ScrollPhase.
static void setTouchPadInvert(bool flag)
static void setTouchPadGestures(bool flag)
Master switch for touchpad gestures, set from the preference.
UI_API void UIsetPenButtonDeadZone(int pixels)
UI_API int UIgetPenButtonDeadZone()
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
#define UI_TOGGLE_SEL_MODIFIER
#define UI_API
Definition: UI_API.h:11
static bool getTouchPadGestures()
Definition: format.h:1821
#define UI_DEVICE_DIMENSIONS