Merge branch 'master' into SDL2
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
|
||||
// Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <Nazara/Platform/Win32/WindowImpl.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <Nazara/Platform/Win32/WindowImpl.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <windowsx.h>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#ifdef _WIN64
|
||||
#define GCL_HCURSOR GCLP_HCURSOR
|
||||
@@ -61,7 +63,7 @@ namespace Nz
|
||||
bool async = (style & WindowStyle_Threaded) != 0;
|
||||
bool fullscreen = (style & WindowStyle_Fullscreen) != 0;
|
||||
DWORD win32Style, win32StyleEx;
|
||||
unsigned int x, y;
|
||||
int x, y;
|
||||
unsigned int width = mode.width;
|
||||
unsigned int height = mode.height;
|
||||
if (fullscreen)
|
||||
@@ -117,8 +119,13 @@ namespace Nz
|
||||
width = rect.right - rect.left;
|
||||
height = rect.bottom - rect.top;
|
||||
|
||||
x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
|
||||
y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
|
||||
// Grab desktop rect in order to center our window on the main display
|
||||
// TODO: Handle multiple displays
|
||||
RECT desktopRect;
|
||||
GetClientRect(GetDesktopWindow(), &desktopRect);
|
||||
|
||||
x = (desktopRect.right / 2) - (width / 2);
|
||||
y = (desktopRect.bottom / 2) - (height / 2);
|
||||
}
|
||||
|
||||
m_callback = 0;
|
||||
@@ -709,6 +716,10 @@ namespace Nz
|
||||
WindowEvent event;
|
||||
event.type = WindowEventType_MouseWheelMoved;
|
||||
event.mouseWheel.delta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wParam)) / WHEEL_DELTA;
|
||||
|
||||
event.mouseWheel.x = GET_X_LPARAM(lParam);
|
||||
event.mouseWheel.y = GET_Y_LPARAM(lParam);
|
||||
|
||||
m_parent->PushEvent(event);
|
||||
}
|
||||
else
|
||||
@@ -719,6 +730,10 @@ namespace Nz
|
||||
WindowEvent event;
|
||||
event.type = WindowEventType_MouseWheelMoved;
|
||||
event.mouseWheel.delta = static_cast<float>(m_scrolling / WHEEL_DELTA);
|
||||
|
||||
event.mouseWheel.x = GET_X_LPARAM(lParam);
|
||||
event.mouseWheel.y = GET_Y_LPARAM(lParam);
|
||||
|
||||
m_parent->PushEvent(event);
|
||||
|
||||
m_scrolling %= WHEEL_DELTA;
|
||||
@@ -928,6 +943,9 @@ namespace Nz
|
||||
|
||||
bool WindowImpl::Initialize()
|
||||
{
|
||||
if (!SetProcessDpiAware())
|
||||
NazaraWarning("failed to make process DPI-aware");
|
||||
|
||||
// Nous devons faire un type Unicode pour que la fenêtre le soit également
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633574(v=vs.85).aspx
|
||||
WNDCLASSW windowClass;
|
||||
@@ -950,6 +968,50 @@ namespace Nz
|
||||
UnregisterClassW(className, GetModuleHandle(nullptr));
|
||||
}
|
||||
|
||||
bool WindowImpl::SetProcessDpiAware()
|
||||
{
|
||||
// MSDN : https://docs.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process
|
||||
// This will work only for windows Vista & above
|
||||
|
||||
HINSTANCE shcoreLib = LoadLibraryW(L"SHCore.dll");
|
||||
if (shcoreLib)
|
||||
{
|
||||
CallOnExit closeLibOnExit([&] { FreeLibrary(shcoreLib); });
|
||||
|
||||
/// shellscalingapi.h
|
||||
enum PROCESS_DPI_AWARENESS
|
||||
{
|
||||
PROCESS_DPI_UNAWARE,
|
||||
PROCESS_SYSTEM_DPI_AWARE,
|
||||
PROCESS_PER_MONITOR_DPI_AWARE
|
||||
};
|
||||
|
||||
using SetProcessDpiAwarenessFunc = HRESULT (WINAPI*)(PROCESS_DPI_AWARENESS);
|
||||
auto SetProcessDpiAwareness = reinterpret_cast<SetProcessDpiAwarenessFunc>(GetProcAddress(shcoreLib, "SetProcessDpiAwareness"));
|
||||
|
||||
if (SetProcessDpiAwareness)
|
||||
{
|
||||
HRESULT result = SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);
|
||||
|
||||
if (result == S_OK || result == E_ACCESSDENIED) //< E_ACCESSDENIED means it has already been set, probably by the .exe manifest
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If SetProcessDpiAwareness doesn't exist, we call old user32 function
|
||||
HMODULE user32 = GetModuleHandleW(L"user32.dll");
|
||||
if (!user32)
|
||||
return false; //< Shouldn't happen as user32 is linked
|
||||
|
||||
using SetProcessDPIAwareFunc = BOOL (WINAPI*)();
|
||||
auto SetProcessDPIAware = reinterpret_cast<SetProcessDPIAwareFunc>(GetProcAddress(user32, "SetProcessDPIAware"));
|
||||
|
||||
if (!SetProcessDPIAware || !SetProcessDPIAware())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Keyboard::Key WindowImpl::ConvertVirtualKey(WPARAM key, LPARAM flags)
|
||||
{
|
||||
switch (key)
|
||||
|
||||
@@ -84,6 +84,8 @@ namespace Nz
|
||||
bool HandleMessage(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
void PrepareWindow(bool fullscreen);
|
||||
|
||||
static bool SetProcessDpiAware();
|
||||
|
||||
static Keyboard::Key ConvertVirtualKey(WPARAM key, LPARAM flags);
|
||||
static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
static UInt32 RetrieveStyle(HWND window);
|
||||
|
||||
Reference in New Issue
Block a user