Added a cleaner way to set the default cursor.
Added a way to cycle through the default cursor in testcursor.c
--- a/src/events/SDL_mouse.c Sun Feb 27 21:17:06 2011 -0800
+++ b/src/events/SDL_mouse.c Sun Feb 27 21:36:23 2011 -0800
@@ -44,6 +44,17 @@
return (0);
}
+void
+SDL_SetDefaultCursor(SDL_Cursor * cursor)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->def_cursor = cursor;
+ if (!mouse->cur_cursor) {
+ SDL_SetCursor(cursor);
+ }
+}
+
SDL_Mouse *
SDL_GetMouse(void)
{
@@ -397,15 +408,17 @@
/* Set the new cursor */
if (cursor) {
/* Make sure the cursor is still valid for this mouse */
- SDL_Cursor *found;
- for (found = mouse->cursors; found; found = found->next) {
- if (found == cursor) {
- break;
+ if (cursor != mouse->def_cursor) {
+ SDL_Cursor *found;
+ for (found = mouse->cursors; found; found = found->next) {
+ if (found == cursor) {
+ break;
+ }
}
- }
- if (!found) {
- SDL_SetError("Cursor not associated with the current mouse");
- return;
+ if (!found) {
+ SDL_SetError("Cursor not associated with the current mouse");
+ return;
+ }
}
mouse->cur_cursor = cursor;
} else {
--- a/src/events/SDL_mouse_c.h Sun Feb 27 21:17:06 2011 -0800
+++ b/src/events/SDL_mouse_c.h Sun Feb 27 21:36:23 2011 -0800
@@ -72,6 +72,9 @@
/* Get the mouse state structure */
SDL_Mouse *SDL_GetMouse(void);
+/* Set the default mouse cursor */
+extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
+
/* Set the mouse focus window */
extern void SDL_SetMouseFocus(SDL_Window * window);
--- a/src/video/cocoa/SDL_cocoamouse.m Sun Feb 27 21:17:06 2011 -0800
+++ b/src/video/cocoa/SDL_cocoamouse.m Sun Feb 27 21:36:23 2011 -0800
@@ -120,15 +120,13 @@
Cocoa_InitMouse(_THIS)
{
SDL_Mouse *mouse = SDL_GetMouse();
- SDL_Cursor *cursor;
mouse->CreateCursor = Cocoa_CreateCursor;
mouse->ShowCursor = Cocoa_ShowCursor;
mouse->WarpMouse = Cocoa_WarpMouse;
mouse->FreeCursor = Cocoa_FreeCursor;
- cursor = Cocoa_CreateDefaultCursor();
- mouse->cursors = mouse->cur_cursor = cursor;
+ SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
}
static int
--- a/test/testcursor.c Sun Feb 27 21:17:06 2011 -0800
+++ b/test/testcursor.c Sun Feb 27 21:36:23 2011 -0800
@@ -147,7 +147,7 @@
{
SDL_Surface *screen;
SDL_bool quit = SDL_FALSE, first_time = SDL_TRUE;
- SDL_Cursor *cursor[3];
+ SDL_Cursor *cursor[4];
int current;
/* Load the SDL library */
@@ -189,6 +189,7 @@
SDL_Quit();
return (1);
}
+ cursor[3] = SDL_GetCursor();
current = 0;
SDL_SetCursor(cursor[current]);
@@ -198,7 +199,7 @@
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
- current = (current + 1) % 3;
+ current = (current + 1) % SDL_arraysize(cursor);
SDL_SetCursor(cursor[current]);
break;
case SDL_KEYDOWN:
@@ -222,3 +223,5 @@
SDL_Quit();
return (0);
}
+
+/* vi: set ts=4 sw=4 expandtab: */