mirror of
https://github.com/yawut/SDL.git
synced 2026-04-24 23:37:09 -05:00
Added a cleaner way to set the default cursor.
Added a way to cycle through the default cursor in testcursor.c
This commit is contained in:
parent
8b92536842
commit
0068b61c49
|
|
@ -44,6 +44,17 @@ SDL_MouseInit(void)
|
|||
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 @@ SDL_SetCursor(SDL_Cursor * cursor)
|
|||
/* 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 {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ extern int SDL_MouseInit(void);
|
|||
/* 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -120,15 +120,13 @@ void
|
|||
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
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ main(int argc, char *argv[])
|
|||
{
|
||||
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 @@ main(int argc, char *argv[])
|
|||
SDL_Quit();
|
||||
return (1);
|
||||
}
|
||||
cursor[3] = SDL_GetCursor();
|
||||
|
||||
current = 0;
|
||||
SDL_SetCursor(cursor[current]);
|
||||
|
|
@ -198,7 +199,7 @@ main(int argc, char *argv[])
|
|||
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 @@ main(int argc, char *argv[])
|
|||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user