19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define WIN32_LEAN_AND_MEAN 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <windows.h> 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mouse.h" 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_cursor_c.h" 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_sysmouse_c.h" 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_lowvideo.h" 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef _WIN32_WCE 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define USE_STATIC_CURSOR 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallHCURSOR SDL_hcursor = NULL; /* Exported for SDL_eventloop.c */ 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The implementation dependent data for the window manager cursor */ 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* For some reason when creating a windows cursor, the ands and xors memory 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall is not copied, so we need to keep track of it and free it when we are done 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall with the cursor. If we free the memory prematurely, the app crashes. :-} 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstruct WMcursor { 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall HCURSOR curs; 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef USE_STATIC_CURSOR 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *ands; 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *xors; 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}; 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Convert bits to padded bytes */ 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define PAD_BITS(bits) ((bits+7)/8) 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef CURSOR_DEBUG 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void PrintBITMAP(FILE *out, char *bits, int w, int h) 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int i; 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned char ch; 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( h-- > 0 ) { 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<w; ++i ) { 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (i%8) == 0 ) 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ch = *bits++; 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ch&0x80 ) 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(out, "X"); 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(out, " "); 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ch <<= 1; 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fprintf(out, "\n"); 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef USE_STATIC_CURSOR 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Local functions to convert the SDL cursor mask into Windows format */ 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void memnot(Uint8 *dst, Uint8 *src, int len) 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( len-- > 0 ) 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dst++ = ~*src++; 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void memxor(Uint8 *dst, Uint8 *src1, Uint8 *src2, int len) 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while ( len-- > 0 ) 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *dst++ = (*src1++)^(*src2++); 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* !USE_STATIC_CURSOR */ 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIN_FreeWMCursor(_THIS, WMcursor *cursor) 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef USE_STATIC_CURSOR 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor->curs == GetCursor() ) 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SetCursor(NULL); 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor->curs != NULL ) 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall DestroyCursor(cursor->curs); 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor->ands != NULL ) 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(cursor->ands); 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor->xors != NULL ) 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(cursor->xors); 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* !USE_STATIC_CURSOR */ 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_free(cursor); 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallWMcursor *WIN_CreateWMCursor(_THIS, 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef USE_STATIC_CURSOR 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WMcursor *cursor; 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Allocate the cursor */ 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor ) { 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor->curs = LoadCursor(NULL, IDC_ARROW); 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(cursor); 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WMcursor *cursor; 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int allowed_x; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int allowed_y; 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int run, pad, i; 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 *aptr, *xptr; 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Check to make sure the cursor size is okay */ 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall allowed_x = GetSystemMetrics(SM_CXCURSOR); 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall allowed_y = GetSystemMetrics(SM_CYCURSOR); 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (w > allowed_x) || (h > allowed_y) ) { 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Only cursors of dimension (%dx%d) are allowed", 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall allowed_x, allowed_y); 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Allocate the cursor */ 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor == NULL ) { 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Out of memory"); 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor->curs = NULL; 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor->ands = NULL; 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor->xors = NULL; 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Pad out to the normal cursor size */ 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall run = PAD_BITS(w); 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pad = PAD_BITS(allowed_x)-run; 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall aptr = cursor->ands = (Uint8 *)SDL_malloc((run+pad)*allowed_y); 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall xptr = cursor->xors = (Uint8 *)SDL_malloc((run+pad)*allowed_y); 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (aptr == NULL) || (xptr == NULL) ) { 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIN_FreeWMCursor(NULL, cursor); 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_OutOfMemory(); 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( i=0; i<h; ++i ) { 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memxor(xptr, data, mask, run); 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall xptr += run; 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall data += run; 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall memnot(aptr, mask, run); 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mask += run; 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall aptr += run; 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(xptr, 0, pad); 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall xptr += pad; 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(aptr, ~0, pad); 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall aptr += pad; 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pad += run; 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for ( ; i<allowed_y; ++i ) { 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(xptr, 0, pad); 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall xptr += pad; 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(aptr, ~0, pad); 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall aptr += pad; 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the cursor */ 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor->curs = CreateCursor( 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (HINSTANCE)GetWindowLongPtr(SDL_Window, GWLP_HINSTANCE), 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall hot_x, hot_y, allowed_x, allowed_y, 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall cursor->ands, cursor->xors); 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor->curs == NULL ) { 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIN_FreeWMCursor(NULL, cursor); 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Windows couldn't create the requested cursor"); 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(cursor); 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* USE_STATIC_CURSOR */ 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint WIN_ShowWMCursor(_THIS, WMcursor *cursor) 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall POINT mouse_pos; 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !this->screen ) { 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set the window cursor to our cursor, if applicable */ 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( cursor != NULL ) { 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_hcursor = cursor->curs; 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_hcursor = NULL; 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GetCursorPos(&mouse_pos); 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( PtInRect(&SDL_bounds, mouse_pos) ) { 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SetCursor(SDL_hcursor); 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(1); 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( mouse_relative) { 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* RJR: March 28, 2000 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall leave physical cursor at center of screen if 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mouse hidden and grabbed */ 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseMotion(0, 0, x, y); 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall POINT pt; 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* With DirectInput the position doesn't follow 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * the cursor, so it is set manually */ 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( DINPUT() ) { 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseMotion(0, 0, x, y); 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pt.x = x; 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pt.y = y; 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ClientToScreen(SDL_Window, &pt); 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SetCursorPos(pt.x, pt.y); 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Update the current mouse state and position */ 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIN_UpdateMouse(_THIS) 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall POINT pt; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Always unset SDL_APPMOUSEFOCUS to give the WM_MOUSEMOVE event 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall * handler a chance to install a TRACKMOUSEEVENT */ 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall GetCursorPos(&pt); 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ScreenToClient(SDL_Window, &pt); 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PrivateMouseMotion(0,0, (Sint16)pt.x, (Sint16)pt.y); 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Check to see if we need to enter or leave mouse relative mode */ 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIN_CheckMouseMode(_THIS) 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef _WIN32_WCE 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If the mouse is hidden and input is grabbed, we use relative mode */ 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( !(SDL_cursorstate & CURSOR_VISIBLE) && 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (this->input_grab != SDL_GRAB_OFF) ) { 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mouse_relative = 1; 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mouse_relative = 0; 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mouse_relative = 0; 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 260