Skip to content

Commit

Permalink
Fix resized window mouse position on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Jul 17, 2017
1 parent 9112224 commit 93f05ea
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/InputFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// for mouse stuff: -aj
#include "PrefsManager.h"
#include "ScreenDimensions.h"

#ifdef _WINDOWS
#include "archutils/Win32/GraphicsWindow.h"
#endif
#include <set>

static const char *InputEventTypeNames[] = {
Expand Down Expand Up @@ -483,18 +485,35 @@ class LunaInputFilter: public Luna<InputFilter>
public:
// todo: Should the input be locked to the theme's width/height instead of
// the window's width/height? -aj
static int GetMouseX( T* p, lua_State *L ){
static int GetMouseX(T* p, lua_State *L) {
float fX = p->GetCursorX();
// Scale input to the theme's dimensions
fX = SCALE( fX, 0, (PREFSMAN->m_iDisplayHeight * PREFSMAN->m_fDisplayAspectRatio), SCREEN_LEFT, SCREEN_RIGHT );
lua_pushnumber( L, fX );
ScreenDimensions::ReloadScreenDimensions();
#ifdef _WINDOWS
RECT rect;
GetClientRect(GraphicsWindow::GetHwnd(), &rect);
int iWidth = rect.right - rect.left;
fX = SCALE(fX, 0, iWidth, SCREEN_LEFT, SCREEN_RIGHT);
#else
fX = SCALE(fX, 0, (PREFSMAN->m_iDisplayHeight * PREFSMAN->m_fDisplayAspectRatio), SCREEN_LEFT, SCREEN_RIGHT);
#endif
lua_pushnumber(L, fX);
return 1;
}
static int GetMouseY( T* p, lua_State *L ){
static int GetMouseY(T* p, lua_State *L) {
float fY = p->GetCursorY();
// Scale input to the theme's dimensions
fY = SCALE( fY, 0, PREFSMAN->m_iDisplayHeight, SCREEN_TOP, SCREEN_BOTTOM );
lua_pushnumber( L, fY );
ScreenDimensions::ReloadScreenDimensions();
#ifdef _WINDOWS
RECT rect;
GetClientRect(GraphicsWindow::GetHwnd(), &rect);
int iHeight = rect.bottom - rect.top;

fY = SCALE(fY, 0, iHeight, SCREEN_TOP, SCREEN_BOTTOM);
#else
fY = SCALE(fY, 0, PREFSMAN->m_iDisplayHeight, SCREEN_TOP, SCREEN_BOTTOM);
#endif
lua_pushnumber(L, fY);
return 1;
}
static int GetMouseWheel( T* p, lua_State *L ){
Expand Down

0 comments on commit 93f05ea

Please sign in to comment.