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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user