Skip to content

Commit 8392abe

Browse files
authored
Code review for Mouse CoreWindow implementation (#523)
1 parent 4aec63e commit 8392abe

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Src/Mouse.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,16 @@ void Mouse::SetWindow(HWND window)
527527

528528
#include <Windows.Devices.Input.h>
529529

530+
// This symbol is defined for Win32 desktop applications, but not for UWP
531+
constexpr float USER_DEFAULT_SCREEN_DPI = 96.f;
532+
530533
class Mouse::Impl
531534
{
532535
public:
533536
explicit Impl(Mouse* owner) noexcept(false) :
534537
mState{},
535538
mOwner(owner),
536-
mDPI(96.f),
539+
mDPI(USER_DEFAULT_SCREEN_DPI),
537540
mMode(MODE_ABSOLUTE),
538541
mAutoReset(true),
539542
mLastX(0),
@@ -906,8 +909,8 @@ class Mouse::Impl
906909

907910
const float dpi = s_mouse->mDPI;
908911

909-
s_mouse->mState.x = static_cast<int>(pos.X * dpi / 96.f + 0.5f);
910-
s_mouse->mState.y = static_cast<int>(pos.Y * dpi / 96.f + 0.5f);
912+
s_mouse->mState.x = static_cast<int>(pos.X * dpi / USER_DEFAULT_SCREEN_DPI + 0.5f);
913+
s_mouse->mState.y = static_cast<int>(pos.Y * dpi / USER_DEFAULT_SCREEN_DPI + 0.5f);
911914
}
912915

913916
return S_OK;
@@ -970,8 +973,8 @@ class Mouse::Impl
970973

971974
float dpi = s_mouse->mDPI;
972975

973-
s_mouse->mState.x = static_cast<int>(pos.X * dpi / 96.f + 0.5f);
974-
s_mouse->mState.y = static_cast<int>(pos.Y * dpi / 96.f + 0.5f);
976+
s_mouse->mState.x = static_cast<int>(pos.X * dpi / USER_DEFAULT_SCREEN_DPI + 0.5f);
977+
s_mouse->mState.y = static_cast<int>(pos.Y * dpi / USER_DEFAULT_SCREEN_DPI + 0.5f);
975978
}
976979
}
977980

0 commit comments

Comments
 (0)