Skip to content

Commit

Permalink
The DInput8Backend now obtains the absolute mouse position from Windo…
Browse files Browse the repository at this point in the history
…w::getCursorPosition()
  • Loading branch information
SebastienLussier committed Jun 26, 2012
1 parent 2102e19 commit f90f35b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/input/DInput8Backend.cpp
Expand Up @@ -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: {
Expand All @@ -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))) {
Expand All @@ -551,10 +551,9 @@ bool DInput8Backend::update() {
}
break;
}

}
}

return success;
}

Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/window/SDLWindow.cpp
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/window/SDLWindow.h
Expand Up @@ -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();

Expand Down
7 changes: 7 additions & 0 deletions src/window/Win32Window.cpp
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/window/Win32Window.h
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions src/window/Window.h
Expand Up @@ -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 {

Expand Down

0 comments on commit f90f35b

Please sign in to comment.