From 4f100f92d859848f44c972c08e7fbf37c04e8d3e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 29 May 2016 13:40:00 -0300 Subject: [PATCH] DPI Detection support Windows only for now. Many builds may break (older visual studio, mingw32) --- core/bind/core_bind.cpp | 6 ++++++ core/bind/core_bind.h | 1 + core/os/os.h | 1 + drivers/freetype/SCsub | 8 ++++---- platform/windows/detect.py | 4 ++-- platform/windows/os_windows.cpp | 23 ++++++++++++++++++++++- platform/windows/os_windows.h | 3 +++ 7 files changed, 39 insertions(+), 7 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index e8703dccca1..addc26525e2 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -226,6 +226,11 @@ Size2 _OS::get_screen_size(int p_screen) const { return OS::get_singleton()->get_screen_size(p_screen); } +int _OS::get_screen_dpi(int p_screen) const { + + return OS::get_singleton()->get_screen_dpi(p_screen); +} + Point2 _OS::get_window_position() const { return OS::get_singleton()->get_window_position(); } @@ -984,6 +989,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_current_screen","screen"),&_OS::set_current_screen); ObjectTypeDB::bind_method(_MD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("get_screen_dpi","screen"),&_OS::get_screen_dpi,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position","position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 0c768651ffd..af89536c45a 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -117,6 +117,7 @@ public: virtual void set_current_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; + virtual int get_screen_dpi(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; diff --git a/core/os/os.h b/core/os/os.h index 160c0495bb9..5fd2bd6c25f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -160,6 +160,7 @@ public: virtual void set_current_screen(int p_screen) { } virtual Point2 get_screen_position(int p_screen=0) const { return Point2(); } virtual Size2 get_screen_size(int p_screen=0) const { return get_window_size(); } + virtual int get_screen_dpi(int p_screen=0) const { return 72; } virtual Point2 get_window_position() const { return Vector2(); } virtual void set_window_position(const Point2& p_position) {} virtual Size2 get_window_size() const=0; diff --git a/drivers/freetype/SCsub b/drivers/freetype/SCsub index 75e872a06fe..c0921c683a3 100644 --- a/drivers/freetype/SCsub +++ b/drivers/freetype/SCsub @@ -58,10 +58,10 @@ if (env["freetype"]=="builtin"): else: half1.append(x) - lib = env.Library("freetype_builtin1",half1) - env.Prepend(LIBS=[lib]) - lib = env.Library("freetype_builtin2",half2) - env.Prepend(LIBS=[lib]) + lib = env.Library("freetype_builtin1",half2) + env.Append(LIBS=[lib]) + lib = env.Library("freetype_builtin2",half1) + env.Append(LIBS=[lib]) # lib = env.Library("freetype_builtin",ft_sources) # env.Prepend(LIBS=[lib]) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 97d2461e580..795c49a7f57 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -243,7 +243,7 @@ def configure(env): env.Append(CCFLAGS=['/DGLES2_ENABLED']) env.Append(CCFLAGS=['/DGLEW_ENABLED']) - LIBS=['winmm','opengl32','dsound','kernel32','ole32','oleaut32','user32','gdi32', 'IPHLPAPI','Shlwapi', 'wsock32', 'shell32','advapi32','dinput8','dxguid'] + LIBS=['winmm','opengl32','dsound','kernel32','ole32','oleaut32','user32','gdi32', 'IPHLPAPI','Shcore','Shlwapi', 'wsock32', 'shell32','advapi32','dinput8','dxguid'] env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS]) env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"]) @@ -370,7 +370,7 @@ def configure(env): env.Append(CCFLAGS=['-DWINDOWS_ENABLED','-mwindows']) env.Append(CPPFLAGS=['-DRTAUDIO_ENABLED']) env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLEW_ENABLED']) - env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','shlwapi','wsock32','kernel32', 'oleaut32', 'dinput8', 'dxguid']) + env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','shlwapi','wsock32','shcore','kernel32', 'oleaut32', 'dinput8', 'dxguid']) # if (env["bits"]=="32"): # env.Append(LIBS=['gcc_s']) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index bf8b0ee6b5e..8bb5de5d5d9 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -57,6 +57,13 @@ #include #include +#if (_MSC_VER >= 1700) +#define HIDPI_SUPPORT +#endif + +#ifdef HIDPI_SUPPORT +#include +#endif static const WORD MAX_CONSOLE_LINES = 1500; extern "C" { @@ -854,7 +861,13 @@ BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPR minfo.rect.pos.y=lprcMonitor->top; minfo.rect.size.x=lprcMonitor->right - lprcMonitor->left; minfo.rect.size.y=lprcMonitor->bottom - lprcMonitor->top; - +#ifdef HIDPI_SUPPORT + UINT dpix,dpiy; + GetDpiForMonitor(hMonitor,MDT_EFFECTIVE_DPI,&dpix,&dpiy); + minfo.dpi=(dpix + dpiy)/2; +#else + minfo.dpi=72; +#endif self->monitor_info.push_back(minfo); return TRUE; @@ -1365,6 +1378,14 @@ Size2 OS_Windows::get_screen_size(int p_screen) const{ ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),Point2()); return Vector2( monitor_info[p_screen].rect.size ); +} + +int OS_Windows::get_screen_dpi(int p_screen) const { + + ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),72); + UINT dpix,dpiy; + return monitor_info[p_screen].dpi; + } Point2 OS_Windows::get_window_position() const{ diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 810da1b3cd0..6dd5b78bfdc 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -172,6 +172,7 @@ protected: HMONITOR hMonitor; HDC hdcMonitor; Rect2 rect; + int dpi; }; @@ -213,6 +214,8 @@ public: virtual void set_current_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; + virtual int get_screen_dpi(int p_screen=0) const; + virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const;