Mercurial > foo_out_sdl
comparison foosdk/sdk/libPPUI/gesture.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 | |
| 3 #ifndef WM_GESTURE | |
| 4 | |
| 5 #define WM_GESTURE 0x0119 | |
| 6 #define WM_GESTURENOTIFY 0x011A | |
| 7 | |
| 8 | |
| 9 DECLARE_HANDLE(HGESTUREINFO); | |
| 10 | |
| 11 | |
| 12 /* | |
| 13 * Gesture flags - GESTUREINFO.dwFlags | |
| 14 */ | |
| 15 #define GF_BEGIN 0x00000001 | |
| 16 #define GF_INERTIA 0x00000002 | |
| 17 #define GF_END 0x00000004 | |
| 18 | |
| 19 /* | |
| 20 * Gesture IDs | |
| 21 */ | |
| 22 #define GID_BEGIN 1 | |
| 23 #define GID_END 2 | |
| 24 #define GID_ZOOM 3 | |
| 25 #define GID_PAN 4 | |
| 26 #define GID_ROTATE 5 | |
| 27 #define GID_TWOFINGERTAP 6 | |
| 28 #define GID_PRESSANDTAP 7 | |
| 29 #define GID_ROLLOVER GID_PRESSANDTAP | |
| 30 | |
| 31 /* | |
| 32 * Gesture information structure | |
| 33 * - Pass the HGESTUREINFO received in the WM_GESTURE message lParam into the | |
| 34 * GetGestureInfo function to retrieve this information. | |
| 35 * - If cbExtraArgs is non-zero, pass the HGESTUREINFO received in the WM_GESTURE | |
| 36 * message lParam into the GetGestureExtraArgs function to retrieve extended | |
| 37 * argument information. | |
| 38 */ | |
| 39 typedef struct tagGESTUREINFO { | |
| 40 UINT cbSize; // size, in bytes, of this structure (including variable length Args field) | |
| 41 DWORD dwFlags; // see GF_* flags | |
| 42 DWORD dwID; // gesture ID, see GID_* defines | |
| 43 HWND hwndTarget; // handle to window targeted by this gesture | |
| 44 POINTS ptsLocation; // current location of this gesture | |
| 45 DWORD dwInstanceID; // internally used | |
| 46 DWORD dwSequenceID; // internally used | |
| 47 ULONGLONG ullArguments; // arguments for gestures whose arguments fit in 8 BYTES | |
| 48 UINT cbExtraArgs; // size, in bytes, of extra arguments, if any, that accompany this gesture | |
| 49 } GESTUREINFO, *PGESTUREINFO; | |
| 50 typedef GESTUREINFO const * PCGESTUREINFO; | |
| 51 | |
| 52 | |
| 53 /* | |
| 54 * Gesture notification structure | |
| 55 * - The WM_GESTURENOTIFY message lParam contains a pointer to this structure. | |
| 56 * - The WM_GESTURENOTIFY message notifies a window that gesture recognition is | |
| 57 * in progress and a gesture will be generated if one is recognized under the | |
| 58 * current gesture settings. | |
| 59 */ | |
| 60 typedef struct tagGESTURENOTIFYSTRUCT { | |
| 61 UINT cbSize; // size, in bytes, of this structure | |
| 62 DWORD dwFlags; // unused | |
| 63 HWND hwndTarget; // handle to window targeted by the gesture | |
| 64 POINTS ptsLocation; // starting location | |
| 65 DWORD dwInstanceID; // internally used | |
| 66 } GESTURENOTIFYSTRUCT, *PGESTURENOTIFYSTRUCT; | |
| 67 | |
| 68 /* | |
| 69 * Gesture argument helpers | |
| 70 * - Angle should be a double in the range of -2pi to +2pi | |
| 71 * - Argument should be an unsigned 16-bit value | |
| 72 */ | |
| 73 #define GID_ROTATE_ANGLE_TO_ARGUMENT(_arg_) ((USHORT)((((_arg_) + 2.0 * 3.14159265) / (4.0 * 3.14159265)) * 65535.0)) | |
| 74 #define GID_ROTATE_ANGLE_FROM_ARGUMENT(_arg_) ((((double)(_arg_) / 65535.0) * 4.0 * 3.14159265) - 2.0 * 3.14159265) | |
| 75 | |
| 76 /* | |
| 77 * Gesture information retrieval | |
| 78 * - HGESTUREINFO is received by a window in the lParam of a WM_GESTURE message. | |
| 79 */ | |
| 80 WINUSERAPI | |
| 81 BOOL | |
| 82 WINAPI | |
| 83 GetGestureInfo( | |
| 84 __in HGESTUREINFO hGestureInfo, | |
| 85 __out PGESTUREINFO pGestureInfo); | |
| 86 | |
| 87 | |
| 88 | |
| 89 /* | |
| 90 * Gesture extra arguments retrieval | |
| 91 * - HGESTUREINFO is received by a window in the lParam of a WM_GESTURE message. | |
| 92 * - Size, in bytes, of the extra argument data is available in the cbExtraArgs | |
| 93 * field of the GESTUREINFO structure retrieved using the GetGestureInfo function. | |
| 94 */ | |
| 95 WINUSERAPI | |
| 96 BOOL | |
| 97 WINAPI | |
| 98 GetGestureExtraArgs( | |
| 99 __in HGESTUREINFO hGestureInfo, | |
| 100 __in UINT cbExtraArgs, | |
| 101 __out_bcount(cbExtraArgs) PBYTE pExtraArgs); | |
| 102 | |
| 103 /* | |
| 104 * Gesture information handle management | |
| 105 * - If an application processes the WM_GESTURE message, then once it is done | |
| 106 * with the associated HGESTUREINFO, the application is responsible for | |
| 107 * closing the handle using this function. Failure to do so may result in | |
| 108 * process memory leaks. | |
| 109 * - If the message is instead passed to DefWindowProc, or is forwarded using | |
| 110 * one of the PostMessage or SendMessage class of API functions, the handle | |
| 111 * is transfered with the message and need not be closed by the application. | |
| 112 */ | |
| 113 WINUSERAPI | |
| 114 BOOL | |
| 115 WINAPI | |
| 116 CloseGestureInfoHandle( | |
| 117 __in HGESTUREINFO hGestureInfo); | |
| 118 | |
| 119 | |
| 120 /* | |
| 121 * Gesture configuration structure | |
| 122 * - Used in SetGestureConfig and GetGestureConfig | |
| 123 * - Note that any setting not included in either GESTURECONFIG.dwWant or | |
| 124 * GESTURECONFIG.dwBlock will use the parent window's preferences or | |
| 125 * system defaults. | |
| 126 */ | |
| 127 typedef struct tagGESTURECONFIG { | |
| 128 DWORD dwID; // gesture ID | |
| 129 DWORD dwWant; // settings related to gesture ID that are to be turned on | |
| 130 DWORD dwBlock; // settings related to gesture ID that are to be turned off | |
| 131 } GESTURECONFIG, *PGESTURECONFIG; | |
| 132 | |
| 133 /* | |
| 134 * Gesture configuration flags - GESTURECONFIG.dwWant or GESTURECONFIG.dwBlock | |
| 135 */ | |
| 136 | |
| 137 /* | |
| 138 * Common gesture configuration flags - set GESTURECONFIG.dwID to zero | |
| 139 */ | |
| 140 #define GC_ALLGESTURES 0x00000001 | |
| 141 | |
| 142 /* | |
| 143 * Zoom gesture configuration flags - set GESTURECONFIG.dwID to GID_ZOOM | |
| 144 */ | |
| 145 #define GC_ZOOM 0x00000001 | |
| 146 | |
| 147 /* | |
| 148 * Pan gesture configuration flags - set GESTURECONFIG.dwID to GID_PAN | |
| 149 */ | |
| 150 #define GC_PAN 0x00000001 | |
| 151 #define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY 0x00000002 | |
| 152 #define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY 0x00000004 | |
| 153 #define GC_PAN_WITH_GUTTER 0x00000008 | |
| 154 #define GC_PAN_WITH_INERTIA 0x00000010 | |
| 155 | |
| 156 /* | |
| 157 * Rotate gesture configuration flags - set GESTURECONFIG.dwID to GID_ROTATE | |
| 158 */ | |
| 159 #define GC_ROTATE 0x00000001 | |
| 160 | |
| 161 /* | |
| 162 * Two finger tap gesture configuration flags - set GESTURECONFIG.dwID to GID_TWOFINGERTAP | |
| 163 */ | |
| 164 #define GC_TWOFINGERTAP 0x00000001 | |
| 165 | |
| 166 /* | |
| 167 * PressAndTap gesture configuration flags - set GESTURECONFIG.dwID to GID_PRESSANDTAP | |
| 168 */ | |
| 169 #define GC_PRESSANDTAP 0x00000001 | |
| 170 #define GC_ROLLOVER GC_PRESSANDTAP | |
| 171 | |
| 172 #define GESTURECONFIGMAXCOUNT 256 // Maximum number of gestures that can be included | |
| 173 // in a single call to SetGestureConfig / GetGestureConfig | |
| 174 | |
| 175 WINUSERAPI | |
| 176 BOOL | |
| 177 WINAPI | |
| 178 SetGestureConfig( | |
| 179 __in HWND hwnd, // window for which configuration is specified | |
| 180 __in DWORD dwReserved, // reserved, must be 0 | |
| 181 __in UINT cIDs, // count of GESTURECONFIG structures | |
| 182 __in_ecount(cIDs) PGESTURECONFIG pGestureConfig, // array of GESTURECONFIG structures, dwIDs will be processed in the | |
| 183 // order specified and repeated occurances will overwrite previous ones | |
| 184 __in UINT cbSize); // sizeof(GESTURECONFIG) | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 #define GCF_INCLUDE_ANCESTORS 0x00000001 // If specified, GetGestureConfig returns consolidated configuration | |
| 190 // for the specified window and it's parent window chain | |
| 191 | |
| 192 WINUSERAPI | |
| 193 BOOL | |
| 194 WINAPI | |
| 195 GetGestureConfig( | |
| 196 __in HWND hwnd, // window for which configuration is required | |
| 197 __in DWORD dwReserved, // reserved, must be 0 | |
| 198 __in DWORD dwFlags, // see GCF_* flags | |
| 199 __in PUINT pcIDs, // *pcIDs contains the size, in number of GESTURECONFIG structures, | |
| 200 // of the buffer pointed to by pGestureConfig | |
| 201 __inout_ecount(*pcIDs) PGESTURECONFIG pGestureConfig, | |
| 202 // pointer to buffer to receive the returned array of GESTURECONFIG structures | |
| 203 __in UINT cbSize); // sizeof(GESTURECONFIG) | |
| 204 | |
| 205 | |
| 206 | |
| 207 typedef BOOL | |
| 208 (WINAPI *pGetGestureInfo_t)( | |
| 209 __in HGESTUREINFO hGestureInfo, | |
| 210 __out PGESTUREINFO pGestureInfo); | |
| 211 | |
| 212 typedef BOOL | |
| 213 (WINAPI * pCloseGestureInfoHandle_t)( | |
| 214 __in HGESTUREINFO hGestureInfo); | |
| 215 | |
| 216 typedef BOOL | |
| 217 (WINAPI * pSetGestureConfig_t) ( | |
| 218 __in HWND hwnd, // window for which configuration is specified | |
| 219 __in DWORD dwReserved, // reserved, must be 0 | |
| 220 __in UINT cIDs, // count of GESTURECONFIG structures | |
| 221 __in_ecount(cIDs) PGESTURECONFIG pGestureConfig, // array of GESTURECONFIG structures, dwIDs will be processed in the | |
| 222 // order specified and repeated occurances will overwrite previous ones | |
| 223 __in UINT cbSize); // sizeof(GESTURECONFIG) | |
| 224 | |
| 225 class CGestureAPI { | |
| 226 public: | |
| 227 CGestureAPI() { | |
| 228 HMODULE dll = GetModuleHandle(_T("user32.dll")); | |
| 229 | |
| 230 Bind(GetGestureInfo, dll, "GetGestureInfo"); | |
| 231 Bind(CloseGestureInfoHandle, dll, "CloseGestureInfoHandle"); | |
| 232 Bind(SetGestureConfig, dll, "SetGestureConfig"); | |
| 233 } | |
| 234 | |
| 235 bool IsAvailable() { | |
| 236 return this->GetGestureInfo != NULL; | |
| 237 } | |
| 238 | |
| 239 pGetGestureInfo_t GetGestureInfo; | |
| 240 pCloseGestureInfoHandle_t CloseGestureInfoHandle; | |
| 241 pSetGestureConfig_t SetGestureConfig; | |
| 242 private: | |
| 243 template<typename func_t> static void Bind(func_t & f, HMODULE dll, const char * name) { | |
| 244 f = reinterpret_cast<func_t>(GetProcAddress(dll, name)); | |
| 245 } | |
| 246 }; | |
| 247 #else | |
| 248 | |
| 249 class CGestureAPI { | |
| 250 public: | |
| 251 inline static bool IsAvailable() { return true; } | |
| 252 inline static BOOL GetGestureInfo(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo) { | |
| 253 return ::GetGestureInfo(hGestureInfo, pGestureInfo); | |
| 254 } | |
| 255 inline static BOOL CloseGestureInfoHandle(HGESTUREINFO hGestureInfo) { | |
| 256 return ::CloseGestureInfoHandle(hGestureInfo); | |
| 257 } | |
| 258 | |
| 259 inline static BOOL SetGestureConfig(HWND hwnd, DWORD dwReserved, UINT cIDs, PGESTURECONFIG pGestureConfig, UINT cbSize) { | |
| 260 return ::SetGestureConfig(hwnd, dwReserved, cIDs, pGestureConfig, cbSize); | |
| 261 } | |
| 262 }; | |
| 263 #endif | |
| 264 |
