Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 5ea6d2d

Browse files
committed
fixes
1 parent 6a4b04e commit 5ea6d2d

File tree

2 files changed

+69
-27
lines changed

2 files changed

+69
-27
lines changed

source/Main.hx

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class Main extends Sprite
7171
super();
7272

7373
#if (cpp && windows)
74-
backend.Native.setWindowDarkMode(true, true);
7574
backend.Native.fixScaling();
75+
backend.Native.setWindowDarkMode(true, true);
7676
#end
7777

7878
// Credits to MAJigsaw77 (he's the og author for this code)

source/backend/Native.hx

+68-26
Original file line numberDiff line numberDiff line change
@@ -104,60 +104,102 @@ class Native
104104

105105
/**
106106
* Enables or disables dark mode support for the title bar.
107+
* Only works on Windows.
107108
*
108109
* @param enable Whether to enable or disable dark mode support.
109110
* @param instant Whether to skip the transition tween.
110111
*/
111112
public static function setWindowDarkMode(enable:Bool = true, instant:Bool = false):Void
112113
{
113114
#if (cpp && windows)
115+
var success:Bool = false;
114116
untyped __cpp__('
115-
const BOOL darkMode = enable ? TRUE : FALSE;
116-
117117
getHandle();
118118
if (curHandle != (HWND)0) {
119-
if (S_OK != DwmSetWindowAttribute(curHandle, darkModeAttribute, (LPCVOID)&darkMode, (DWORD)sizeof(darkMode))) {
120-
DwmSetWindowAttribute(curHandle, darkModeAttributeFallback, (LPCVOID)&darkMode, (DWORD)sizeof(darkMode));
119+
const BOOL darkMode = enable ? TRUE : FALSE;
120+
if (
121+
S_OK == DwmSetWindowAttribute(curHandle, darkModeAttribute, (LPCVOID)&darkMode, (DWORD)sizeof(darkMode)) ||
122+
S_OK == DwmSetWindowAttribute(curHandle, darkModeAttributeFallback, (LPCVOID)&darkMode, (DWORD)sizeof(darkMode))
123+
) {
124+
success = true;
121125
}
122126

123127
UpdateWindow(curHandle);
124128
}
125129
');
126-
127-
if (instant)
130+
131+
if (instant && success)
128132
{
129-
setWindowColors(0xff000000);
130-
setWindowColors();
133+
final curBarColor:Null<FlxColor> = windowBarColor;
134+
windowBarColor = FlxColor.BLACK;
135+
windowBarColor = curBarColor;
131136
}
132137
#end
133138
}
134139

135140
/**
136-
* Sets window colors.
137-
*
138-
* If any of the parameters are not provided, the corresponding color is reset to the system default.
139-
*
140-
* @param bar The color to use for the title bar.
141-
* @param text The color to use for the title bar text.
142-
* @param border The color to use for the window border.
141+
* The color of the window title bar. If `null`, the default is used.
142+
* Only works on Windows.
143143
*/
144-
public static function setWindowColors(?bar:FlxColor, ?text:FlxColor, ?border:FlxColor):Void
144+
public static var windowBarColor(default, set):Null<FlxColor> = null;
145+
public static function set_windowBarColor(value:Null<FlxColor>):Null<FlxColor>
145146
{
146147
#if (cpp && windows)
147-
final intBar:Int = Std.isOfType(bar, Int) ? cast FlxColor.fromRGB(bar.blue, bar.green, bar.red, 0) : 0xffffffff;
148-
final intText:Int = Std.isOfType(text, Int) ? cast FlxColor.fromRGB(text.blue, text.green, text.red, 0) : 0xffffffff;
149-
final intBorder:Int = Std.isOfType(border, Int) ? cast FlxColor.fromRGB(border.blue, border.green, border.red, 0) : 0xffffffff;
148+
final intColor:Int = Std.isOfType(value, Int) ? cast FlxColor.fromRGB(value.blue, value.green, value.red, 0) : 0xffffffff;
150149
untyped __cpp__('
151-
COLORREF targetBar = (COLORREF)intBar;
152-
COLORREF targetText = (COLORREF)intText;
153-
COLORREF targetBorder = (COLORREF)intBorder;
150+
getHandle();
151+
if (curHandle != (HWND)0) {
152+
const COLORREF targetColor = (COLORREF)intColor;
153+
DwmSetWindowAttribute(curHandle, DWMWINDOWATTRIBUTE::DWMWA_CAPTION_COLOR, (LPCVOID)&targetColor, (DWORD)sizeof(targetColor));
154+
UpdateWindow(curHandle);
155+
}
156+
');
157+
#end
158+
159+
return windowBarColor = value;
160+
}
154161

162+
/**
163+
* The color of the window title bar text. If `null`, the default is used.
164+
* Only works on Windows.
165+
*/
166+
public static var windowTextColor(default, set):Null<FlxColor> = null;
167+
public static function set_windowTextColor(value:Null<FlxColor>):Null<FlxColor>
168+
{
169+
#if (cpp && windows)
170+
final intColor:Int = Std.isOfType(value, Int) ? cast FlxColor.fromRGB(value.blue, value.green, value.red, 0) : 0xffffffff;
171+
untyped __cpp__('
155172
getHandle();
156-
DwmSetWindowAttribute(curHandle, DWMWINDOWATTRIBUTE::DWMWA_CAPTION_COLOR, (LPCVOID)&targetBar, (DWORD)sizeof(targetBar));
157-
DwmSetWindowAttribute(curHandle, DWMWINDOWATTRIBUTE::DWMWA_TEXT_COLOR, (LPCVOID)&targetText, (DWORD)sizeof(targetText));
158-
DwmSetWindowAttribute(curHandle, DWMWINDOWATTRIBUTE::DWMWA_BORDER_COLOR, (LPCVOID)&targetBorder, (DWORD)sizeof(targetBorder));
159-
UpdateWindow(curHandle);
173+
if (curHandle != (HWND)0) {
174+
const COLORREF targetColor = (COLORREF)intColor;
175+
DwmSetWindowAttribute(curHandle, DWMWINDOWATTRIBUTE::DWMWA_TEXT_COLOR, (LPCVOID)&targetColor, (DWORD)sizeof(targetColor));
176+
UpdateWindow(curHandle);
177+
}
178+
');
179+
#end
180+
181+
return windowTextColor = value;
182+
}
183+
184+
/**
185+
* The color of the window border. If `null`, the default is used.
186+
* Only works on Windows.
187+
*/
188+
public static var windowBorderColor(default, set):Null<FlxColor> = null;
189+
public static function set_windowBorderColor(value:Null<FlxColor>):Null<FlxColor>
190+
{
191+
#if (cpp && windows)
192+
final intColor:Int = Std.isOfType(value, Int) ? cast FlxColor.fromRGB(value.blue, value.green, value.red, 0) : 0xffffffff;
193+
untyped __cpp__('
194+
getHandle();
195+
if (curHandle != (HWND)0) {
196+
const COLORREF targetColor = (COLORREF)intColor;
197+
DwmSetWindowAttribute(curHandle, DWMWINDOWATTRIBUTE::DWMWA_BORDER_COLOR, (LPCVOID)&targetColor, (DWORD)sizeof(targetColor));
198+
UpdateWindow(curHandle);
199+
}
160200
');
161201
#end
202+
203+
return windowBorderColor = value;
162204
}
163205
}

0 commit comments

Comments
 (0)