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

@ -23,14 +23,17 @@
#endif
static SDLTest_CommonState *state;
int i, done;
SDL_Rect rect;
SDL_Event event;
static int i, done;
static float mouseX, mouseY;
static SDL_Rect rect;
static SDL_Event event;
static void
DrawRects(SDL_Renderer *renderer)
{
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
rect.x = (int)mouseX;
rect.y = (int)mouseY;
SDL_RenderFillRect(renderer, &rect);
}
@ -43,8 +46,8 @@ loop()
switch (event.type) {
case SDL_MOUSEMOTION:
{
rect.x += event.motion.xrel;
rect.y += event.motion.yrel;
mouseX += event.motion.xrel;
mouseY += event.motion.yrel;
} break;
}
}