mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-29 02:34:23 +00:00
Mouse coordinates are floating point
You can get sub-pixel mouse coordinates and motion depending on the platform and display scaling. Fixes https://github.com/libsdl-org/SDL/issues/2999
This commit is contained in:
@@ -72,18 +72,18 @@ void loop()
|
||||
|
||||
if (event.type == SDL_MOUSEMOTION) {
|
||||
if (event.motion.state) {
|
||||
int xrel, yrel;
|
||||
float xrel, yrel;
|
||||
int window_w, window_h;
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.motion.windowID);
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
xrel = event.motion.xrel;
|
||||
yrel = event.motion.yrel;
|
||||
if (event.motion.y < window_h / 2) {
|
||||
if (event.motion.y < (float)window_h / 2.0f) {
|
||||
angle += xrel;
|
||||
} else {
|
||||
angle -= xrel;
|
||||
}
|
||||
if (event.motion.x < window_w / 2) {
|
||||
if (event.motion.x < (float)window_w / 2.0f) {
|
||||
angle -= yrel;
|
||||
} else {
|
||||
angle += yrel;
|
||||
|
||||
Reference in New Issue
Block a user