From d248ae8b9ac73b71caae0cfd7d414cd226ff803f Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 19 Jan 2011 12:34:23 +0000 Subject: [PATCH] Make SdlInput regularly inject the mouse position into the Input singleton. --- src/input.cpp | 17 ++++++++++++++++- src/input.h | 2 ++ src/sdlinput.cpp | 7 ++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index db3c90b5..428c5f05 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -29,7 +29,12 @@ static class InputData friend class Input; public: - int dummy; + InputData() + { + mouse.x = mouse.y = -1; + } + + Int2 mouse; } inputdata; @@ -59,3 +64,13 @@ Float2 Input::GetAxis(int axis) return f; } +void Input::SetMousePos(Int2 coord) +{ + data->mouse = coord; +} + +Int2 Input::GetMousePos() +{ + return data->mouse; +} + diff --git a/src/input.h b/src/input.h index d5e7155d..53c36a24 100644 --- a/src/input.h +++ b/src/input.h @@ -22,6 +22,8 @@ class Input { public: static Float2 GetAxis(int axis); + static void SetMousePos(Int2 coord); + static Int2 GetMousePos(); }; #endif // __DH_INPUT_H__ diff --git a/src/sdlinput.cpp b/src/sdlinput.cpp index 8d5d2673..f90c9deb 100644 --- a/src/sdlinput.cpp +++ b/src/sdlinput.cpp @@ -48,7 +48,12 @@ void SdlInput::TickGame(float deltams) Entity::TickGame(deltams); /* Handle mouse input */ - SDL_GetMouseState(&data->mx, &data->my); + Int2 mouse; + if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) + SDL_GetMouseState(&mouse.x, &mouse.y); + else + mouse.x = mouse.y = -1; + Input::SetMousePos(mouse); /* Handle keyboard and WM events */ SDL_Event event;