high DPI resolution
This commit is contained in:
parent
8ec5daeafd
commit
f545a15365
|
|
@ -83,8 +83,6 @@ namespace easy2d
|
|||
ThrowIfFailed(
|
||||
Input::Instance()->Init(
|
||||
hwnd,
|
||||
Window::Instance()->GetContentScaleX(),
|
||||
Window::Instance()->GetContentScaleY(),
|
||||
debug_
|
||||
)
|
||||
);
|
||||
|
|
@ -299,8 +297,8 @@ namespace easy2d
|
|||
{
|
||||
Event evt;
|
||||
|
||||
evt.mouse.x = GET_X_LPARAM(lparam) * Window::Instance()->GetContentScaleX();
|
||||
evt.mouse.y = GET_Y_LPARAM(lparam) * Window::Instance()->GetContentScaleY();
|
||||
evt.mouse.x = static_cast<float>(GET_X_LPARAM(lparam));
|
||||
evt.mouse.y = static_cast<float>(GET_Y_LPARAM(lparam));
|
||||
evt.mouse.left_btn_down = !!(wparam & MK_LBUTTON);
|
||||
evt.mouse.left_btn_down = !!(wparam & MK_RBUTTON);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ namespace easy2d
|
|||
{
|
||||
Input::Input()
|
||||
: hwnd_(nullptr)
|
||||
, scale_x_(1.f)
|
||||
, scale_y_(1.f)
|
||||
{
|
||||
ZeroMemory(keys_, sizeof(keys_));
|
||||
ZeroMemory(keys_cache_, sizeof(keys_cache_));
|
||||
|
|
@ -38,13 +36,11 @@ namespace easy2d
|
|||
E2D_LOG(L"Destroying input device");
|
||||
}
|
||||
|
||||
HRESULT Input::Init(HWND hwnd, float scalex, float scaley, bool debug)
|
||||
HRESULT Input::Init(HWND hwnd, bool debug)
|
||||
{
|
||||
E2D_LOG(L"Initing input device");
|
||||
|
||||
hwnd_ = hwnd;
|
||||
scale_x_ = scalex;
|
||||
scale_y_ = scaley;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
|
@ -52,7 +48,7 @@ namespace easy2d
|
|||
void Input::Update()
|
||||
{
|
||||
memcpy(keys_cache_, keys_, sizeof(keys_cache_));
|
||||
GetKeyboardState(keys_);
|
||||
::GetKeyboardState(keys_);
|
||||
}
|
||||
|
||||
bool Input::IsDown(KeyCode code)
|
||||
|
|
@ -91,18 +87,12 @@ namespace easy2d
|
|||
|
||||
float Input::GetMouseX()
|
||||
{
|
||||
POINT pos;
|
||||
::GetCursorPos(&pos);
|
||||
::ScreenToClient(hwnd_, &pos);
|
||||
return pos.x * scale_x_;
|
||||
return GetMousePos().x;
|
||||
}
|
||||
|
||||
float Input::GetMouseY()
|
||||
{
|
||||
POINT pos;
|
||||
::GetCursorPos(&pos);
|
||||
::ScreenToClient(hwnd_, &pos);
|
||||
return pos.y * scale_y_;
|
||||
return GetMousePos().y;
|
||||
}
|
||||
|
||||
Point Input::GetMousePos()
|
||||
|
|
@ -110,6 +100,6 @@ namespace easy2d
|
|||
POINT pos;
|
||||
::GetCursorPos(&pos);
|
||||
::ScreenToClient(hwnd_, &pos);
|
||||
return Point{ pos.x * scale_x_, pos.y * scale_y_ };
|
||||
return Point{ static_cast<float>(pos.x), static_cast<float>(pos.y) };
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ namespace easy2d
|
|||
E2D_DECLARE_SINGLETON(Input);
|
||||
|
||||
public:
|
||||
HRESULT Init(HWND hwnd, float scalex, float scaley, bool debug);
|
||||
HRESULT Init(HWND hwnd, bool debug);
|
||||
|
||||
// 检测键盘按键是否正被按下
|
||||
bool IsDown(
|
||||
|
|
@ -81,8 +81,6 @@ namespace easy2d
|
|||
|
||||
protected:
|
||||
HWND hwnd_;
|
||||
float scale_x_;
|
||||
float scale_y_;
|
||||
BYTE keys_[256];
|
||||
BYTE keys_cache_[256];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -506,7 +506,12 @@ namespace easy2d
|
|||
|
||||
hr = Factory::Instance()->CreateHwndRenderTarget(
|
||||
render_target_,
|
||||
D2D1::RenderTargetProperties(),
|
||||
D2D1::RenderTargetProperties(
|
||||
D2D1_RENDER_TARGET_TYPE_DEFAULT,
|
||||
D2D1::PixelFormat(),
|
||||
96.f,
|
||||
96.f
|
||||
),
|
||||
D2D1::HwndRenderTargetProperties(
|
||||
hwnd,
|
||||
size,
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ namespace easy2d
|
|||
{
|
||||
MONITORINFOEX GetMoniterInfoEx(HWND hwnd);
|
||||
|
||||
void GetContentScale(float* scalex, float* scaley);
|
||||
|
||||
void AdjustWindow(UINT width, UINT height, DWORD style, float scalex, float scaley, UINT* win_width, UINT* win_height);
|
||||
void AdjustWindow(UINT width, UINT height, DWORD style, UINT* win_width, UINT* win_height);
|
||||
|
||||
void ChangeFullScreenResolution(int width, int height, WCHAR* device_name);
|
||||
|
||||
|
|
@ -46,8 +44,6 @@ namespace easy2d
|
|||
: handle_(nullptr)
|
||||
, width_(0)
|
||||
, height_(0)
|
||||
, scalex_(1.f)
|
||||
, scaley_(1.f)
|
||||
, device_name_(nullptr)
|
||||
{
|
||||
}
|
||||
|
|
@ -105,8 +101,6 @@ namespace easy2d
|
|||
device_name_ = new WCHAR[len + 1];
|
||||
lstrcpyW(device_name_, monitor_info_ex.szDevice);
|
||||
|
||||
GetContentScale(&scalex_, &scaley_);
|
||||
|
||||
int left = -1;
|
||||
int top = -1;
|
||||
|
||||
|
|
@ -133,8 +127,6 @@ namespace easy2d
|
|||
width,
|
||||
height,
|
||||
GetWindowStyle(),
|
||||
scalex_,
|
||||
scaley_,
|
||||
&win_width,
|
||||
&win_height
|
||||
);
|
||||
|
|
@ -282,7 +274,7 @@ namespace easy2d
|
|||
UINT screenh = info.rcWork.bottom - info.rcWork.top;
|
||||
|
||||
UINT win_width, win_height;
|
||||
AdjustWindow(width, height, GetWindowStyle(), scalex_, scaley_, &win_width, &win_height);
|
||||
AdjustWindow(width, height, GetWindowStyle(), &win_width, &win_height);
|
||||
|
||||
int left = screenw > win_width ? ((screenw - win_width) / 2) : 0;
|
||||
int top = screenh > win_height ? ((screenh - win_height) / 2) : 0;
|
||||
|
|
@ -307,16 +299,6 @@ namespace easy2d
|
|||
return is_fullscreen_ ? (WINDOW_FULLSCREEN_STYLE) : (WINDOW_STYLE);
|
||||
}
|
||||
|
||||
float Window::GetContentScaleX() const
|
||||
{
|
||||
return scalex_;
|
||||
}
|
||||
|
||||
float Window::GetContentScaleY() const
|
||||
{
|
||||
return scaley_;
|
||||
}
|
||||
|
||||
void Window::UpdateWindowRect()
|
||||
{
|
||||
if (!handle_)
|
||||
|
|
@ -376,24 +358,10 @@ namespace easy2d
|
|||
return monitor_info;
|
||||
}
|
||||
|
||||
void GetContentScale(float* scalex, float* scaley)
|
||||
{
|
||||
const float DEFAULT_SCREEN_DPI = 96.f;
|
||||
const HDC dc = GetDC(NULL);
|
||||
float xdpi = static_cast<float>(GetDeviceCaps(dc, LOGPIXELSX));
|
||||
float ydpi = static_cast<float>(GetDeviceCaps(dc, LOGPIXELSY));
|
||||
ReleaseDC(NULL, dc);
|
||||
|
||||
if (scalex)
|
||||
*scalex = xdpi / DEFAULT_SCREEN_DPI;
|
||||
if (scaley)
|
||||
*scaley = ydpi / DEFAULT_SCREEN_DPI;
|
||||
}
|
||||
|
||||
void AdjustWindow(UINT width, UINT height, DWORD style, float scalex, float scaley, UINT* win_width, UINT* win_height)
|
||||
void AdjustWindow(UINT width, UINT height, DWORD style, UINT* win_width, UINT* win_height)
|
||||
{
|
||||
RECT rc;
|
||||
::SetRect(&rc, 0, 0, (int)math::Ceil(width * scalex), (int)math::Ceil(height * scaley));
|
||||
::SetRect(&rc, 0, 0, (int)width, (int)height);
|
||||
::AdjustWindowRect(&rc, style, false);
|
||||
|
||||
*win_width = rc.right - rc.left;
|
||||
|
|
|
|||
|
|
@ -70,10 +70,6 @@ namespace easy2d
|
|||
|
||||
DWORD GetWindowStyle() const;
|
||||
|
||||
float GetContentScaleX() const;
|
||||
|
||||
float GetContentScaleY() const;
|
||||
|
||||
void UpdateWindowRect();
|
||||
|
||||
void SetActive(bool actived);
|
||||
|
|
@ -90,8 +86,6 @@ namespace easy2d
|
|||
bool is_fullscreen_;
|
||||
int width_;
|
||||
int height_;
|
||||
float scalex_;
|
||||
float scaley_;
|
||||
WCHAR* device_name_;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue