Mercurial > sdl-ios-xcode
comparison src/video/wincommon/SDL_sysmouse.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | 4aac8563c296 |
children |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
32 | 32 |
33 #ifdef _WIN32_WCE | 33 #ifdef _WIN32_WCE |
34 #define USE_STATIC_CURSOR | 34 #define USE_STATIC_CURSOR |
35 #endif | 35 #endif |
36 | 36 |
37 HCURSOR SDL_hcursor = NULL; /* Exported for SDL_eventloop.c */ | 37 HCURSOR SDL_hcursor = NULL; /* Exported for SDL_eventloop.c */ |
38 | 38 |
39 /* The implementation dependent data for the window manager cursor */ | 39 /* The implementation dependent data for the window manager cursor */ |
40 /* For some reason when creating a windows cursor, the ands and xors memory | 40 /* For some reason when creating a windows cursor, the ands and xors memory |
41 is not copied, so we need to keep track of it and free it when we are done | 41 is not copied, so we need to keep track of it and free it when we are done |
42 with the cursor. If we free the memory prematurely, the app crashes. :-} | 42 with the cursor. If we free the memory prematurely, the app crashes. :-} |
43 */ | 43 */ |
44 struct WMcursor { | 44 struct WMcursor |
45 HCURSOR curs; | 45 { |
46 HCURSOR curs; | |
46 #ifndef USE_STATIC_CURSOR | 47 #ifndef USE_STATIC_CURSOR |
47 Uint8 *ands; | 48 Uint8 *ands; |
48 Uint8 *xors; | 49 Uint8 *xors; |
49 #endif | 50 #endif |
50 }; | 51 }; |
51 | 52 |
52 /* Convert bits to padded bytes */ | 53 /* Convert bits to padded bytes */ |
53 #define PAD_BITS(bits) ((bits+7)/8) | 54 #define PAD_BITS(bits) ((bits+7)/8) |
54 | 55 |
55 #ifdef CURSOR_DEBUG | 56 #ifdef CURSOR_DEBUG |
56 static void PrintBITMAP(FILE *out, char *bits, int w, int h) | 57 static void |
57 { | 58 PrintBITMAP(FILE * out, char *bits, int w, int h) |
58 int i; | 59 { |
59 unsigned char ch; | 60 int i; |
60 | 61 unsigned char ch; |
61 while ( h-- > 0 ) { | 62 |
62 for ( i=0; i<w; ++i ) { | 63 while (h-- > 0) { |
63 if ( (i%8) == 0 ) | 64 for (i = 0; i < w; ++i) { |
64 ch = *bits++; | 65 if ((i % 8) == 0) |
65 if ( ch&0x80 ) | 66 ch = *bits++; |
66 fprintf(out, "X"); | 67 if (ch & 0x80) |
67 else | 68 fprintf(out, "X"); |
68 fprintf(out, " "); | 69 else |
69 ch <<= 1; | 70 fprintf(out, " "); |
70 } | 71 ch <<= 1; |
71 fprintf(out, "\n"); | 72 } |
72 } | 73 fprintf(out, "\n"); |
74 } | |
73 } | 75 } |
74 #endif | 76 #endif |
75 | 77 |
76 #ifndef USE_STATIC_CURSOR | 78 #ifndef USE_STATIC_CURSOR |
77 /* Local functions to convert the SDL cursor mask into Windows format */ | 79 /* Local functions to convert the SDL cursor mask into Windows format */ |
78 static void memnot(Uint8 *dst, Uint8 *src, int len) | 80 static void |
79 { | 81 memnot(Uint8 * dst, Uint8 * src, int len) |
80 while ( len-- > 0 ) | 82 { |
81 *dst++ = ~*src++; | 83 while (len-- > 0) |
82 } | 84 *dst++ = ~*src++; |
83 static void memxor(Uint8 *dst, Uint8 *src1, Uint8 *src2, int len) | 85 } |
84 { | 86 static void |
85 while ( len-- > 0 ) | 87 memxor(Uint8 * dst, Uint8 * src1, Uint8 * src2, int len) |
86 *dst++ = (*src1++)^(*src2++); | 88 { |
89 while (len-- > 0) | |
90 *dst++ = (*src1++) ^ (*src2++); | |
87 } | 91 } |
88 #endif /* !USE_STATIC_CURSOR */ | 92 #endif /* !USE_STATIC_CURSOR */ |
89 | 93 |
90 void WIN_FreeWMCursor(_THIS, WMcursor *cursor) | 94 void |
95 WIN_FreeWMCursor(_THIS, WMcursor * cursor) | |
91 { | 96 { |
92 #ifndef USE_STATIC_CURSOR | 97 #ifndef USE_STATIC_CURSOR |
93 if ( cursor->curs == GetCursor() ) | 98 if (cursor->curs == GetCursor()) |
94 SetCursor(NULL); | 99 SetCursor(NULL); |
95 if ( cursor->curs != NULL ) | 100 if (cursor->curs != NULL) |
96 DestroyCursor(cursor->curs); | 101 DestroyCursor(cursor->curs); |
97 if ( cursor->ands != NULL ) | 102 if (cursor->ands != NULL) |
98 SDL_free(cursor->ands); | 103 SDL_free(cursor->ands); |
99 if ( cursor->xors != NULL ) | 104 if (cursor->xors != NULL) |
100 SDL_free(cursor->xors); | 105 SDL_free(cursor->xors); |
101 #endif /* !USE_STATIC_CURSOR */ | 106 #endif /* !USE_STATIC_CURSOR */ |
102 SDL_free(cursor); | 107 SDL_free(cursor); |
103 } | 108 } |
104 | 109 |
105 WMcursor *WIN_CreateWMCursor(_THIS, | 110 WMcursor * |
106 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | 111 WIN_CreateWMCursor(_THIS, |
112 Uint8 * data, Uint8 * mask, int w, int h, int hot_x, | |
113 int hot_y) | |
107 { | 114 { |
108 #ifdef USE_STATIC_CURSOR | 115 #ifdef USE_STATIC_CURSOR |
109 WMcursor *cursor; | 116 WMcursor *cursor; |
110 | 117 |
111 /* Allocate the cursor */ | 118 /* Allocate the cursor */ |
112 cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); | 119 cursor = (WMcursor *) SDL_malloc(sizeof(*cursor)); |
113 if ( cursor ) { | 120 if (cursor) { |
114 cursor->curs = LoadCursor(NULL, IDC_ARROW); | 121 cursor->curs = LoadCursor(NULL, IDC_ARROW); |
115 } | 122 } |
116 return(cursor); | 123 return (cursor); |
117 #else | 124 #else |
118 WMcursor *cursor; | 125 WMcursor *cursor; |
119 int allowed_x; | 126 int allowed_x; |
120 int allowed_y; | 127 int allowed_y; |
121 int run, pad, i; | 128 int run, pad, i; |
122 Uint8 *aptr, *xptr; | 129 Uint8 *aptr, *xptr; |
123 | 130 |
124 /* Check to make sure the cursor size is okay */ | 131 /* Check to make sure the cursor size is okay */ |
125 allowed_x = GetSystemMetrics(SM_CXCURSOR); | 132 allowed_x = GetSystemMetrics(SM_CXCURSOR); |
126 allowed_y = GetSystemMetrics(SM_CYCURSOR); | 133 allowed_y = GetSystemMetrics(SM_CYCURSOR); |
127 if ( (w > allowed_x) || (h > allowed_y) ) { | 134 if ((w > allowed_x) || (h > allowed_y)) { |
128 SDL_SetError("Only cursors of dimension (%dx%d) are allowed", | 135 SDL_SetError("Only cursors of dimension (%dx%d) are allowed", |
129 allowed_x, allowed_y); | 136 allowed_x, allowed_y); |
130 return(NULL); | 137 return (NULL); |
131 } | 138 } |
132 | 139 |
133 /* Allocate the cursor */ | 140 /* Allocate the cursor */ |
134 cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); | 141 cursor = (WMcursor *) SDL_malloc(sizeof(*cursor)); |
135 if ( cursor == NULL ) { | 142 if (cursor == NULL) { |
136 SDL_SetError("Out of memory"); | 143 SDL_SetError("Out of memory"); |
137 return(NULL); | 144 return (NULL); |
138 } | 145 } |
139 cursor->curs = NULL; | 146 cursor->curs = NULL; |
140 cursor->ands = NULL; | 147 cursor->ands = NULL; |
141 cursor->xors = NULL; | 148 cursor->xors = NULL; |
142 | 149 |
143 /* Pad out to the normal cursor size */ | 150 /* Pad out to the normal cursor size */ |
144 run = PAD_BITS(w); | 151 run = PAD_BITS(w); |
145 pad = PAD_BITS(allowed_x)-run; | 152 pad = PAD_BITS(allowed_x) - run; |
146 aptr = cursor->ands = (Uint8 *)SDL_malloc((run+pad)*allowed_y); | 153 aptr = cursor->ands = (Uint8 *) SDL_malloc((run + pad) * allowed_y); |
147 xptr = cursor->xors = (Uint8 *)SDL_malloc((run+pad)*allowed_y); | 154 xptr = cursor->xors = (Uint8 *) SDL_malloc((run + pad) * allowed_y); |
148 if ( (aptr == NULL) || (xptr == NULL) ) { | 155 if ((aptr == NULL) || (xptr == NULL)) { |
149 WIN_FreeWMCursor(NULL, cursor); | 156 WIN_FreeWMCursor(NULL, cursor); |
150 SDL_OutOfMemory(); | 157 SDL_OutOfMemory(); |
151 return(NULL); | 158 return (NULL); |
152 } | 159 } |
153 for ( i=0; i<h; ++i ) { | 160 for (i = 0; i < h; ++i) { |
154 memxor(xptr, data, mask, run); | 161 memxor(xptr, data, mask, run); |
155 xptr += run; | 162 xptr += run; |
156 data += run; | 163 data += run; |
157 memnot(aptr, mask, run); | 164 memnot(aptr, mask, run); |
158 mask += run; | 165 mask += run; |
159 aptr += run; | 166 aptr += run; |
160 SDL_memset(xptr, 0, pad); | 167 SDL_memset(xptr, 0, pad); |
161 xptr += pad; | 168 xptr += pad; |
162 SDL_memset(aptr, ~0, pad); | 169 SDL_memset(aptr, ~0, pad); |
163 aptr += pad; | 170 aptr += pad; |
164 } | 171 } |
165 pad += run; | 172 pad += run; |
166 for ( ; i<allowed_y; ++i ) { | 173 for (; i < allowed_y; ++i) { |
167 SDL_memset(xptr, 0, pad); | 174 SDL_memset(xptr, 0, pad); |
168 xptr += pad; | 175 xptr += pad; |
169 SDL_memset(aptr, ~0, pad); | 176 SDL_memset(aptr, ~0, pad); |
170 aptr += pad; | 177 aptr += pad; |
171 } | 178 } |
172 | 179 |
173 /* Create the cursor */ | 180 /* Create the cursor */ |
174 cursor->curs = CreateCursor( | 181 cursor->curs = CreateCursor((HINSTANCE) |
175 (HINSTANCE)GetWindowLongPtr(SDL_Window, GWLP_HINSTANCE), | 182 GetWindowLongPtr(SDL_Window, |
176 hot_x, hot_y, allowed_x, allowed_y, | 183 GWLP_HINSTANCE), hot_x, |
177 cursor->ands, cursor->xors); | 184 hot_y, allowed_x, allowed_y, cursor->ands, |
178 if ( cursor->curs == NULL ) { | 185 cursor->xors); |
179 WIN_FreeWMCursor(NULL, cursor); | 186 if (cursor->curs == NULL) { |
180 SDL_SetError("Windows couldn't create the requested cursor"); | 187 WIN_FreeWMCursor(NULL, cursor); |
181 return(NULL); | 188 SDL_SetError("Windows couldn't create the requested cursor"); |
182 } | 189 return (NULL); |
183 return(cursor); | 190 } |
191 return (cursor); | |
184 #endif /* USE_STATIC_CURSOR */ | 192 #endif /* USE_STATIC_CURSOR */ |
185 } | 193 } |
186 | 194 |
187 int WIN_ShowWMCursor(_THIS, WMcursor *cursor) | 195 int |
188 { | 196 WIN_ShowWMCursor(_THIS, WMcursor * cursor) |
189 POINT mouse_pos; | 197 { |
190 | 198 POINT mouse_pos; |
191 /* The fullscreen cursor must be done in software with DirectInput */ | 199 |
192 if ( !this->screen || DDRAW_FULLSCREEN() ) { | 200 /* The fullscreen cursor must be done in software with DirectInput */ |
193 return(0); | 201 if (!this->screen || DDRAW_FULLSCREEN()) { |
194 } | 202 return (0); |
195 | 203 } |
196 /* Set the window cursor to our cursor, if applicable */ | 204 |
197 if ( cursor != NULL ) { | 205 /* Set the window cursor to our cursor, if applicable */ |
198 SDL_hcursor = cursor->curs; | 206 if (cursor != NULL) { |
199 } else { | 207 SDL_hcursor = cursor->curs; |
200 SDL_hcursor = NULL; | 208 } else { |
201 } | 209 SDL_hcursor = NULL; |
202 GetCursorPos(&mouse_pos); | 210 } |
203 if ( PtInRect(&SDL_bounds, mouse_pos) ) { | 211 GetCursorPos(&mouse_pos); |
204 SetCursor(SDL_hcursor); | 212 if (PtInRect(&SDL_bounds, mouse_pos)) { |
205 } | 213 SetCursor(SDL_hcursor); |
206 return(1); | 214 } |
207 } | 215 return (1); |
208 | 216 } |
209 void WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | 217 |
210 { | 218 void |
211 if ( DDRAW_FULLSCREEN() ) { | 219 WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y) |
212 SDL_PrivateMouseMotion(0, 0, x, y); | 220 { |
213 } else if ( mouse_relative) { | 221 if (DDRAW_FULLSCREEN()) { |
214 /* RJR: March 28, 2000 | 222 SDL_PrivateMouseMotion(0, 0, x, y); |
215 leave physical cursor at center of screen if | 223 } else if (mouse_relative) { |
216 mouse hidden and grabbed */ | 224 /* RJR: March 28, 2000 |
217 SDL_PrivateMouseMotion(0, 0, x, y); | 225 leave physical cursor at center of screen if |
218 } else { | 226 mouse hidden and grabbed */ |
219 POINT pt; | 227 SDL_PrivateMouseMotion(0, 0, x, y); |
220 pt.x = x; | 228 } else { |
221 pt.y = y; | 229 POINT pt; |
222 ClientToScreen(SDL_Window, &pt); | 230 pt.x = x; |
223 SetCursorPos(pt.x, pt.y); | 231 pt.y = y; |
224 } | 232 ClientToScreen(SDL_Window, &pt); |
233 SetCursorPos(pt.x, pt.y); | |
234 } | |
225 } | 235 } |
226 | 236 |
227 /* Update the current mouse state and position */ | 237 /* Update the current mouse state and position */ |
228 void WIN_UpdateMouse(_THIS) | 238 void |
229 { | 239 WIN_UpdateMouse(_THIS) |
230 RECT rect; | 240 { |
231 POINT pt; | 241 RECT rect; |
232 | 242 POINT pt; |
233 if ( ! DDRAW_FULLSCREEN() ) { | 243 |
234 GetClientRect(SDL_Window, &rect); | 244 if (!DDRAW_FULLSCREEN()) { |
235 GetCursorPos(&pt); | 245 GetClientRect(SDL_Window, &rect); |
236 MapWindowPoints(NULL, SDL_Window, &pt, 1); | 246 GetCursorPos(&pt); |
237 if (PtInRect(&rect, pt) && (WindowFromPoint(pt) == SDL_Window)){ | 247 MapWindowPoints(NULL, SDL_Window, &pt, 1); |
238 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | 248 if (PtInRect(&rect, pt) && (WindowFromPoint(pt) == SDL_Window)) { |
239 SDL_PrivateMouseMotion(0,0, (Sint16)pt.x, (Sint16)pt.y); | 249 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); |
240 } else { | 250 SDL_PrivateMouseMotion(0, 0, (Sint16) pt.x, (Sint16) pt.y); |
241 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | 251 } else { |
242 } | 252 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); |
243 } | 253 } |
254 } | |
244 } | 255 } |
245 | 256 |
246 /* Check to see if we need to enter or leave mouse relative mode */ | 257 /* Check to see if we need to enter or leave mouse relative mode */ |
247 void WIN_CheckMouseMode(_THIS) | 258 void |
248 { | 259 WIN_CheckMouseMode(_THIS) |
249 #ifndef _WIN32_WCE | 260 { |
250 /* If the mouse is hidden and input is grabbed, we use relative mode */ | 261 #ifndef _WIN32_WCE |
251 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && | 262 /* If the mouse is hidden and input is grabbed, we use relative mode */ |
252 (this->input_grab != SDL_GRAB_OFF) ) { | 263 if (!(SDL_cursorstate & CURSOR_VISIBLE) && |
253 mouse_relative = 1; | 264 (this->input_grab != SDL_GRAB_OFF)) { |
254 } else { | 265 mouse_relative = 1; |
255 mouse_relative = 0; | 266 } else { |
256 } | 267 mouse_relative = 0; |
268 } | |
257 #else | 269 #else |
258 mouse_relative = 0; | 270 mouse_relative = 0; |
259 #endif | 271 #endif |
260 } | 272 } |
273 | |
274 /* vi: set ts=4 sw=4 expandtab: */ |