1
+ package backend ;
2
+
3
+ import lime .app .Application ;
4
+ import lime .system .Display ;
5
+ import lime .system .System ;
6
+
7
+ import flixel .util .FlxColor ;
8
+
9
+ #if (cpp && windows)
10
+ @:buildXml ('
11
+ <target id="haxe">
12
+ <lib name="dwmapi.lib" if="windows"/>
13
+ <lib name="gdi32.lib" if="windows"/>
14
+ </target>
15
+ ' )
16
+ @:cppFileCode ('
17
+ #include <windows.h>
18
+ #include <dwmapi.h>
19
+ #include <winuser.h>
20
+ #include <wingdi.h>
21
+
22
+ #define attributeDarkMode 20
23
+ #define attributeDarkModeFallback 19
24
+
25
+ #define attributeCaptionColor 34
26
+ #define attributeTextColor 35
27
+ #define attributeBorderColor 36
28
+
29
+ struct HandleData {
30
+ DWORD pid = 0;
31
+ HWND handle = 0;
32
+ };
33
+
34
+ BOOL CALLBACK findByPID(HWND handle, LPARAM lParam) {
35
+ DWORD targetPID = ((HandleData*)lParam)->pid;
36
+ DWORD curPID = 0;
37
+
38
+ GetWindowThreadProcessId(handle, &curPID);
39
+ if (targetPID != curPID || GetWindow(handle, GW_OWNER) != (HWND)0 || !IsWindowVisible(handle)) {
40
+ return TRUE;
41
+ }
42
+
43
+ ((HandleData*)lParam)->handle = handle;
44
+ return FALSE;
45
+ }
46
+
47
+ HWND curHandle = 0;
48
+ void getHandle() {
49
+ if (curHandle == (HWND)0) {
50
+ HandleData data;
51
+ data.pid = GetCurrentProcessId();
52
+ EnumWindows(findByPID, (LPARAM)&data);
53
+ curHandle = data.handle;
54
+ }
55
+ }
56
+ ' )
57
+ #end
58
+ class Native
59
+ {
60
+ public static function __init__ (): Void
61
+ {
62
+ registerDPIAware ();
63
+ }
64
+
65
+ public static function registerDPIAware (): Void
66
+ {
67
+ #if (cpp && windows)
68
+ // DPI Scaling fix for windows
69
+ // this shouldn't be needed for other systems
70
+ // Credit to YoshiCrafter29 for finding this function
71
+ untyped __cpp__ ('
72
+ SetProcessDPIAware();
73
+ #ifdef DPI_AWARENESS_CONTEXT
74
+ SetProcessDpiAwarenessContext(
75
+ #ifdef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
76
+ DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
77
+ #else
78
+ DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
79
+ #endif
80
+ );
81
+ #endif
82
+ ' );
83
+ #end
84
+ }
85
+
86
+ private static var fixedScaling : Bool = false ;
87
+ public static function fixScaling (): Void
88
+ {
89
+ if (fixedScaling ) return ;
90
+ fixedScaling = true ;
91
+
92
+ #if (cpp && windows)
93
+ final display : Null <Display > = System .getDisplay (0 );
94
+ if (display != null )
95
+ {
96
+ final dpiScale : Float = display .dpi / 96 ;
97
+ @:privateAccess Application .current .window .width = Std .int (Main .game .width * dpiScale );
98
+ @:privateAccess Application .current .window .height = Std .int (Main .game .height * dpiScale );
99
+
100
+ Application .current .window .x = Std .int ((Application .current .window .display .bounds .width - Application .current .window .width ) / 2 );
101
+ Application .current .window .y = Std .int ((Application .current .window .display .bounds .height - Application .current .window .height ) / 2 );
102
+ }
103
+
104
+ untyped __cpp__ ('
105
+ getHandle();
106
+ if (curHandle != (HWND)0) {
107
+ HDC curHDC = GetDC(curHandle);
108
+ RECT curRect;
109
+ GetClientRect(curHandle, &curRect);
110
+ FillRect(curHDC, &curRect, (HBRUSH)GetStockObject(BLACK_BRUSH));
111
+ ReleaseDC(curHandle, curHDC);
112
+ }
113
+ ' );
114
+ #end
115
+ }
116
+ }
0 commit comments