comparison src/video/SDL_cursor.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children eef792d31de8
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
40 static SDL_Cursor *SDL_defcursor = NULL; 40 static SDL_Cursor *SDL_defcursor = NULL;
41 SDL_mutex *SDL_cursorlock = NULL; 41 SDL_mutex *SDL_cursorlock = NULL;
42 42
43 /* Public functions */ 43 /* Public functions */
44 void 44 void
45 SDL_CursorQuit (void) 45 SDL_CursorQuit(void)
46 { 46 {
47 if (SDL_cursor != NULL) { 47 if (SDL_cursor != NULL) {
48 SDL_Cursor *cursor; 48 SDL_Cursor *cursor;
49 49
50 SDL_cursorstate &= ~CURSOR_VISIBLE; 50 SDL_cursorstate &= ~CURSOR_VISIBLE;
51 if (SDL_cursor != SDL_defcursor) { 51 if (SDL_cursor != SDL_defcursor) {
52 SDL_FreeCursor (SDL_cursor); 52 SDL_FreeCursor(SDL_cursor);
53 } 53 }
54 SDL_cursor = NULL; 54 SDL_cursor = NULL;
55 if (SDL_defcursor != NULL) { 55 if (SDL_defcursor != NULL) {
56 cursor = SDL_defcursor; 56 cursor = SDL_defcursor;
57 SDL_defcursor = NULL; 57 SDL_defcursor = NULL;
58 SDL_FreeCursor (cursor); 58 SDL_FreeCursor(cursor);
59 } 59 }
60 } 60 }
61 if (SDL_cursorlock != NULL) { 61 if (SDL_cursorlock != NULL) {
62 SDL_DestroyMutex (SDL_cursorlock); 62 SDL_DestroyMutex(SDL_cursorlock);
63 SDL_cursorlock = NULL; 63 SDL_cursorlock = NULL;
64 } 64 }
65 } 65 }
66 int 66 int
67 SDL_CursorInit (Uint32 multithreaded) 67 SDL_CursorInit(Uint32 multithreaded)
68 { 68 {
69 /* We don't have mouse focus, and the cursor isn't drawn yet */ 69 /* We don't have mouse focus, and the cursor isn't drawn yet */
70 #ifndef IPOD 70 #ifndef IPOD
71 SDL_cursorstate = CURSOR_VISIBLE; 71 SDL_cursorstate = CURSOR_VISIBLE;
72 #endif 72 #endif
73 73
74 /* Create the default cursor */ 74 /* Create the default cursor */
75 if (SDL_defcursor == NULL) { 75 if (SDL_defcursor == NULL) {
76 SDL_defcursor = SDL_CreateCursor (default_cdata, default_cmask, 76 SDL_defcursor = SDL_CreateCursor(default_cdata, default_cmask,
77 DEFAULT_CWIDTH, DEFAULT_CHEIGHT, 77 DEFAULT_CWIDTH, DEFAULT_CHEIGHT,
78 DEFAULT_CHOTX, DEFAULT_CHOTY); 78 DEFAULT_CHOTX, DEFAULT_CHOTY);
79 SDL_SetCursor (SDL_defcursor); 79 SDL_SetCursor(SDL_defcursor);
80 } 80 }
81 81
82 /* Create a lock if necessary */ 82 /* Create a lock if necessary */
83 if (multithreaded) { 83 if (multithreaded) {
84 SDL_cursorlock = SDL_CreateMutex (); 84 SDL_cursorlock = SDL_CreateMutex();
85 } 85 }
86 86
87 /* That's it! */ 87 /* That's it! */
88 return (0); 88 return (0);
89 } 89 }
90 90
91 /* Multi-thread support for cursors */ 91 /* Multi-thread support for cursors */
92 #ifndef SDL_LockCursor 92 #ifndef SDL_LockCursor
93 void 93 void
94 SDL_LockCursor (void) 94 SDL_LockCursor(void)
95 { 95 {
96 if (SDL_cursorlock) { 96 if (SDL_cursorlock) {
97 SDL_mutexP (SDL_cursorlock); 97 SDL_mutexP(SDL_cursorlock);
98 } 98 }
99 } 99 }
100 #endif 100 #endif
101 #ifndef SDL_UnlockCursor 101 #ifndef SDL_UnlockCursor
102 void 102 void
103 SDL_UnlockCursor (void) 103 SDL_UnlockCursor(void)
104 { 104 {
105 if (SDL_cursorlock) { 105 if (SDL_cursorlock) {
106 SDL_mutexV (SDL_cursorlock); 106 SDL_mutexV(SDL_cursorlock);
107 } 107 }
108 } 108 }
109 #endif 109 #endif
110 110
111 /* Software cursor drawing support */ 111 /* Software cursor drawing support */
112 SDL_Cursor * 112 SDL_Cursor *
113 SDL_CreateCursor (Uint8 * data, Uint8 * mask, 113 SDL_CreateCursor(Uint8 * data, Uint8 * mask,
114 int w, int h, int hot_x, int hot_y) 114 int w, int h, int hot_x, int hot_y)
115 { 115 {
116 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 116 SDL_VideoDevice *_this = SDL_GetVideoDevice();
117 int savelen; 117 int savelen;
118 int i; 118 int i;
119 SDL_Cursor *cursor; 119 SDL_Cursor *cursor;
120 120
121 /* Make sure the width is a multiple of 8 */ 121 /* Make sure the width is a multiple of 8 */
122 w = ((w + 7) & ~7); 122 w = ((w + 7) & ~7);
123 123
124 /* Sanity check the hot spot */ 124 /* Sanity check the hot spot */
125 if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) { 125 if ((hot_x < 0) || (hot_y < 0) || (hot_x >= w) || (hot_y >= h)) {
126 SDL_SetError ("Cursor hot spot doesn't lie within cursor"); 126 SDL_SetError("Cursor hot spot doesn't lie within cursor");
127 return (NULL); 127 return (NULL);
128 } 128 }
129 129
130 /* Allocate memory for the cursor */ 130 /* Allocate memory for the cursor */
131 cursor = (SDL_Cursor *) SDL_malloc (sizeof *cursor); 131 cursor = (SDL_Cursor *) SDL_malloc(sizeof *cursor);
132 if (cursor == NULL) { 132 if (cursor == NULL) {
133 SDL_OutOfMemory (); 133 SDL_OutOfMemory();
134 return (NULL); 134 return (NULL);
135 } 135 }
136 savelen = (w * 4) * h; 136 savelen = (w * 4) * h;
137 cursor->area.x = 0; 137 cursor->area.x = 0;
138 cursor->area.y = 0; 138 cursor->area.y = 0;
139 cursor->area.w = w; 139 cursor->area.w = w;
140 cursor->area.h = h; 140 cursor->area.h = h;
141 cursor->hot_x = hot_x; 141 cursor->hot_x = hot_x;
142 cursor->hot_y = hot_y; 142 cursor->hot_y = hot_y;
143 cursor->data = (Uint8 *) SDL_malloc ((w / 8) * h * 2); 143 cursor->data = (Uint8 *) SDL_malloc((w / 8) * h * 2);
144 cursor->mask = cursor->data + ((w / 8) * h); 144 cursor->mask = cursor->data + ((w / 8) * h);
145 cursor->save[0] = (Uint8 *) SDL_malloc (savelen * 2); 145 cursor->save[0] = (Uint8 *) SDL_malloc(savelen * 2);
146 cursor->save[1] = cursor->save[0] + savelen; 146 cursor->save[1] = cursor->save[0] + savelen;
147 cursor->wm_cursor = NULL; 147 cursor->wm_cursor = NULL;
148 if (!cursor->data || !cursor->save[0]) { 148 if (!cursor->data || !cursor->save[0]) {
149 SDL_FreeCursor (cursor); 149 SDL_FreeCursor(cursor);
150 SDL_OutOfMemory (); 150 SDL_OutOfMemory();
151 return (NULL); 151 return (NULL);
152 } 152 }
153 for (i = ((w / 8) * h) - 1; i >= 0; --i) { 153 for (i = ((w / 8) * h) - 1; i >= 0; --i) {
154 cursor->data[i] = data[i]; 154 cursor->data[i] = data[i];
155 cursor->mask[i] = mask[i] | data[i]; 155 cursor->mask[i] = mask[i] | data[i];
156 } 156 }
157 SDL_memset (cursor->save[0], 0, savelen * 2); 157 SDL_memset(cursor->save[0], 0, savelen * 2);
158 158
159 /* If the window manager gives us a good cursor, we're done! */ 159 /* If the window manager gives us a good cursor, we're done! */
160 if (_this->CreateWMCursor) { 160 if (_this->CreateWMCursor) {
161 cursor->wm_cursor = _this->CreateWMCursor (_this, data, mask, 161 cursor->wm_cursor = _this->CreateWMCursor(_this, data, mask,
162 w, h, hot_x, hot_y); 162 w, h, hot_x, hot_y);
163 } else { 163 } else {
164 cursor->wm_cursor = NULL; 164 cursor->wm_cursor = NULL;
165 } 165 }
166 return (cursor); 166 return (cursor);
167 } 167 }
169 /* SDL_SetCursor(NULL) can be used to force the cursor redraw, 169 /* SDL_SetCursor(NULL) can be used to force the cursor redraw,
170 if this is desired for any reason. This is used when setting 170 if this is desired for any reason. This is used when setting
171 the video mode and when the SDL window gains the mouse focus. 171 the video mode and when the SDL window gains the mouse focus.
172 */ 172 */
173 void 173 void
174 SDL_SetCursor (SDL_Cursor * cursor) 174 SDL_SetCursor(SDL_Cursor * cursor)
175 { 175 {
176 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 176 SDL_VideoDevice *_this = SDL_GetVideoDevice();
177 177
178 /* Make sure that the video subsystem has been initialized */ 178 /* Make sure that the video subsystem has been initialized */
179 if (!_this) { 179 if (!_this) {
180 return; 180 return;
181 } 181 }
182 182
183 /* Prevent the event thread from moving the mouse */ 183 /* Prevent the event thread from moving the mouse */
184 SDL_LockCursor (); 184 SDL_LockCursor();
185 185
186 /* Set the new cursor */ 186 /* Set the new cursor */
187 if (cursor && (cursor != SDL_cursor)) { 187 if (cursor && (cursor != SDL_cursor)) {
188 /* Erase the current mouse position */ 188 /* Erase the current mouse position */
189 if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { 189 if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
190 SDL_EraseCursor (SDL_VideoSurface); 190 SDL_EraseCursor(SDL_VideoSurface);
191 } else if (_this->MoveWMCursor) { 191 } else if (_this->MoveWMCursor) {
192 /* If the video driver is moving the cursor directly, 192 /* If the video driver is moving the cursor directly,
193 it needs to hide the old cursor before (possibly) 193 it needs to hide the old cursor before (possibly)
194 showing the new one. (But don't erase NULL cursor) 194 showing the new one. (But don't erase NULL cursor)
195 */ 195 */
196 if (SDL_cursor) { 196 if (SDL_cursor) {
197 _this->ShowWMCursor (_this, NULL); 197 _this->ShowWMCursor(_this, NULL);
198 } 198 }
199 } 199 }
200 SDL_cursor = cursor; 200 SDL_cursor = cursor;
201 } 201 }
202 202
203 /* Draw the new mouse cursor */ 203 /* Draw the new mouse cursor */
204 if (SDL_cursor && (SDL_cursorstate & CURSOR_VISIBLE)) { 204 if (SDL_cursor && (SDL_cursorstate & CURSOR_VISIBLE)) {
205 /* Use window manager cursor if possible */ 205 /* Use window manager cursor if possible */
206 if (SDL_cursor->wm_cursor && 206 if (SDL_cursor->wm_cursor &&
207 _this->ShowWMCursor (_this, SDL_cursor->wm_cursor)) { 207 _this->ShowWMCursor(_this, SDL_cursor->wm_cursor)) {
208 SDL_cursorstate &= ~CURSOR_USINGSW; 208 SDL_cursorstate &= ~CURSOR_USINGSW;
209 } else { 209 } else {
210 SDL_cursorstate |= CURSOR_USINGSW; 210 SDL_cursorstate |= CURSOR_USINGSW;
211 if (_this->ShowWMCursor) { 211 if (_this->ShowWMCursor) {
212 _this->ShowWMCursor (_this, NULL); 212 _this->ShowWMCursor(_this, NULL);
213 } 213 }
214 { 214 {
215 int x, y; 215 int x, y;
216 SDL_GetMouseState (&x, &y); 216 SDL_GetMouseState(&x, &y);
217 SDL_cursor->area.x = (x - SDL_cursor->hot_x); 217 SDL_cursor->area.x = (x - SDL_cursor->hot_x);
218 SDL_cursor->area.y = (y - SDL_cursor->hot_y); 218 SDL_cursor->area.y = (y - SDL_cursor->hot_y);
219 } 219 }
220 SDL_DrawCursor (SDL_VideoSurface); 220 SDL_DrawCursor(SDL_VideoSurface);
221 } 221 }
222 } else { 222 } else {
223 /* Erase window manager mouse (cursor not visible) */ 223 /* Erase window manager mouse (cursor not visible) */
224 if (SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW)) { 224 if (SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW)) {
225 SDL_EraseCursor (SDL_VideoSurface); 225 SDL_EraseCursor(SDL_VideoSurface);
226 } else { 226 } else {
227 if (_this) { 227 if (_this) {
228 _this->ShowWMCursor (_this, NULL); 228 _this->ShowWMCursor(_this, NULL);
229 } 229 }
230 } 230 }
231 } 231 }
232 SDL_UnlockCursor (); 232 SDL_UnlockCursor();
233 } 233 }
234 234
235 SDL_Cursor * 235 SDL_Cursor *
236 SDL_GetCursor (void) 236 SDL_GetCursor(void)
237 { 237 {
238 return (SDL_cursor); 238 return (SDL_cursor);
239 } 239 }
240 240
241 void 241 void
242 SDL_FreeCursor (SDL_Cursor * cursor) 242 SDL_FreeCursor(SDL_Cursor * cursor)
243 { 243 {
244 if (cursor) { 244 if (cursor) {
245 if (cursor == SDL_cursor) { 245 if (cursor == SDL_cursor) {
246 SDL_SetCursor (SDL_defcursor); 246 SDL_SetCursor(SDL_defcursor);
247 } 247 }
248 if (cursor != SDL_defcursor) { 248 if (cursor != SDL_defcursor) {
249 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 249 SDL_VideoDevice *_this = SDL_GetVideoDevice();
250 250
251 if (cursor->data) { 251 if (cursor->data) {
252 SDL_free (cursor->data); 252 SDL_free(cursor->data);
253 } 253 }
254 if (cursor->save[0]) { 254 if (cursor->save[0]) {
255 SDL_free (cursor->save[0]); 255 SDL_free(cursor->save[0]);
256 } 256 }
257 if (_this && cursor->wm_cursor) { 257 if (_this && cursor->wm_cursor) {
258 _this->FreeWMCursor (_this, cursor->wm_cursor); 258 _this->FreeWMCursor(_this, cursor->wm_cursor);
259 } 259 }
260 SDL_free (cursor); 260 SDL_free(cursor);
261 } 261 }
262 } 262 }
263 } 263 }
264 264
265 int 265 int
266 SDL_ShowCursor (int toggle) 266 SDL_ShowCursor(int toggle)
267 { 267 {
268 int showing; 268 int showing;
269 269
270 showing = (SDL_cursorstate & CURSOR_VISIBLE); 270 showing = (SDL_cursorstate & CURSOR_VISIBLE);
271 if (toggle >= 0) { 271 if (toggle >= 0) {
272 SDL_LockCursor (); 272 SDL_LockCursor();
273 if (toggle) { 273 if (toggle) {
274 SDL_cursorstate |= CURSOR_VISIBLE; 274 SDL_cursorstate |= CURSOR_VISIBLE;
275 } else { 275 } else {
276 SDL_cursorstate &= ~CURSOR_VISIBLE; 276 SDL_cursorstate &= ~CURSOR_VISIBLE;
277 } 277 }
278 SDL_UnlockCursor (); 278 SDL_UnlockCursor();
279 if ((SDL_cursorstate & CURSOR_VISIBLE) != showing) { 279 if ((SDL_cursorstate & CURSOR_VISIBLE) != showing) {
280 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 280 SDL_VideoDevice *_this = SDL_GetVideoDevice();
281 281
282 SDL_SetCursor (NULL); 282 SDL_SetCursor(NULL);
283 if (_this && _this->CheckMouseMode) { 283 if (_this && _this->CheckMouseMode) {
284 _this->CheckMouseMode (_this); 284 _this->CheckMouseMode(_this);
285 } 285 }
286 } 286 }
287 } else { 287 } else {
288 /* Query current state */ ; 288 /* Query current state */ ;
289 } 289 }
290 return (showing ? 1 : 0); 290 return (showing ? 1 : 0);
291 } 291 }
292 292
293 void 293 void
294 SDL_WarpMouse (Uint16 x, Uint16 y) 294 SDL_WarpMouse(Uint16 x, Uint16 y)
295 { 295 {
296 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 296 SDL_VideoDevice *_this = SDL_GetVideoDevice();
297 297
298 if (!_this || !SDL_PublicSurface) { 298 if (!_this || !SDL_PublicSurface) {
299 SDL_SetError ("A video mode must be set before warping mouse"); 299 SDL_SetError("A video mode must be set before warping mouse");
300 return; 300 return;
301 } 301 }
302 302
303 /* If we have an offset video mode, offset the mouse coordinates */ 303 /* If we have an offset video mode, offset the mouse coordinates */
304 if (SDL_VideoSurface->pitch == 0) { 304 if (SDL_VideoSurface->pitch == 0) {
311 y += (SDL_VideoSurface->offset / SDL_VideoSurface->pitch); 311 y += (SDL_VideoSurface->offset / SDL_VideoSurface->pitch);
312 } 312 }
313 313
314 /* This generates a mouse motion event */ 314 /* This generates a mouse motion event */
315 if (_this->WarpWMCursor) { 315 if (_this->WarpWMCursor) {
316 _this->WarpWMCursor (_this, x, y); 316 _this->WarpWMCursor(_this, x, y);
317 } else { 317 } else {
318 SDL_PrivateMouseMotion (0, 0, x, y); 318 SDL_PrivateMouseMotion(0, 0, x, y);
319 } 319 }
320 } 320 }
321 321
322 void 322 void
323 SDL_MoveCursor (int x, int y) 323 SDL_MoveCursor(int x, int y)
324 { 324 {
325 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 325 SDL_VideoDevice *_this = SDL_GetVideoDevice();
326 326
327 /* Erase and update the current mouse position */ 327 /* Erase and update the current mouse position */
328 if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { 328 if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
329 /* Erase and redraw mouse cursor in new position */ 329 /* Erase and redraw mouse cursor in new position */
330 SDL_LockCursor (); 330 SDL_LockCursor();
331 SDL_EraseCursor (SDL_VideoSurface); 331 SDL_EraseCursor(SDL_VideoSurface);
332 SDL_cursor->area.x = (x - SDL_cursor->hot_x); 332 SDL_cursor->area.x = (x - SDL_cursor->hot_x);
333 SDL_cursor->area.y = (y - SDL_cursor->hot_y); 333 SDL_cursor->area.y = (y - SDL_cursor->hot_y);
334 SDL_DrawCursor (SDL_VideoSurface); 334 SDL_DrawCursor(SDL_VideoSurface);
335 SDL_UnlockCursor (); 335 SDL_UnlockCursor();
336 } else if (_this->MoveWMCursor) { 336 } else if (_this->MoveWMCursor) {
337 _this->MoveWMCursor (_this, x, y); 337 _this->MoveWMCursor(_this, x, y);
338 } 338 }
339 } 339 }
340 340
341 /* Keep track of the current cursor colors */ 341 /* Keep track of the current cursor colors */
342 static int palette_changed = 1; 342 static int palette_changed = 1;
343 static Uint8 pixels8[2]; 343 static Uint8 pixels8[2];
344 344
345 void 345 void
346 SDL_CursorPaletteChanged (void) 346 SDL_CursorPaletteChanged(void)
347 { 347 {
348 palette_changed = 1; 348 palette_changed = 1;
349 } 349 }
350 350
351 void 351 void
352 SDL_MouseRect (SDL_Rect * area) 352 SDL_MouseRect(SDL_Rect * area)
353 { 353 {
354 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 354 SDL_VideoDevice *_this = SDL_GetVideoDevice();
355 int clip_diff; 355 int clip_diff;
356 356
357 *area = SDL_cursor->area; 357 *area = SDL_cursor->area;
358 if (area->x < 0) { 358 if (area->x < 0) {
359 area->w += area->x; 359 area->w += area->x;
372 area->h = area->h < clip_diff ? 0 : area->h - clip_diff; 372 area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
373 } 373 }
374 } 374 }
375 375
376 static void 376 static void
377 SDL_DrawCursorFast (SDL_Surface * screen, SDL_Rect * area) 377 SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
378 { 378 {
379 const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 }; 379 const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
380 int i, w, h; 380 int i, w, h;
381 Uint8 *data, datab; 381 Uint8 *data, datab;
382 Uint8 *mask, maskb; 382 Uint8 *mask, maskb;
390 Uint8 *dst; 390 Uint8 *dst;
391 int dstskip; 391 int dstskip;
392 392
393 if (palette_changed) { 393 if (palette_changed) {
394 pixels8[0] = 394 pixels8[0] =
395 (Uint8) SDL_MapRGB (screen->format, 255, 255, 255); 395 (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
396 pixels8[1] = (Uint8) SDL_MapRGB (screen->format, 0, 0, 0); 396 pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
397 palette_changed = 0; 397 palette_changed = 0;
398 } 398 }
399 dst = (Uint8 *) screen->pixels + 399 dst = (Uint8 *) screen->pixels +
400 (SDL_cursor->area.y + area->y) * screen->pitch + 400 (SDL_cursor->area.y + area->y) * screen->pitch +
401 SDL_cursor->area.x; 401 SDL_cursor->area.x;
461 for (w = area->w / 8; w; w--) { 461 for (w = area->w / 8; w; w--) {
462 maskb = *mask++; 462 maskb = *mask++;
463 datab = *data++; 463 datab = *data++;
464 for (i = 0; i < 8; ++i) { 464 for (i = 0; i < 8; ++i) {
465 if (maskb & 0x80) { 465 if (maskb & 0x80) {
466 SDL_memset (dst, pixels[datab >> 7], 3); 466 SDL_memset(dst, pixels[datab >> 7], 3);
467 } 467 }
468 maskb <<= 1; 468 maskb <<= 1;
469 datab <<= 1; 469 datab <<= 1;
470 dst += 3; 470 dst += 3;
471 } 471 }
504 break; 504 break;
505 } 505 }
506 } 506 }
507 507
508 static void 508 static void
509 SDL_DrawCursorSlow (SDL_Surface * screen, SDL_Rect * area) 509 SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
510 { 510 {
511 const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 }; 511 const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
512 int h; 512 int h;
513 int x, minx, maxx; 513 int x, minx, maxx;
514 Uint8 *data, datab = 0; 514 Uint8 *data, datab = 0;
526 526
527 minx = area->x; 527 minx = area->x;
528 maxx = area->x + area->w; 528 maxx = area->x + area->w;
529 if (screen->format->BytesPerPixel == 1) { 529 if (screen->format->BytesPerPixel == 1) {
530 if (palette_changed) { 530 if (palette_changed) {
531 pixels8[0] = (Uint8) SDL_MapRGB (screen->format, 255, 255, 255); 531 pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
532 pixels8[1] = (Uint8) SDL_MapRGB (screen->format, 0, 0, 0); 532 pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
533 palette_changed = 0; 533 palette_changed = 0;
534 } 534 }
535 for (h = area->h; h; h--) { 535 for (h = area->h; h; h--) {
536 for (x = 0; x < SDL_cursor->area.w; ++x) { 536 for (x = 0; x < SDL_cursor->area.w; ++x) {
537 if ((x % 8) == 0) { 537 if ((x % 8) == 0) {
538 maskb = *mask++; 538 maskb = *mask++;
539 datab = *data++; 539 datab = *data++;
540 } 540 }
541 if ((x >= minx) && (x < maxx)) { 541 if ((x >= minx) && (x < maxx)) {
542 if (maskb & 0x80) { 542 if (maskb & 0x80) {
543 SDL_memset (dst, pixels8[datab >> 7], dstbpp); 543 SDL_memset(dst, pixels8[datab >> 7], dstbpp);
544 } 544 }
545 } 545 }
546 maskb <<= 1; 546 maskb <<= 1;
547 datab <<= 1; 547 datab <<= 1;
548 dst += dstbpp; 548 dst += dstbpp;
556 maskb = *mask++; 556 maskb = *mask++;
557 datab = *data++; 557 datab = *data++;
558 } 558 }
559 if ((x >= minx) && (x < maxx)) { 559 if ((x >= minx) && (x < maxx)) {
560 if (maskb & 0x80) { 560 if (maskb & 0x80) {
561 SDL_memset (dst, pixels[datab >> 7], dstbpp); 561 SDL_memset(dst, pixels[datab >> 7], dstbpp);
562 } 562 }
563 } 563 }
564 maskb <<= 1; 564 maskb <<= 1;
565 datab <<= 1; 565 datab <<= 1;
566 dst += dstbpp; 566 dst += dstbpp;
574 the pixel format of the shadow surface to that of the video surface. 574 the pixel format of the shadow surface to that of the video surface.
575 This is only necessary when blitting from a shadow surface of a different 575 This is only necessary when blitting from a shadow surface of a different
576 pixel format than the video surface, and using a software rendered cursor. 576 pixel format than the video surface, and using a software rendered cursor.
577 */ 577 */
578 static void 578 static void
579 SDL_ConvertCursorSave (SDL_Surface * screen, int w, int h) 579 SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
580 { 580 {
581 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 581 SDL_VideoDevice *_this = SDL_GetVideoDevice();
582 SDL_BlitInfo info; 582 SDL_BlitInfo info;
583 SDL_loblit RunBlit; 583 SDL_loblit RunBlit;
584 584
585 /* Make sure we can steal the blit mapping */ 585 /* Make sure we can steal the blit mapping */
586 if (screen->map->dst != SDL_VideoSurface) { 586 if (screen->map->dst != SDL_VideoSurface) {
601 info.table = screen->map->table; 601 info.table = screen->map->table;
602 info.dst = SDL_VideoSurface->format; 602 info.dst = SDL_VideoSurface->format;
603 RunBlit = screen->map->sw_data->blit; 603 RunBlit = screen->map->sw_data->blit;
604 604
605 /* Run the actual software blit */ 605 /* Run the actual software blit */
606 RunBlit (&info); 606 RunBlit(&info);
607 } 607 }
608 608
609 void 609 void
610 SDL_DrawCursorNoLock (SDL_Surface * screen) 610 SDL_DrawCursorNoLock(SDL_Surface * screen)
611 { 611 {
612 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 612 SDL_VideoDevice *_this = SDL_GetVideoDevice();
613 SDL_Rect area; 613 SDL_Rect area;
614 614
615 /* Get the mouse rectangle, clipped to the screen */ 615 /* Get the mouse rectangle, clipped to the screen */
616 SDL_MouseRect (&area); 616 SDL_MouseRect(&area);
617 if ((area.w == 0) || (area.h == 0)) { 617 if ((area.w == 0) || (area.h == 0)) {
618 return; 618 return;
619 } 619 }
620 620
621 /* Copy mouse background */ 621 /* Copy mouse background */
624 Uint8 *src, *dst; 624 Uint8 *src, *dst;
625 625
626 /* Set up the copy pointers */ 626 /* Set up the copy pointers */
627 screenbpp = screen->format->BytesPerPixel; 627 screenbpp = screen->format->BytesPerPixel;
628 if ((screen == SDL_VideoSurface) || 628 if ((screen == SDL_VideoSurface) ||
629 FORMAT_EQUAL (screen->format, SDL_VideoSurface->format)) { 629 FORMAT_EQUAL(screen->format, SDL_VideoSurface->format)) {
630 dst = SDL_cursor->save[0]; 630 dst = SDL_cursor->save[0];
631 } else { 631 } else {
632 dst = SDL_cursor->save[1]; 632 dst = SDL_cursor->save[1];
633 } 633 }
634 src = (Uint8 *) screen->pixels + area.y * screen->pitch + 634 src = (Uint8 *) screen->pixels + area.y * screen->pitch +
636 636
637 /* Perform the copy */ 637 /* Perform the copy */
638 w = area.w * screenbpp; 638 w = area.w * screenbpp;
639 h = area.h; 639 h = area.h;
640 while (h--) { 640 while (h--) {
641 SDL_memcpy (dst, src, w); 641 SDL_memcpy(dst, src, w);
642 dst += w; 642 dst += w;
643 src += screen->pitch; 643 src += screen->pitch;
644 } 644 }
645 } 645 }
646 646
647 /* Draw the mouse cursor */ 647 /* Draw the mouse cursor */
648 area.x -= SDL_cursor->area.x; 648 area.x -= SDL_cursor->area.x;
649 area.y -= SDL_cursor->area.y; 649 area.y -= SDL_cursor->area.y;
650 if ((area.x == 0) && (area.w == SDL_cursor->area.w)) { 650 if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
651 SDL_DrawCursorFast (screen, &area); 651 SDL_DrawCursorFast(screen, &area);
652 } else { 652 } else {
653 SDL_DrawCursorSlow (screen, &area); 653 SDL_DrawCursorSlow(screen, &area);
654 } 654 }
655 } 655 }
656 656
657 void 657 void
658 SDL_DrawCursor (SDL_Surface * screen) 658 SDL_DrawCursor(SDL_Surface * screen)
659 { 659 {
660 /* Lock the screen if necessary */ 660 /* Lock the screen if necessary */
661 if (screen == NULL) { 661 if (screen == NULL) {
662 return; 662 return;
663 } 663 }
664 if (SDL_MUSTLOCK (screen)) { 664 if (SDL_MUSTLOCK(screen)) {
665 if (SDL_LockSurface (screen) < 0) { 665 if (SDL_LockSurface(screen) < 0) {
666 return; 666 return;
667 } 667 }
668 } 668 }
669 669
670 SDL_DrawCursorNoLock (screen); 670 SDL_DrawCursorNoLock(screen);
671 671
672 /* Unlock the screen and update if necessary */ 672 /* Unlock the screen and update if necessary */
673 if (SDL_MUSTLOCK (screen)) { 673 if (SDL_MUSTLOCK(screen)) {
674 SDL_UnlockSurface (screen); 674 SDL_UnlockSurface(screen);
675 } 675 }
676 if ((screen->flags & SDL_SCREEN_SURFACE) && 676 if ((screen->flags & SDL_SCREEN_SURFACE) &&
677 !(screen->flags & SDL_HWSURFACE)) { 677 !(screen->flags & SDL_HWSURFACE)) {
678 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 678 SDL_VideoDevice *_this = SDL_GetVideoDevice();
679 SDL_Window *window; 679 SDL_Window *window;
680 SDL_Rect area; 680 SDL_Rect area;
681 681
682 window = SDL_GetWindowFromSurface (screen); 682 window = SDL_GetWindowFromSurface(screen);
683 if (!window) { 683 if (!window) {
684 return; 684 return;
685 } 685 }
686 686
687 SDL_MouseRect (&area); 687 SDL_MouseRect(&area);
688 688
689 if (_this->UpdateWindowSurface) { 689 if (_this->UpdateWindowSurface) {
690 _this->UpdateWindowSurface (_this, window, 1, &area); 690 _this->UpdateWindowSurface(_this, window, 1, &area);
691 } 691 }
692 } 692 }
693 } 693 }
694 694
695 void 695 void
696 SDL_EraseCursorNoLock (SDL_Surface * screen) 696 SDL_EraseCursorNoLock(SDL_Surface * screen)
697 { 697 {
698 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 698 SDL_VideoDevice *_this = SDL_GetVideoDevice();
699 SDL_Window *window; 699 SDL_Window *window;
700 SDL_Rect area; 700 SDL_Rect area;
701 701
702 /* Get the window associated with the surface */ 702 /* Get the window associated with the surface */
703 window = SDL_GetWindowFromSurface (screen); 703 window = SDL_GetWindowFromSurface(screen);
704 if (!window || !window->surface) { 704 if (!window || !window->surface) {
705 return; 705 return;
706 } 706 }
707 707
708 /* Get the mouse rectangle, clipped to the screen */ 708 /* Get the mouse rectangle, clipped to the screen */
709 SDL_MouseRect (&area); 709 SDL_MouseRect(&area);
710 if ((area.w == 0) || (area.h == 0)) { 710 if ((area.w == 0) || (area.h == 0)) {
711 return; 711 return;
712 } 712 }
713 713
714 /* Copy mouse background */ 714 /* Copy mouse background */
717 Uint8 *src, *dst; 717 Uint8 *src, *dst;
718 718
719 /* Set up the copy pointers */ 719 /* Set up the copy pointers */
720 screenbpp = screen->format->BytesPerPixel; 720 screenbpp = screen->format->BytesPerPixel;
721 if ((screen->flags & SDL_SCREEN_SURFACE) || 721 if ((screen->flags & SDL_SCREEN_SURFACE) ||
722 FORMAT_EQUAL (screen->format, window->surface->format)) { 722 FORMAT_EQUAL(screen->format, window->surface->format)) {
723 src = SDL_cursor->save[0]; 723 src = SDL_cursor->save[0];
724 } else { 724 } else {
725 src = SDL_cursor->save[1]; 725 src = SDL_cursor->save[1];
726 } 726 }
727 dst = (Uint8 *) screen->pixels + area.y * screen->pitch + 727 dst = (Uint8 *) screen->pixels + area.y * screen->pitch +
729 729
730 /* Perform the copy */ 730 /* Perform the copy */
731 w = area.w * screenbpp; 731 w = area.w * screenbpp;
732 h = area.h; 732 h = area.h;
733 while (h--) { 733 while (h--) {
734 SDL_memcpy (dst, src, w); 734 SDL_memcpy(dst, src, w);
735 src += w; 735 src += w;
736 dst += screen->pitch; 736 dst += screen->pitch;
737 } 737 }
738 738
739 /* Perform pixel conversion on cursor background */ 739 /* Perform pixel conversion on cursor background */
740 if (src > SDL_cursor->save[1]) { 740 if (src > SDL_cursor->save[1]) {
741 SDL_ConvertCursorSave (screen, area.w, area.h); 741 SDL_ConvertCursorSave(screen, area.w, area.h);
742 } 742 }
743 } 743 }
744 } 744 }
745 745
746 void 746 void
747 SDL_EraseCursor (SDL_Surface * screen) 747 SDL_EraseCursor(SDL_Surface * screen)
748 { 748 {
749 /* Lock the screen if necessary */ 749 /* Lock the screen if necessary */
750 if (screen == NULL) { 750 if (screen == NULL) {
751 return; 751 return;
752 } 752 }
753 if (SDL_MUSTLOCK (screen)) { 753 if (SDL_MUSTLOCK(screen)) {
754 if (SDL_LockSurface (screen) < 0) { 754 if (SDL_LockSurface(screen) < 0) {
755 return; 755 return;
756 } 756 }
757 } 757 }
758 758
759 SDL_EraseCursorNoLock (screen); 759 SDL_EraseCursorNoLock(screen);
760 760
761 /* Unlock the screen and update if necessary */ 761 /* Unlock the screen and update if necessary */
762 if (SDL_MUSTLOCK (screen)) { 762 if (SDL_MUSTLOCK(screen)) {
763 SDL_UnlockSurface (screen); 763 SDL_UnlockSurface(screen);
764 } 764 }
765 if ((screen->flags & SDL_SCREEN_SURFACE) && 765 if ((screen->flags & SDL_SCREEN_SURFACE) &&
766 !(screen->flags & SDL_HWSURFACE)) { 766 !(screen->flags & SDL_HWSURFACE)) {
767 SDL_VideoDevice *_this = SDL_GetVideoDevice (); 767 SDL_VideoDevice *_this = SDL_GetVideoDevice();
768 SDL_Window *window; 768 SDL_Window *window;
769 SDL_Rect area; 769 SDL_Rect area;
770 770
771 window = SDL_GetWindowFromSurface (screen); 771 window = SDL_GetWindowFromSurface(screen);
772 if (!window) { 772 if (!window) {
773 return; 773 return;
774 } 774 }
775 775
776 SDL_MouseRect (&area); 776 SDL_MouseRect(&area);
777 777
778 if (_this->UpdateWindowSurface) { 778 if (_this->UpdateWindowSurface) {
779 _this->UpdateWindowSurface (_this, window, 1, &area); 779 _this->UpdateWindowSurface(_this, window, 1, &area);
780 } 780 }
781 } 781 }
782 } 782 }
783 783
784 /* Reset the cursor on video mode change 784 /* Reset the cursor on video mode change
785 FIXME: Keep track of all cursors, and reset them all. 785 FIXME: Keep track of all cursors, and reset them all.
786 */ 786 */
787 void 787 void
788 SDL_ResetCursor (void) 788 SDL_ResetCursor(void)
789 { 789 {
790 int savelen; 790 int savelen;
791 791
792 if (SDL_cursor) { 792 if (SDL_cursor) {
793 savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h; 793 savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h;
794 SDL_cursor->area.x = 0; 794 SDL_cursor->area.x = 0;
795 SDL_cursor->area.y = 0; 795 SDL_cursor->area.y = 0;
796 SDL_memset (SDL_cursor->save[0], 0, savelen); 796 SDL_memset(SDL_cursor->save[0], 0, savelen);
797 } 797 }
798 } 798 }
799 799
800 /* vi: set ts=4 sw=4 expandtab: */ 800 /* vi: set ts=4 sw=4 expandtab: */