Mercurial > sdl-ios-xcode
annotate src/video/wincommon/SDL_sysmouse.c @ 1402:d910939febfa
Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 21 Feb 2006 08:46:50 +0000 |
parents | 19418e4422cb |
children | bb6839704ed6 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
13
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
24 #include "SDL_windows.h" |
0 | 25 |
26 #include "SDL_mouse.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
27 #include "../../events/SDL_events_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
28 #include "../SDL_cursor_c.h" |
0 | 29 #include "SDL_sysmouse_c.h" |
30 #include "SDL_lowvideo.h" | |
31 | |
32 #ifdef _WIN32_WCE | |
33 #define USE_STATIC_CURSOR | |
34 #endif | |
35 | |
36 HCURSOR SDL_hcursor = NULL; /* Exported for SDL_eventloop.c */ | |
37 | |
38 /* The implementation dependent data for the window manager cursor */ | |
39 /* For some reason when creating a windows cursor, the ands and xors memory | |
40 is not copied, so we need to keep track of it and free it when we are done | |
41 with the cursor. If we free the memory prematurely, the app crashes. :-} | |
42 */ | |
43 struct WMcursor { | |
44 HCURSOR curs; | |
45 #ifndef USE_STATIC_CURSOR | |
46 Uint8 *ands; | |
47 Uint8 *xors; | |
48 #endif | |
49 }; | |
50 | |
51 /* Convert bits to padded bytes */ | |
52 #define PAD_BITS(bits) ((bits+7)/8) | |
53 | |
54 #ifdef CURSOR_DEBUG | |
55 static void PrintBITMAP(FILE *out, char *bits, int w, int h) | |
56 { | |
57 int i; | |
58 unsigned char ch; | |
59 | |
60 while ( h-- > 0 ) { | |
61 for ( i=0; i<w; ++i ) { | |
62 if ( (i%8) == 0 ) | |
63 ch = *bits++; | |
64 if ( ch&0x80 ) | |
65 fprintf(out, "X"); | |
66 else | |
67 fprintf(out, " "); | |
68 ch <<= 1; | |
69 } | |
70 fprintf(out, "\n"); | |
71 } | |
72 } | |
73 #endif | |
74 | |
75 #ifndef USE_STATIC_CURSOR | |
76 /* Local functions to convert the SDL cursor mask into Windows format */ | |
77 static void memnot(Uint8 *dst, Uint8 *src, int len) | |
78 { | |
79 while ( len-- > 0 ) | |
80 *dst++ = ~*src++; | |
81 } | |
82 static void memxor(Uint8 *dst, Uint8 *src1, Uint8 *src2, int len) | |
83 { | |
84 while ( len-- > 0 ) | |
85 *dst++ = (*src1++)^(*src2++); | |
86 } | |
87 #endif /* !USE_STATIC_CURSOR */ | |
88 | |
89 void WIN_FreeWMCursor(_THIS, WMcursor *cursor) | |
90 { | |
91 #ifndef USE_STATIC_CURSOR | |
506
f097dba83975
Fixed cursor resource leak in Windows (thanks Huib-Jan Imbens!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
92 if ( cursor->curs == GetCursor() ) |
f097dba83975
Fixed cursor resource leak in Windows (thanks Huib-Jan Imbens!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
93 SetCursor(NULL); |
0 | 94 if ( cursor->curs != NULL ) |
95 DestroyCursor(cursor->curs); | |
96 if ( cursor->ands != NULL ) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
97 SDL_free(cursor->ands); |
0 | 98 if ( cursor->xors != NULL ) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
99 SDL_free(cursor->xors); |
0 | 100 #endif /* !USE_STATIC_CURSOR */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
101 SDL_free(cursor); |
0 | 102 } |
103 | |
104 WMcursor *WIN_CreateWMCursor(_THIS, | |
105 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | |
106 { | |
107 #ifdef USE_STATIC_CURSOR | |
108 WMcursor *cursor; | |
109 | |
110 /* Allocate the cursor */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
111 cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); |
0 | 112 if ( cursor ) { |
113 cursor->curs = LoadCursor(NULL, IDC_ARROW); | |
114 } | |
115 return(cursor); | |
116 #else | |
117 WMcursor *cursor; | |
118 int allowed_x; | |
119 int allowed_y; | |
120 int run, pad, i; | |
121 Uint8 *aptr, *xptr; | |
122 | |
123 /* Check to make sure the cursor size is okay */ | |
124 allowed_x = GetSystemMetrics(SM_CXCURSOR); | |
125 allowed_y = GetSystemMetrics(SM_CYCURSOR); | |
126 if ( (w > allowed_x) || (h > allowed_y) ) { | |
127 SDL_SetError("Only cursors of dimension (%dx%d) are allowed", | |
128 allowed_x, allowed_y); | |
129 return(NULL); | |
130 } | |
131 | |
132 /* Allocate the cursor */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
133 cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); |
0 | 134 if ( cursor == NULL ) { |
135 SDL_SetError("Out of memory"); | |
136 return(NULL); | |
137 } | |
138 cursor->curs = NULL; | |
139 cursor->ands = NULL; | |
140 cursor->xors = NULL; | |
141 | |
142 /* Pad out to the normal cursor size */ | |
143 run = PAD_BITS(w); | |
144 pad = PAD_BITS(allowed_x)-run; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
145 aptr = cursor->ands = (Uint8 *)SDL_malloc((run+pad)*allowed_y); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
146 xptr = cursor->xors = (Uint8 *)SDL_malloc((run+pad)*allowed_y); |
0 | 147 if ( (aptr == NULL) || (xptr == NULL) ) { |
148 WIN_FreeWMCursor(NULL, cursor); | |
149 SDL_OutOfMemory(); | |
150 return(NULL); | |
151 } | |
152 for ( i=0; i<h; ++i ) { | |
153 memxor(xptr, data, mask, run); | |
154 xptr += run; | |
155 data += run; | |
156 memnot(aptr, mask, run); | |
157 mask += run; | |
158 aptr += run; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
159 SDL_memset(xptr, 0, pad); |
0 | 160 xptr += pad; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
161 SDL_memset(aptr, ~0, pad); |
0 | 162 aptr += pad; |
163 } | |
164 pad += run; | |
165 for ( ; i<allowed_y; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
166 SDL_memset(xptr, 0, pad); |
0 | 167 xptr += pad; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
168 SDL_memset(aptr, ~0, pad); |
0 | 169 aptr += pad; |
170 } | |
171 | |
172 /* Create the cursor */ | |
173 cursor->curs = CreateCursor( | |
174 (HINSTANCE)GetWindowLong(SDL_Window, GWL_HINSTANCE), | |
175 hot_x, hot_y, allowed_x, allowed_y, | |
176 cursor->ands, cursor->xors); | |
177 if ( cursor->curs == NULL ) { | |
178 WIN_FreeWMCursor(NULL, cursor); | |
179 SDL_SetError("Windows couldn't create the requested cursor"); | |
180 return(NULL); | |
181 } | |
182 return(cursor); | |
183 #endif /* USE_STATIC_CURSOR */ | |
184 } | |
185 | |
186 int WIN_ShowWMCursor(_THIS, WMcursor *cursor) | |
187 { | |
188 POINT mouse_pos; | |
189 | |
190 /* The fullscreen cursor must be done in software with DirectInput */ | |
13
e30a8ce27c22
Fixed double-mouse event bug on Windows using OpenGL
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
191 if ( !this->screen || DDRAW_FULLSCREEN() ) { |
0 | 192 return(0); |
193 } | |
194 | |
195 /* Set the window cursor to our cursor, if applicable */ | |
196 if ( cursor != NULL ) { | |
197 SDL_hcursor = cursor->curs; | |
198 } else { | |
199 SDL_hcursor = NULL; | |
200 } | |
201 GetCursorPos(&mouse_pos); | |
202 if ( PtInRect(&SDL_bounds, mouse_pos) ) { | |
203 SetCursor(SDL_hcursor); | |
204 } | |
205 return(1); | |
206 } | |
207 | |
208 void WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
209 { | |
13
e30a8ce27c22
Fixed double-mouse event bug on Windows using OpenGL
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
210 if ( DDRAW_FULLSCREEN() ) { |
0 | 211 SDL_PrivateMouseMotion(0, 0, x, y); |
212 } else if ( mouse_relative) { | |
213 /* RJR: March 28, 2000 | |
214 leave physical cursor at center of screen if | |
215 mouse hidden and grabbed */ | |
216 SDL_PrivateMouseMotion(0, 0, x, y); | |
217 } else { | |
527
5c74ac147358
Fixed mouse warp position bug with offset video modes
Sam Lantinga <slouken@libsdl.org>
parents:
506
diff
changeset
|
218 POINT pt; |
0 | 219 pt.x = x; |
220 pt.y = y; | |
221 ClientToScreen(SDL_Window, &pt); | |
222 SetCursorPos(pt.x, pt.y); | |
223 } | |
224 } | |
225 | |
226 /* Update the current mouse state and position */ | |
227 void WIN_UpdateMouse(_THIS) | |
228 { | |
229 RECT rect; | |
230 POINT pt; | |
231 | |
13
e30a8ce27c22
Fixed double-mouse event bug on Windows using OpenGL
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
232 if ( ! DDRAW_FULLSCREEN() ) { |
0 | 233 GetClientRect(SDL_Window, &rect); |
234 GetCursorPos(&pt); | |
235 MapWindowPoints(NULL, SDL_Window, &pt, 1); | |
236 if (PtInRect(&rect, pt) && (WindowFromPoint(pt) == SDL_Window)){ | |
237 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | |
238 SDL_PrivateMouseMotion(0,0, (Sint16)pt.x, (Sint16)pt.y); | |
239 } else { | |
240 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | |
241 } | |
242 } | |
243 } | |
244 | |
245 /* Check to see if we need to enter or leave mouse relative mode */ | |
246 void WIN_CheckMouseMode(_THIS) | |
247 { | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
527
diff
changeset
|
248 #ifndef _WIN32_WCE |
0 | 249 /* If the mouse is hidden and input is grabbed, we use relative mode */ |
250 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && | |
251 (this->input_grab != SDL_GRAB_OFF) ) { | |
252 mouse_relative = 1; | |
253 } else { | |
254 mouse_relative = 0; | |
255 } | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
527
diff
changeset
|
256 #else |
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
527
diff
changeset
|
257 mouse_relative = 0; |
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
527
diff
changeset
|
258 #endif |
0 | 259 } |