Skip to content

Commit

Permalink
Fix gl.cursor return value
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Oct 27, 2023
1 parent 2299b20 commit 5931f40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions dev/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ nfr("visible", "", "", "B",

nfr("cursor", "on", "B", "B",
"default the cursor is visible, turn off for implementing FPS like control schemes. return"
" whether it's on.",
" whether it was on before this call.",
[](StackPtr &, VM &vm, Value &on) {
TestGL(vm);
return Value(SDLCursor(on.ival() != 0));
return Value(SDLCursor(on.True()));
});

nfr("grab", "on", "B", "B",
Expand Down
29 changes: 14 additions & 15 deletions dev/src/sdlsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,22 +855,21 @@ int SDLWheelDelta() { return mousewheeldelta; }
bool SDLIsMinimized() { return minimized; }

bool SDLCursor(bool on) {
if (on != cursor) {
cursor = !cursor;
if (cursor) {
if (fullscreen) SDL_SetWindowGrab(_sdl_window, SDL_FALSE);
SDL_ShowCursor(1);
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_WarpMouseInWindow(_sdl_window, cursorx, cursory);
} else {
SDL_GetMouseState(&cursorx, &cursory);
if (fullscreen) SDL_SetWindowGrab(_sdl_window, SDL_TRUE);
SDL_ShowCursor(0);
SDL_SetRelativeMouseMode(SDL_TRUE);
clearfingers(false);
}
if (on == cursor) return cursor;
cursor = !cursor;
if (cursor) {
if (fullscreen) SDL_SetWindowGrab(_sdl_window, SDL_FALSE);
SDL_ShowCursor(1);
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_WarpMouseInWindow(_sdl_window, cursorx, cursory);
} else {
SDL_GetMouseState(&cursorx, &cursory);
if (fullscreen) SDL_SetWindowGrab(_sdl_window, SDL_TRUE);
SDL_ShowCursor(0);
SDL_SetRelativeMouseMode(SDL_TRUE);
clearfingers(false);
}
return cursor;
return !cursor;
}

bool SDLGrab(bool on) {
Expand Down

0 comments on commit 5931f40

Please sign in to comment.