diff --git a/src/input/DInput8Backend.cpp b/src/input/DInput8Backend.cpp index a13f753333..05186fb6e1 100644 --- a/src/input/DInput8Backend.cpp +++ b/src/input/DInput8Backend.cpp @@ -504,14 +504,14 @@ bool getMouseInputDevice(DXIMode mode, int minbutton, int minaxe) { } bool DInput8Backend::update() { - + bool success = true; for(InputList::iterator i = DI_InputInfo.begin(); i != DI_InputInfo.end(); ++i) { - + if(!i->active) { continue; } - + switch(GET_DIDEVICE_TYPE(i->type)) { case DI8DEVTYPE_MOUSE: { @@ -523,11 +523,11 @@ bool DInput8Backend::update() { success = false; } } - + i->nbele = (int)dwNbele; break; } - + case DI8DEVTYPE_KEYBOARD: { char keyBuffer[DI8_KEY_ARRAY_SIZE]; if(FAILED(i->inputdevice8->GetDeviceState(DI8_KEY_ARRAY_SIZE, keyBuffer))) { @@ -551,10 +551,9 @@ bool DInput8Backend::update() { } break; } - } } - + return success; } @@ -611,13 +610,13 @@ bool DInput8Backend::getKeyAsText(int keyId, char& result) const { } bool DInput8Backend::getAbsoluteMouseCoords(int & absX, int & absY) const { - POINT pt; - GetCursorPos(&pt); - ScreenToClient((HWND)mainApp->GetWindow()->GetHandle(), &pt); - absX = pt.x; - absY = pt.y; + + Vec2i cursorPos = mainApp->GetWindow()->getCursorPosition(); RECT rc; + POINT pt; + absX = pt.x = cursorPos.x; + absY = pt.y = cursorPos.y; GetClientRect((HWND)mainApp->GetWindow()->GetHandle(), &rc); return PtInRect(&rc, pt) == TRUE; } diff --git a/src/window/SDLWindow.cpp b/src/window/SDLWindow.cpp index 922b21b08a..8095f219f6 100644 --- a/src/window/SDLWindow.cpp +++ b/src/window/SDLWindow.cpp @@ -399,6 +399,12 @@ void SDLWindow::tick() { } +Vec2i SDLWindow::getCursorPosition() const { + int cursorPosX, cursorPosY; + SDL_GetMouseState(&cursorPosX, &cursorPosY); + return Vec2i(cursorPosX, cursorPosY); +} + void SDLWindow::showFrame() { SDL_GL_SwapBuffers(); diff --git a/src/window/SDLWindow.h b/src/window/SDLWindow.h index 6a913f5c32..104d6fd7d0 100644 --- a/src/window/SDLWindow.h +++ b/src/window/SDLWindow.h @@ -39,6 +39,7 @@ class SDLWindow : public RenderWindow { void setFullscreenMode(Vec2i resolution, unsigned depth = 0); void setWindowSize(Vec2i size); void tick(); + Vec2i getCursorPosition() const; void showFrame(); diff --git a/src/window/Win32Window.cpp b/src/window/Win32Window.cpp index e402e17af5..a09b14b808 100644 --- a/src/window/Win32Window.cpp +++ b/src/window/Win32Window.cpp @@ -279,6 +279,13 @@ void Win32Window::tick() { updateSize(); } +Vec2i Win32Window::getCursorPosition() const { + POINT pt; + GetCursorPos(&pt); + ScreenToClient(m_hWnd, &pt); + return Vec2i(pt.x, pt.y); +} + void* Win32Window::GetHandle() { return m_hWnd; } diff --git a/src/window/Win32Window.h b/src/window/Win32Window.h index 703f4e6492..3d7d210c2b 100644 --- a/src/window/Win32Window.h +++ b/src/window/Win32Window.h @@ -38,6 +38,7 @@ class Win32Window : public RenderWindow { virtual void setFullscreenMode(Vec2i resolution, unsigned depth = 0); virtual void setWindowSize(Vec2i size); virtual void tick(); + virtual Vec2i getCursorPosition() const; void updateSize(); diff --git a/src/window/Window.h b/src/window/Window.h index 66f246d8d9..04e4a72d49 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -47,6 +47,9 @@ class Window { virtual void tick() = 0; virtual void hide() = 0; + + //! Obtain the cursor position relative to this window. + virtual Vec2i getCursorPosition() const = 0; class Listener {