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:
Sam Lantinga
2022-12-29 19:31:12 -08:00
parent 8c3239dee5
commit cefbeb582f
52 changed files with 564 additions and 654 deletions

View File

@@ -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;