Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the SDL backend of SetCursor to accept global positions. #349

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading