Skip to content

Commit b0e05cf

Browse files
Tools: Keep each window's scale for projects that use OpenFL 9.5.2 or earlier, which read it only once
1 parent 08601d7 commit b0e05cf

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Changelog
136136
- Changed `Font.loadFromName()` on HTML5 to use the browser's CSS Font Loading API in Safari, as in other browsers, rather than measuring text for up to three seconds.
137137
- Changed HTML5 applications with a frame rate of 0 to update on every animation frame.
138138
- Changed the error when the main class isn't found to also mention a missing `<source />` path.
139-
- Changed `Window.scale` to follow changes to the display scale, which `Window.onDisplayScaleChange` reports. Define `lime_disable_window_scale_change` to keep the scale a window was created with.
139+
- Changed `Window.scale` to follow changes to the display scale, which `Window.onDisplayScaleChange` reports. Define `lime_disable_window_scale_change` to keep the scale a window was created with, as projects that use OpenFL 9.5.2 or earlier do, since those versions read it only once. Define `lime_window_scale_change` to follow it with them anyway.
140140
- Changed SDL to name the application after its first window, as Linux shows it while it plays sound or keeps the screen awake.
141141
- Changed native windows to share OpenGL textures, buffers, and shaders with the main window, and to keep the main window's context current outside of rendering, rather than the last window created or rendered.
142142
- Changed desktop builds to include SDL's virtual joystick driver, as SDL does by default.

‎src/lime/tools/ProjectHelper.hx‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ class ProjectHelper
188188
return string;
189189
}
190190

191+
/**
192+
Keeps each window's scale as it was created, with `lime_disable_window_scale_change`,
193+
for a project that uses OpenFL 9.5.2 or earlier. Those versions read the scale once,
194+
so a window that followed a change of the display's scale would be drawn at the old
195+
one. A project can define `lime_window_scale_change` to follow it anyway.
196+
**/
197+
public static function keepWindowScaleForOlderOpenFL(project:HXProject):Void
198+
{
199+
if (project.haxedefs.exists("lime_disable_window_scale_change") || project.haxedefs.exists("lime_window_scale_change"))
200+
{
201+
return;
202+
}
203+
204+
for (haxelib in project.haxelibs)
205+
{
206+
if (haxelib.name == "openfl")
207+
{
208+
var version:Version = Haxelib.getVersion(haxelib);
209+
210+
if (version != null && version < ("9.5.3" : Version))
211+
{
212+
project.haxedefs.set("lime_disable_window_scale_change", "1");
213+
}
214+
215+
return;
216+
}
217+
}
218+
}
219+
191220
/**
192221
Compares two values of a condition: numbers as numbers, dotted versions such as
193222
10.0.0 part by part, and anything else as text. A number with at most one dot,

‎src/lime/ui/Window.hx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,9 @@ class Window
333333

334334
/**
335335
Fired when `scale` changes, as when the window moves to a display with
336-
another scale, or the display's scale is changed. On native targets it can
337-
be left out with `lime_disable_window_scale_change`.
336+
another scale, or the display's scale is changed. It is left out with
337+
`lime_disable_window_scale_change`, which the tools define for projects that
338+
use OpenFL 9.5.2 or earlier, unless `lime_window_scale_change` is defined.
338339
**/
339340
public var onDisplayScaleChange(default, null) = new Event<Void->Void>();
340341

‎tools/CommandLineTools.hx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,7 @@ class CommandLineTools
18541854
}*/
18551855

18561856
project.merge(overrides);
1857+
ProjectHelper.keepWindowScaleForOlderOpenFL(project);
18571858

18581859
for (haxelib in project.haxelibs)
18591860
{

0 commit comments

Comments
 (0)