comparison src/video/win32/SDL_win32window.c @ 3771:8cc36a399a12 gsoc2008_manymouse

comments added and improved code look(windows part)
author Szymon Wilczek <kazeuser@gmail.com>
date Sat, 02 Aug 2008 14:02:28 +0000
parents 81b649bad6d2
children 5f599ed92fb9
comparison
equal deleted inserted replaced
3770:81b649bad6d2 3771:8cc36a399a12
18 18
19 Sam Lantinga 19 Sam Lantinga
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 22
23 /*we need to define it, so that raw input is included*/
24
23 #if (_WIN32_WINNT < 0x0501) 25 #if (_WIN32_WINNT < 0x0501)
24 #undef _WIN32_WINNT 26 #undef _WIN32_WINNT
25 #define _WIN32_WINNT 0x0501 27 #define _WIN32_WINNT 0x0501
26 #endif 28 #endif
27 29
34 36
35 /* This is included after SDL_win32video.h, which includes windows.h */ 37 /* This is included after SDL_win32video.h, which includes windows.h */
36 #include "SDL_syswm.h" 38 #include "SDL_syswm.h"
37 39
38 #include <wintab.h> 40 #include <wintab.h>
41 /*we're telling wintab that we want to receive movement, button events and pressure information in packets*/
39 #define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE) 42 #define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE)
40 #define PACKETMODE 0 43 #define PACKETMODE 0
41 #include <pktdef.h> 44 #include <pktdef.h>
42 45
43 extern HCTX* g_hCtx; 46 extern HCTX* g_hCtx; /*the table of tablet event contexts, each windows has to have it's own tablet context*/
44 47
45 int highestId=0; 48 int highestId=0; /*the highest id of the tablet context*/
46 49
47 static int 50 static int
48 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) 51 SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
49 { 52 {
50 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; 53 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
196 199
197 hwnd = 200 hwnd =
198 CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL, 201 CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, NULL, NULL,
199 SDL_Instance, NULL); 202 SDL_Instance, NULL);
200 203
201 WTInfo(WTI_DEFSYSCTX, 0, &lc); 204 /*we're configuring the tablet data. See Wintab reference for more info*/
202 lc.lcPktData = PACKETDATA;
203 lc.lcPktMode = PACKETMODE;
204 lc.lcOptions |= CXO_MESSAGES;
205 lc.lcOptions |= CXO_SYSTEM;
206 lc.lcMoveMask = PACKETDATA;
207 lc.lcBtnDnMask=lc.lcBtnUpMask = PACKETDATA;
208
209 WTInfo(WTI_DEVICES,DVC_X,&TabX);
210 WTInfo(WTI_DEVICES,DVC_Y,&TabY);
211 205
212 lc.lcInOrgX = 0; 206 if(WTInfo(WTI_DEFSYSCTX, 0, &lc)!=0)
213 lc.lcInOrgY = 0; 207 {
214 208
215 lc.lcInExtX = TabX.axMax; 209 lc.lcPktData = PACKETDATA;
216 lc.lcInExtY = TabY.axMax; 210 lc.lcPktMode = PACKETMODE;
217 211 lc.lcOptions |= CXO_MESSAGES;
218 lc.lcOutOrgX = 0; 212 lc.lcOptions |= CXO_SYSTEM;
219 lc.lcOutOrgY = 0; 213 lc.lcMoveMask = PACKETDATA;
220 214 lc.lcBtnDnMask=lc.lcBtnUpMask = PACKETDATA;
221 lc.lcOutExtX = GetSystemMetrics(SM_CXSCREEN); 215
222 lc.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN); 216 WTInfo(WTI_DEVICES,DVC_X,&TabX);
223 if(window->id>highestId) 217 WTInfo(WTI_DEVICES,DVC_Y,&TabY);
224 { 218
225 HCTX* tmp_hctx; 219 lc.lcInOrgX = 0;
226 highestId=window->id; 220 lc.lcInOrgY = 0;
227 tmp_hctx= (HCTX*)SDL_realloc(g_hCtx,(highestId+1)*sizeof(HCTX)); 221
228 if (!tmp_hctx) { 222 lc.lcInExtX = TabX.axMax;
229 SDL_OutOfMemory(); 223 lc.lcInExtY = TabY.axMax;
230 return -1; 224
231 } 225 lc.lcOutOrgX = 0;
232 g_hCtx=tmp_hctx; 226 lc.lcOutOrgY = 0;
227
228 lc.lcOutExtX = GetSystemMetrics(SM_CXSCREEN);
229 lc.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN);
230
231 if(window->id>highestId)
232 {
233 HCTX* tmp_hctx;
234 highestId=window->id;
235 tmp_hctx= (HCTX*)SDL_realloc(g_hCtx,(highestId+1)*sizeof(HCTX));
236 if (!tmp_hctx) {
237 SDL_OutOfMemory();
238 return -1;
239 }
240 g_hCtx=tmp_hctx;
241 }
242
243 g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE);
233 } 244 }
234 245
235 g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE); 246 /*we're telling the window, we want it to report raw input events from mice*/
236 247
237 Rid.usUsagePage = 0x01; 248 Rid.usUsagePage = 0x01;
238 Rid.usUsage = 0x02; 249 Rid.usUsage = 0x02;
239 //Rid.usUsage = MOUSE_MOVE_ABSOLUTE; 250 Rid.dwFlags = RIDEV_INPUTSINK;
240 Rid.dwFlags = RIDEV_INPUTSINK; // adds HID mouse and also ignores legacy mouse messages
241 Rid.hwndTarget = hwnd; 251 Rid.hwndTarget = hwnd;
242 252
243 RegisterRawInputDevices(&Rid, 1, sizeof(Rid)); 253 RegisterRawInputDevices(&Rid, 1, sizeof(Rid));
244 254
245 255
454 if (data->created) { 464 if (data->created) {
455 WTClose(g_hCtx[window->id]); 465 WTClose(g_hCtx[window->id]);
456 DestroyWindow(data->hwnd); 466 DestroyWindow(data->hwnd);
457 } 467 }
458 SDL_free(data); 468 SDL_free(data);
469 /*lets close the tablet context for the destoryed window*/
459 WTClose(g_hCtx[window->id]); 470 WTClose(g_hCtx[window->id]);
460 } 471 }
461 } 472 }
462 473
463 SDL_bool 474 SDL_bool