Merge pull request #396 from bjornblissing/feature/DPIAwareScaling
Applications declared as DPI-aware in the Windows environment
This commit is contained in:
@@ -344,6 +344,10 @@ ENDIF()
|
||||
|
||||
|
||||
IF(WIN32 AND NOT ANDROID)
|
||||
# Check window version
|
||||
INCLUDE (OsgDetermineWinVersion)
|
||||
get_WIN32_WINNT(WIN_VERSION)
|
||||
ADD_DEFINITIONS(-D_WIN32_WINNT=${WIN_VERSION})
|
||||
|
||||
IF(MSVC)
|
||||
# This option is to enable the /MP switch for Visual Studio 2005 and above compilers
|
||||
|
||||
22
CMakeModules/OsgDetermineWinVersion.cmake
Normal file
22
CMakeModules/OsgDetermineWinVersion.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
# - If Windows is used, this script sets the variable WIN32_WINNT to the corresponding windows version
|
||||
|
||||
if (WIN32)
|
||||
message(STATUS "Checking windows version...")
|
||||
macro(get_WIN32_WINNT version)
|
||||
if (CMAKE_SYSTEM_VERSION)
|
||||
set(ver ${CMAKE_SYSTEM_VERSION})
|
||||
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
|
||||
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
|
||||
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
|
||||
if ("${verMajor}" MATCHES "10")
|
||||
set(verMajor "A")
|
||||
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
|
||||
endif ("${verMajor}" MATCHES "10")
|
||||
# Remove all remaining '.' characters.
|
||||
string(REPLACE "." "" ver ${ver})
|
||||
# Prepend each digit with a zero.
|
||||
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
|
||||
set(${version} "0x${ver}")
|
||||
endif(CMAKE_SYSTEM_VERSION)
|
||||
endmacro(get_WIN32_WINNT)
|
||||
endif(WIN32)
|
||||
@@ -16,8 +16,17 @@
|
||||
|
||||
#include <osgViewer/Export>
|
||||
|
||||
// Fallback if not correctly detected in CMake macro
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0500
|
||||
//#define _WIN32_WINNT 0x0A00 // Windows 10
|
||||
//#define _WIN32_WINNT 0x0603 // Windows 8.1
|
||||
//#define _WIN32_WINNT 0x0602 // Windows 8
|
||||
//#define _WIN32_WINNT 0x0601 // Windows 7
|
||||
//#define _WIN32_WINNT 0x0600 // Windows Server 2008
|
||||
//#define _WIN32_WINNT 0x0600 // Windows Vista
|
||||
//#define _WIN32_WINNT 0x0502 // Windows Server 2003 with SP1, Windows XP with SP2
|
||||
//#define _WIN32_WINNT 0x0501 // Windows Server 2003, Windows XP
|
||||
#define _WIN32_WINNT 0x0500 // Windows NT
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
#include <osgDB/FileUtils>
|
||||
|
||||
#ifdef WIN32
|
||||
#if !defined(__MINGW32__)
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -144,6 +144,26 @@ static CloseTouchInputHandleFunc *closeTouchInputHandleFunc = NULL;
|
||||
static GetTouchInputInfoFunc *getTouchInputInfoFunc = NULL;
|
||||
static GetPointerTypeFunc *getPointerTypeFunc = NULL;
|
||||
|
||||
// DPI Awareness
|
||||
#if(WINVER >= 0x0603)
|
||||
|
||||
#ifndef DPI_ENUMS_DECLARED
|
||||
|
||||
typedef enum PROCESS_DPI_AWARENESS {
|
||||
PROCESS_DPI_UNAWARE = 0,
|
||||
PROCESS_SYSTEM_DPI_AWARE = 1,
|
||||
PROCESS_PER_MONITOR_DPI_AWARE = 2
|
||||
} PROCESS_DPI_AWARENESS;
|
||||
|
||||
#endif // DPI_ENUMS_DECLARED
|
||||
|
||||
typedef
|
||||
BOOL
|
||||
(WINAPI SetProcessDpiAwarenessFunc(
|
||||
PROCESS_DPI_AWARENESS dpi_awareness));
|
||||
|
||||
static SetProcessDpiAwarenessFunc *setProcessDpiAwareness = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -765,6 +785,21 @@ Win32WindowingSystem::Win32WindowingSystem()
|
||||
FreeLibrary( hModule);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if(WINVER >= 0x0603)
|
||||
// For Windows 8.1 and higher
|
||||
//
|
||||
// Per monitor DPI aware.This app checks for the DPI when it is created and adjusts the scale factor
|
||||
// whenever the DPI changes.These applications are not automatically scaled by the system.
|
||||
HMODULE hModuleShore = LoadLibrary("Shcore");
|
||||
if (hModuleShore) {
|
||||
setProcessDpiAwareness = (SetProcessDpiAwarenessFunc *) GetProcAddress(hModuleShore, "SetProcessDpiAwareness");
|
||||
if (setProcessDpiAwareness) {
|
||||
(*setProcessDpiAwareness)(PROCESS_DPI_AWARENESS::PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Win32WindowingSystem::~Win32WindowingSystem()
|
||||
|
||||
Reference in New Issue
Block a user