mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-06 06:34:35 +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:
parent
8c3239dee5
commit
cefbeb582f
52 changed files with 564 additions and 654 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue