comparison src/video/win32/SDL_win32window.c @ 2710:44e49d3fa6cf

Final merge of Google Summer of Code 2008 work... Many-mouse and tablet support by Szymon Wilczek, mentored by Ryan C. Gordon Everything concerning the project is noted on the wiki: http://wilku.ravenlord.ws/doku.php?id=start
author Sam Lantinga <slouken@libsdl.org>
date Mon, 25 Aug 2008 06:33:00 +0000
parents ba0d62354872
children 0906692aa6a4
comparison
equal deleted inserted replaced
2709:fd3f0f1147e7 2710:44e49d3fa6cf
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 18
19 Sam Lantinga 19 Sam Lantinga
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22
23 /* we need to define it, so that raw input is included */
24
25 #if (_WIN32_WINNT < 0x0501)
26 #undef _WIN32_WINNT
27 #define _WIN32_WINNT 0x0501
28 #endif
29
22 #include "SDL_config.h" 30 #include "SDL_config.h"
23 31
24 #include "../SDL_sysvideo.h" 32 #include "../SDL_sysvideo.h"
25 #include "../../events/SDL_keyboard_c.h" 33 #include "../../events/SDL_keyboard_c.h"
26 34
27 #include "SDL_win32video.h" 35 #include "SDL_win32video.h"
28 36
29 /* This is included after SDL_win32video.h, which includes windows.h */ 37 /* This is included after SDL_win32video.h, which includes windows.h */
30 #include "SDL_syswm.h" 38 #include "SDL_syswm.h"
31 39
40 #include <wintab.h>
41
42 /* we're telling wintab that we want to receive movement, button events and pressure information in packets */
43 #define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_CURSOR)
44 #define PACKETMODE 0
45 #include <pktdef.h>
46
47 extern HCTX *g_hCtx; /* the table of tablet event contexts, each windows has to have it's own tablet context */
48 int highestId = 0; /* the highest id of the tablet context */
32 49
33 static int 50 static int
34 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) 51 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
35 { 52 {
36 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 53 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
130 } 147 }
131 148
132 int 149 int
133 WIN_CreateWindow(_THIS, SDL_Window * window) 150 WIN_CreateWindow(_THIS, SDL_Window * window)
134 { 151 {
152 RAWINPUTDEVICE Rid;
153 AXIS TabX, TabY;
154 LOGCONTEXT lc;
135 HWND hwnd; 155 HWND hwnd;
136 HWND top; 156 HWND top;
137 RECT rect; 157 RECT rect;
138 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN); 158 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
139 int x, y; 159 int x, y;
178 } 198 }
179 199
180 hwnd = 200 hwnd =
181 CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL, 201 CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
182 SDL_Instance, NULL); 202 SDL_Instance, NULL);
183 WIN_PumpEvents(_this);
184
185 if (!hwnd) { 203 if (!hwnd) {
186 WIN_SetError("Couldn't create window"); 204 WIN_SetError("Couldn't create window");
187 return -1; 205 return -1;
188 } 206 }
207
208 /* we're configuring the tablet data. See Wintab reference for more info */
209 if (WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) {
210 lc.lcPktData = PACKETDATA;
211 lc.lcPktMode = PACKETMODE;
212 lc.lcOptions |= CXO_MESSAGES;
213 lc.lcOptions |= CXO_SYSTEM;
214 lc.lcMoveMask = PACKETDATA;
215 lc.lcBtnDnMask = lc.lcBtnUpMask = PACKETDATA;
216 WTInfo(WTI_DEVICES, DVC_X, &TabX);
217 WTInfo(WTI_DEVICES, DVC_Y, &TabY);
218 lc.lcInOrgX = 0;
219 lc.lcInOrgY = 0;
220 lc.lcInExtX = TabX.axMax;
221 lc.lcInExtY = TabY.axMax;
222 lc.lcOutOrgX = 0;
223 lc.lcOutOrgY = 0;
224 lc.lcOutExtX = GetSystemMetrics(SM_CXSCREEN);
225 lc.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN);
226 if (window->id > highestId) {
227 HCTX *tmp_hctx;
228 highestId = window->id;
229 tmp_hctx =
230 (HCTX *) SDL_realloc(g_hCtx, (highestId + 1) * sizeof(HCTX));
231 if (!tmp_hctx) {
232 SDL_OutOfMemory();
233 DestroyWindow(hwnd);
234 return -1;
235 }
236 g_hCtx = tmp_hctx;
237 }
238 g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE);
239 }
240
241 /* we're telling the window, we want it to report raw input events from mice */
242 Rid.usUsagePage = 0x01;
243 Rid.usUsage = 0x02;
244 Rid.dwFlags = RIDEV_INPUTSINK;
245 Rid.hwndTarget = hwnd;
246 RegisterRawInputDevices(&Rid, 1, sizeof(Rid));
247
248 WIN_PumpEvents(_this);
189 249
190 if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) { 250 if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) {
191 DestroyWindow(hwnd); 251 DestroyWindow(hwnd);
192 return -1; 252 return -1;
193 } 253 }
387 WIN_GL_CleanupWindow(_this, window); 447 WIN_GL_CleanupWindow(_this, window);
388 } 448 }
389 #endif 449 #endif
390 ReleaseDC(data->hwnd, data->hdc); 450 ReleaseDC(data->hwnd, data->hdc);
391 if (data->created) { 451 if (data->created) {
452 WTClose(g_hCtx[window->id]);
392 DestroyWindow(data->hwnd); 453 DestroyWindow(data->hwnd);
393 } 454 }
394 SDL_free(data); 455 SDL_free(data);
395 } 456 }
396 } 457 }