Mercurial > sdl-ios-xcode
changeset 3770:81b649bad6d2 gsoc2008_manymouse
Implementation finished
author | Szymon Wilczek <kazeuser@gmail.com> |
---|---|
date | Thu, 31 Jul 2008 14:41:48 +0000 |
parents | fe32943f86ec |
children | 8cc36a399a12 |
files | src/events/SDL_mouse.c src/video/win32/SDL_win32events.c src/video/win32/SDL_win32mouse.c src/video/win32/SDL_win32video.c src/video/win32/SDL_win32window.c |
diffstat | 5 files changed, 252 insertions(+), 287 deletions(-) [+] |
line wrap: on
line diff
--- a/src/events/SDL_mouse.c Wed Jul 30 16:20:32 2008 +0000 +++ b/src/events/SDL_mouse.c Thu Jul 31 14:41:48 2008 +0000 @@ -330,6 +330,8 @@ { int index=SDL_GetIndexById(id); int posted=0; + last_x=x; + last_y=y; if(SDL_ProcessEvents[type]==SDL_ENABLE) { SDL_Event event;
--- a/src/video/win32/SDL_win32events.c Wed Jul 30 16:20:32 2008 +0000 +++ b/src/video/win32/SDL_win32events.c Thu Jul 31 14:41:48 2008 +0000 @@ -62,6 +62,7 @@ extern HCTX* g_hCtx; extern HANDLE* mice; extern int total_mice; +extern int tablet; int pressure=0; @@ -146,13 +147,16 @@ case WT_PROXIMITY: { int h_context=LOWORD(lParam); + LPPOINT point; + GetCursorPos(&point); + ScreenToClient(hwnd, &point); if(h_context==0) { - SDL_SendProximity(0, 0, 0, SDL_PROXIMITYOUT); + SDL_SendProximity(tablet, (int)(&point->x),(int)(&point->y), SDL_PROXIMITYOUT); } else { - SDL_SendProximity(0, 0, 0, SDL_PROXIMITYIN); + SDL_SendProximity(tablet, (int)(&point->x),(int)(&point->y), SDL_PROXIMITYIN); } } break; @@ -202,74 +206,6 @@ return (0); } break; - case WT_CTXOPEN: - { - SDL_SendMouseMotion(0,1,1,0,0); - SDL_SendMouseMotion(0,1,-1,0,0); - } - /*case WM_MOUSEMOVE: - { - LPBYTE lpb; - const RAWINPUTHEADER *header; - int index; - int i; - int size=0; - SDL_Mouse *mouse; - int x, y; - - //index = data->videodata->mouse; - GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size, sizeof (RAWINPUTHEADER)); - lpb = SDL_malloc(size*sizeof(LPBYTE)); - GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &size, sizeof (RAWINPUTHEADER)); - raw = (RAWINPUT *) lpb; - header = &raw->header; - for(i=0;i<total_mice;++i) - { - if(mice[i]==header->hDevice) - { - index=i; - break; - } - } - mouse = SDL_GetMouse(index); - - if (mouse->focus != data->windowID) { - TRACKMOUSEEVENT tme; - - tme.cbSize = sizeof(tme); - tme.dwFlags = TME_LEAVE; - tme.hwndTrack = hwnd; - TrackMouseEvent(&tme); - - SDL_SetMouseFocus(index, data->windowID); - } - - /* mouse has moved within the window */ - //x = LOWORD(lParam); - //y = HIWORD(lParam); - //printf("index: %d\n",index); - /*if (WTPacketsPeek(g_hCtx[data->windowID],1,&packet)) - { - pressure=(int)packet.pkNormalPressure; - }*/ - /*if (mouse->relative_mode) { - int w, h; - POINT center; - SDL_GetWindowSize(data->windowID, &w, &h); - center.x = (w / 2); - center.y = (h / 2); - x -= center.x; - y -= center.y; - if (x || y) { - ClientToScreen(hwnd, ¢er); - SetCursorPos(center.x, center.y); - SDL_SendMouseMotion(index, 1, x, y,pressure); - } - } else { - SDL_SendMouseMotion(index, 0, x, y,pressure); - } - } - return (0);*/ case WM_INPUT: { LPBYTE lpb; @@ -287,7 +223,6 @@ GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &size, sizeof (RAWINPUTHEADER)); raw = (RAWINPUT *) lpb; header = &raw->header; - //raw_mouse=&raw->data.mouse; flags=raw->data.mouse.usButtonFlags; for(i=0;i<total_mice;++i) { @@ -302,7 +237,14 @@ ScreenToClient(hwnd, &point); SDL_GetWindowSize(data->windowID, &w, &h); SDL_UpdateCoordinates(w,h); - SDL_SendMouseMotion(index,0,(int)(&point->x),(int)(&point->y),pressure); + if(i==tablet) + { + SDL_SendMouseMotion(index,0,(int)(&point->x),(int)(&point->y),pressure); + } + else + { + SDL_SendMouseMotion(index,0,(int)(&point->x),(int)(&point->y),0); + } if(flags & RI_MOUSE_BUTTON_1_DOWN) { SDL_SendMouseButton(index,SDL_PRESSED,SDL_BUTTON_LEFT); @@ -327,6 +269,13 @@ { SDL_SendMouseButton(index,SDL_RELEASED,SDL_BUTTON_RIGHT); } + if(flags & RI_MOUSE_WHEEL) + { + if(raw->data.mouse.usButtonData!=0) + { + SDL_SendMouseWheel(index, 0, raw->data.mouse.usButtonData); + } + } } return(0); case WM_MOUSELEAVE: @@ -342,19 +291,6 @@ } } return (0); - - - - /* case WM_MOUSEWHEEL: - { - int index; - int motion = (short) HIWORD(wParam); - - index = data->videodata->mouse; - SDL_SendMouseWheel(index, 0, motion); - } - return (0);*/ - case WM_SYSKEYDOWN: case WM_KEYDOWN: { @@ -743,3 +679,4 @@ } /* vi: set ts=4 sw=4 expandtab: */ +
--- a/src/video/win32/SDL_win32mouse.c Wed Jul 30 16:20:32 2008 +0000 +++ b/src/video/win32/SDL_win32mouse.c Thu Jul 31 14:41:48 2008 +0000 @@ -31,13 +31,16 @@ #include "../../events/SDL_mouse_c.h" -extern int total_mice; +#include <wintab.h> +#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE) +#define PACKETMODE 0 +#include <pktdef.h> extern HANDLE* mice; extern int total_mice; -RAWINPUTDEVICE *Rid=NULL; +extern int tablet; void WIN_InitMouse(_THIS) @@ -48,6 +51,7 @@ int i; int tmp=0; char* buffer=NULL; + char* tab="wacom"; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; @@ -67,6 +71,7 @@ for(i=0;i<devCount;++i) { int j; + int k; char *default_device_name="Pointing device xx"; const char *reg_key_root = "System\\CurrentControlSet\\Enum\\"; char *device_name=SDL_malloc(256*sizeof(char)); @@ -77,6 +82,7 @@ DWORD regtype = REG_SZ; DWORD out=256*sizeof(char); SDL_Mouse mouse; + int l; if(deviceList[i].dwType!=RIM_TYPEMOUSE) { continue; @@ -117,35 +123,53 @@ rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); if (rc != ERROR_SUCCESS) - return; + { + SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); + } rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, ®type, device_name, &out); RegCloseKey(hkey); if (rc != ERROR_SUCCESS) { - return; - //SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); + SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); } - //device_name[254] = '\0'; - mice[index]=deviceList[i].hDevice; SDL_zero(mouse); SDL_SetIndexId(index,index); - data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0); - //data->mouse = SDL_AddMouse(&mouse, index,key_name,0,0); + l=SDL_strlen(device_name); + if(tablet==-1) + { + for(j=0;j<l-5;++j) + { + for(k=0;k<5;++k) + { + if(tab[k]!=SDL_tolower((unsigned char)device_name[j+k])) + { + break; + } + } + if(k==5) + { + tablet=index; + break; + } + } + } + if(tablet==index) + { + AXIS pressure; + WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure); + data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin); + } + else + { + data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0); + } ++index; SDL_free(buffer); SDL_free(key_name); } - Rid = SDL_malloc(sizeof(RAWINPUTDEVICE)); - /*Rid[0].usUsagePage = 0x01; - Rid[0].usUsage = 0x02; - Rid[0].dwFlags = RIDEV_INPUTSINK; // adds HID mouse and also ignores legacy mouse messages - Rid[0].hwndTarget = NULL; - - RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));*/ - total_mice=index; SDL_free(deviceList); } @@ -159,7 +183,7 @@ { SDL_DelMouse(i); } - SDL_free(Rid); } /* vi: set ts=4 sw=4 expandtab: */ +
--- a/src/video/win32/SDL_win32video.c Wed Jul 30 16:20:32 2008 +0000 +++ b/src/video/win32/SDL_win32video.c Thu Jul 31 14:41:48 2008 +0000 @@ -1,184 +1,185 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_main.h" -#include "SDL_video.h" -#include "SDL_mouse.h" -#include "../SDL_sysvideo.h" -#include "../SDL_pixels_c.h" - -#include "SDL_win32video.h" -#include "SDL_d3drender.h" -#include "SDL_gdirender.h" - -#include <wintab.h> - -/* Initialization/Query functions */ -static int WIN_VideoInit(_THIS); -static void WIN_VideoQuit(_THIS); - -int total_mice =0; -HANDLE* mice = NULL; -HCTX* g_hCtx = NULL; -//int highestId=0; - -/* WIN32 driver bootstrap functions */ - -static int -WIN_Available(void) -{ - return (1); -} - -static void -WIN_DeleteDevice(SDL_VideoDevice * device) -{ - SDL_VideoData *data = (SDL_VideoData *) device->driverdata; - - SDL_UnregisterApp(); -#if SDL_VIDEO_RENDER_D3D - if (data->d3d) { - IDirect3D9_Release(data->d3d); - FreeLibrary(data->d3dDLL); - } -#endif - SDL_free(device->driverdata); - SDL_free(device); -} - -static SDL_VideoDevice * -WIN_CreateDevice(int devindex) -{ - SDL_VideoDevice *device; - SDL_VideoData *data; - - SDL_RegisterApp(NULL, 0, NULL); - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (device) { - data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - } - if (!device || !data) { - SDL_OutOfMemory(); - if (device) { - SDL_free(device); - } - return NULL; - } - device->driverdata = data; - -#if SDL_VIDEO_RENDER_D3D - data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL")); - if (data->d3dDLL) { - IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion); - - D3DCreate = - (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL, - "Direct3DCreate9"); - if (D3DCreate) { - data->d3d = D3DCreate(D3D_SDK_VERSION); - } - if (!data->d3d) { - FreeLibrary(data->d3dDLL); - data->d3dDLL = NULL; - } - } -#endif /* SDL_VIDEO_RENDER_D3D */ - - /* Set the function pointers */ - device->VideoInit = WIN_VideoInit; - device->VideoQuit = WIN_VideoQuit; - device->GetDisplayModes = WIN_GetDisplayModes; - device->SetDisplayMode = WIN_SetDisplayMode; - device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp; - device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp; - device->PumpEvents = WIN_PumpEvents; - -#undef CreateWindow - device->CreateWindow = WIN_CreateWindow; - device->CreateWindowFrom = WIN_CreateWindowFrom; - device->SetWindowTitle = WIN_SetWindowTitle; - device->SetWindowPosition = WIN_SetWindowPosition; - device->SetWindowSize = WIN_SetWindowSize; - device->ShowWindow = WIN_ShowWindow; - device->HideWindow = WIN_HideWindow; - device->RaiseWindow = WIN_RaiseWindow; - device->MaximizeWindow = WIN_MaximizeWindow; - device->MinimizeWindow = WIN_MinimizeWindow; - device->RestoreWindow = WIN_RestoreWindow; - device->SetWindowGrab = WIN_SetWindowGrab; - device->DestroyWindow = WIN_DestroyWindow; - device->GetWindowWMInfo = WIN_GetWindowWMInfo; -#ifdef SDL_VIDEO_OPENGL_WGL - device->GL_LoadLibrary = WIN_GL_LoadLibrary; - device->GL_GetProcAddress = WIN_GL_GetProcAddress; - device->GL_CreateContext = WIN_GL_CreateContext; - device->GL_MakeCurrent = WIN_GL_MakeCurrent; - device->GL_SetSwapInterval = WIN_GL_SetSwapInterval; - device->GL_GetSwapInterval = WIN_GL_GetSwapInterval; - device->GL_SwapWindow = WIN_GL_SwapWindow; - device->GL_DeleteContext = WIN_GL_DeleteContext; -#endif - - device->free = WIN_DeleteDevice; - - return device; -} - -VideoBootStrap WIN32_bootstrap = { - "win32", "SDL Win32/64 video driver", - WIN_Available, WIN_CreateDevice -}; - - -int -WIN_VideoInit(_THIS) -{ - WIN_InitModes(_this); - -#if SDL_VIDEO_RENDER_D3D - D3D_AddRenderDriver(_this); -#endif -#if SDL_VIDEO_RENDER_GDI - GDI_AddRenderDriver(_this); -#endif - - g_hCtx = SDL_malloc(sizeof(HCTX)); - - WIN_InitKeyboard(_this); - WIN_InitMouse(_this); - - return 0; -} - -void -WIN_VideoQuit(_THIS) -{ - WIN_QuitModes(_this); - WIN_QuitKeyboard(_this); - WIN_QuitMouse(_this); - SDL_free(g_hCtx); -} - -/* vim: set ts=4 sw=4 expandtab: */ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_main.h" +#include "SDL_video.h" +#include "SDL_mouse.h" +#include "../SDL_sysvideo.h" +#include "../SDL_pixels_c.h" + +#include "SDL_win32video.h" +#include "SDL_d3drender.h" +#include "SDL_gdirender.h" + +#include <wintab.h> + +/* Initialization/Query functions */ +static int WIN_VideoInit(_THIS); +static void WIN_VideoQuit(_THIS); + +int total_mice =0; +HANDLE* mice = NULL; +HCTX* g_hCtx = NULL; +int tablet=-1; + +/* WIN32 driver bootstrap functions */ + +static int +WIN_Available(void) +{ + return (1); +} + +static void +WIN_DeleteDevice(SDL_VideoDevice * device) +{ + SDL_VideoData *data = (SDL_VideoData *) device->driverdata; + + SDL_UnregisterApp(); +#if SDL_VIDEO_RENDER_D3D + if (data->d3d) { + IDirect3D9_Release(data->d3d); + FreeLibrary(data->d3dDLL); + } +#endif + SDL_free(device->driverdata); + SDL_free(device); +} + +static SDL_VideoDevice * +WIN_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + SDL_VideoData *data; + + SDL_RegisterApp(NULL, 0, NULL); + + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (device) { + data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); + } + if (!device || !data) { + SDL_OutOfMemory(); + if (device) { + SDL_free(device); + } + return NULL; + } + device->driverdata = data; + +#if SDL_VIDEO_RENDER_D3D + data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL")); + if (data->d3dDLL) { + IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion); + + D3DCreate = + (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL, + "Direct3DCreate9"); + if (D3DCreate) { + data->d3d = D3DCreate(D3D_SDK_VERSION); + } + if (!data->d3d) { + FreeLibrary(data->d3dDLL); + data->d3dDLL = NULL; + } + } +#endif /* SDL_VIDEO_RENDER_D3D */ + + /* Set the function pointers */ + device->VideoInit = WIN_VideoInit; + device->VideoQuit = WIN_VideoQuit; + device->GetDisplayModes = WIN_GetDisplayModes; + device->SetDisplayMode = WIN_SetDisplayMode; + device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp; + device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp; + device->PumpEvents = WIN_PumpEvents; + +#undef CreateWindow + device->CreateWindow = WIN_CreateWindow; + device->CreateWindowFrom = WIN_CreateWindowFrom; + device->SetWindowTitle = WIN_SetWindowTitle; + device->SetWindowPosition = WIN_SetWindowPosition; + device->SetWindowSize = WIN_SetWindowSize; + device->ShowWindow = WIN_ShowWindow; + device->HideWindow = WIN_HideWindow; + device->RaiseWindow = WIN_RaiseWindow; + device->MaximizeWindow = WIN_MaximizeWindow; + device->MinimizeWindow = WIN_MinimizeWindow; + device->RestoreWindow = WIN_RestoreWindow; + device->SetWindowGrab = WIN_SetWindowGrab; + device->DestroyWindow = WIN_DestroyWindow; + device->GetWindowWMInfo = WIN_GetWindowWMInfo; +#ifdef SDL_VIDEO_OPENGL_WGL + device->GL_LoadLibrary = WIN_GL_LoadLibrary; + device->GL_GetProcAddress = WIN_GL_GetProcAddress; + device->GL_CreateContext = WIN_GL_CreateContext; + device->GL_MakeCurrent = WIN_GL_MakeCurrent; + device->GL_SetSwapInterval = WIN_GL_SetSwapInterval; + device->GL_GetSwapInterval = WIN_GL_GetSwapInterval; + device->GL_SwapWindow = WIN_GL_SwapWindow; + device->GL_DeleteContext = WIN_GL_DeleteContext; +#endif + + device->free = WIN_DeleteDevice; + + return device; +} + +VideoBootStrap WIN32_bootstrap = { + "win32", "SDL Win32/64 video driver", + WIN_Available, WIN_CreateDevice +}; + + +int +WIN_VideoInit(_THIS) +{ + WIN_InitModes(_this); + +#if SDL_VIDEO_RENDER_D3D + D3D_AddRenderDriver(_this); +#endif +#if SDL_VIDEO_RENDER_GDI + GDI_AddRenderDriver(_this); +#endif + + g_hCtx = SDL_malloc(sizeof(HCTX)); + + WIN_InitKeyboard(_this); + WIN_InitMouse(_this); + + return 0; +} + +void +WIN_VideoQuit(_THIS) +{ + WIN_QuitModes(_this); + WIN_QuitKeyboard(_this); + WIN_QuitMouse(_this); + SDL_free(g_hCtx); +} + +/* vim: set ts=4 sw=4 expandtab: */ +