forked from turanszkij/WickedEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiPlatform.h
116 lines (104 loc) · 2.92 KB
/
wiPlatform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
// This file includes platform, os specific libraries and supplies common platform specific resources
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif // NOMINMAX
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <SDKDDKVer.h>
#include <windows.h>
#include <tchar.h>
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
#define PLATFORM_UWP
#define wiLoadLibrary(name) LoadPackagedLibrary(_T(name),0)
#define wiGetProcAddress(handle,name) GetProcAddress(handle, name)
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.Graphics.Display.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#else
#if WINAPI_FAMILY == WINAPI_FAMILY_GAMES
#define PLATFORM_XBOX
#else
#define PLATFORM_WINDOWS_DESKTOP
#endif // WINAPI_FAMILY_GAMES
#define wiLoadLibrary(name) LoadLibraryA(name)
#define wiGetProcAddress(handle,name) GetProcAddress(handle, name)
#endif // WINAPI_FAMILY_APP
#elif defined(__SCE__)
#define PLATFORM_PS5
#else
#define PLATFORM_LINUX
#include <dlfcn.h>
#define wiLoadLibrary(name) dlopen(name, RTLD_LAZY)
#define wiGetProcAddress(handle,name) dlsym(handle, name)
typedef void* HMODULE;
#endif // _WIN32
#ifdef SDL2
#include <SDL2/SDL.h>
#include <SDL_vulkan.h>
#include "sdl2.h"
#endif
namespace wi::platform
{
#ifdef _WIN32
#ifdef PLATFORM_UWP
using window_type = const winrt::Windows::UI::Core::CoreWindow*;
#else
using window_type = HWND;
#endif // PLATFORM_UWP
#elif SDL2
using window_type = SDL_Window*;
#else
using window_type = void*;
#endif // _WIN32
inline void Exit()
{
#ifdef _WIN32
#ifndef PLATFORM_UWP
PostQuitMessage(0);
#else
winrt::Windows::ApplicationModel::Core::CoreApplication::Exit();
#endif // PLATFORM_UWP
#endif // _WIN32
#ifdef SDL2
SDL_Event quit_event;
quit_event.type = SDL_QUIT;
SDL_PushEvent(&quit_event);
#endif
}
struct WindowProperties
{
int width = 0;
int height = 0;
float dpi = 96;
};
inline void GetWindowProperties(window_type window, WindowProperties* dest)
{
#ifdef PLATFORM_WINDOWS_DESKTOP
dest->dpi = (float)GetDpiForWindow(window);
#endif // WINDOWS_DESKTOP
#ifdef PLATFORM_XBOX
dest->dpi = 96.f;
#endif // PLATFORM_XBOX
#if defined(PLATFORM_WINDOWS_DESKTOP) || defined(PLATFORM_XBOX)
RECT rect;
GetClientRect(window, &rect);
dest->width = int(rect.right - rect.left);
dest->height = int(rect.bottom - rect.top);
#endif // PLATFORM_WINDOWS_DESKTOP || PLATFORM_XBOX
#ifdef PLATFORM_UWP
dest->dpi = winrt::Windows::Graphics::Display::DisplayInformation::GetForCurrentView().LogicalDpi();
float dpiscale = dest->dpi / 96.f;
dest->width = uint32_t(window->Bounds().Width * dpiscale);
dest->height = uint32_t(window->Bounds().Height * dpiscale);
#endif // PLATFORM_UWP
#ifdef PLATFORM_LINUX
int window_width, window_height;
SDL_GetWindowSize(window, &window_width, &window_height);
SDL_Vulkan_GetDrawableSize(window, &dest->width, &dest->height);
dest->dpi = ((float)dest->width / (float)window_width) * 96.f;
#endif // PLATFORM_LINUX
}
}