Skip to content

Commit

Permalink
Merge pull request #349 from Bradbev/sdl_fix_setcursor
Browse files Browse the repository at this point in the history
Change the SDL backend of SetCursor to accept global positions.
  • Loading branch information
gucio321 authored Oct 18, 2024
2 parents 1a15ba4 + ddaefc9 commit c39c7e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions backend/sdlbackend/sdl_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ SDL_Window* igCreateSDLWindow(const char* title, int width, int height,VoidCallb
SDL_Window* window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, sdl_flags);
sdl_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); // reset default flags
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
if (!gl_context)
{
printf("Error creating SDL context %s\n", SDL_GetError());
exit(1);
}
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync

Expand Down
4 changes: 3 additions & 1 deletion backend/sdlbackend/sdl_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,10 @@ func (b *SDLBackend) SetSwapInterval(interval SDLWindowFlags) error {
return nil
}

// the SDL backend gives mouse positions in global coordinates, so to make it possible to
// "lock" the mouse in one place, SetCursorPos will set the mouse in global coordinates
func (b *SDLBackend) SetCursorPos(x, y float64) {
C.SDL_WarpMouseInWindow(b.handle(), C.int(x), C.int(y))
C.SDL_WarpMouseGlobal(C.int(x), C.int(y))
}

func (b *SDLBackend) SetInputMode(mode SDLWindowFlags, value SDLWindowFlags) {
Expand Down

0 comments on commit c39c7e5

Please sign in to comment.