Skip to content

Commit e8205ac

Browse files
authored
FlxDebugger: Add scale and defaultScale (#3399)
* add debug scale * add to coverage
1 parent 3064087 commit e8205ac

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

flixel/system/debug/FlxDebugger.hx

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ package flixel.system.debug;
33
import openfl.display.BitmapData;
44
import openfl.display.Sprite;
55
#if FLX_DEBUG
6-
import openfl.events.MouseEvent;
7-
import openfl.geom.Point;
8-
import openfl.geom.Rectangle;
9-
import openfl.text.TextField;
10-
import openfl.text.TextFieldAutoSize;
11-
import openfl.text.TextFormat;
12-
import openfl.display.DisplayObject;
136
import flixel.FlxG;
7+
import flixel.system.FlxAssets;
8+
import flixel.system.debug.completion.CompletionList;
149
import flixel.system.debug.console.Console;
10+
import flixel.system.debug.interaction.Interaction;
11+
import flixel.system.debug.log.BitmapLog;
1512
import flixel.system.debug.log.Log;
1613
import flixel.system.debug.stats.Stats;
17-
import flixel.system.debug.watch.Watch;
1814
import flixel.system.debug.watch.Tracker;
19-
import flixel.system.debug.completion.CompletionList;
20-
import flixel.system.debug.log.BitmapLog;
21-
import flixel.system.debug.interaction.Interaction;
22-
import flixel.system.FlxAssets;
15+
import flixel.system.debug.watch.Watch;
2316
import flixel.system.ui.FlxSystemButton;
2417
import flixel.util.FlxHorizontalAlign;
18+
import openfl.display.DisplayObject;
19+
import openfl.events.MouseEvent;
20+
import openfl.geom.Point;
21+
import openfl.geom.Rectangle;
22+
import openfl.text.TextField;
23+
import openfl.text.TextFieldAutoSize;
24+
import openfl.text.TextFormat;
2525

2626
using flixel.util.FlxArrayUtil;
2727
#end
@@ -33,6 +33,20 @@ using flixel.util.FlxArrayUtil;
3333
class FlxDebugger extends openfl.display.Sprite
3434
{
3535
#if FLX_DEBUG
36+
37+
38+
/**
39+
* The scale of the debug windows must be set before the `FlxGame` is made.
40+
* Can also use the compile flag `-DFLX_DEBUGGER_SCALE=2`
41+
*/
42+
public static var defaultScale:Int
43+
#if FLX_DEBUGGER_SCALE
44+
= Std.parseInt('${haxe.macro.Compiler.getDefine("FLX_DEBUGGER_SCALE")}');
45+
#else
46+
= 1;
47+
#end
48+
49+
3650
/**
3751
* Internal, used to space out windows from the edges.
3852
*/
@@ -50,6 +64,7 @@ class FlxDebugger extends openfl.display.Sprite
5064
public var vcr:VCR;
5165
public var console:Console;
5266
public var interaction:Interaction;
67+
public var scale:Int;
5368

5469
var completionList:CompletionList;
5570

@@ -84,13 +99,18 @@ class FlxDebugger extends openfl.display.Sprite
8499
/**
85100
* Instantiates the debugger overlay.
86101
*
87-
* @param Width The width of the screen.
88-
* @param Height The height of the screen.
102+
* @param width The width of the screen.
103+
* @param height The height of the screen.
104+
* @param scale The scale of the debugger relative to the stage size
89105
*/
90106
@:allow(flixel.FlxGame)
91-
function new(Width:Float, Height:Float)
107+
function new(width:Float, height:Float, scale = 0)
92108
{
93109
super();
110+
if (scale == 0)
111+
scale = defaultScale;
112+
scaleX = scale;
113+
scaleY = scale;
94114

95115
visible = false;
96116
tabChildren = false;
@@ -99,7 +119,7 @@ class FlxDebugger extends openfl.display.Sprite
99119

100120
_topBar = new Sprite();
101121
_topBar.graphics.beginFill(0x000000, 0xAA / 255);
102-
_topBar.graphics.drawRect(0, 0, FlxG.stage.stageWidth, TOP_HEIGHT);
122+
_topBar.graphics.drawRect(0, 0, FlxG.stage.stageWidth / scaleX, TOP_HEIGHT);
103123
_topBar.graphics.endFill();
104124
addChild(_topBar);
105125

@@ -148,7 +168,7 @@ class FlxDebugger extends openfl.display.Sprite
148168

149169
addChild(completionList);
150170

151-
onResize(Width, Height);
171+
onResize(width, height);
152172

153173
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
154174
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
@@ -292,16 +312,19 @@ class FlxDebugger extends openfl.display.Sprite
292312
}
293313
}
294314

295-
public function onResize(Width:Float, Height:Float):Void
315+
public function onResize(width:Float, height:Float, scale = 0):Void
296316
{
297-
_screen.x = Width;
298-
_screen.y = Height;
317+
if (scale == 0)
318+
scale = defaultScale;
319+
this.scale = scale;
320+
_screen.x = width / scale;
321+
_screen.y = height / scale;
299322

300323
updateBounds();
301-
_topBar.width = FlxG.stage.stageWidth;
324+
_topBar.width = FlxG.stage.stageWidth / scaleX;
302325
resetButtonLayout();
303326
resetLayout();
304-
scaleX = scaleY = 1;
327+
scaleX = scaleY = scale;
305328
x = -FlxG.scaleMode.offset.x;
306329
y = -FlxG.scaleMode.offset.y;
307330
}
@@ -342,10 +365,10 @@ class FlxDebugger extends openfl.display.Sprite
342365
{
343366
hAlignButtons(_buttons[FlxHorizontalAlign.LEFT], 10, true, 10);
344367

345-
var offset = FlxG.stage.stageWidth * 0.5 - hAlignButtons(_buttons[FlxHorizontalAlign.CENTER], 10, false) * 0.5;
368+
var offset = FlxG.stage.stageWidth / scaleX * 0.5 - hAlignButtons(_buttons[FlxHorizontalAlign.CENTER], 10, false) * 0.5;
346369
hAlignButtons(_buttons[FlxHorizontalAlign.CENTER], 10, true, offset);
347370

348-
var offset = FlxG.stage.stageWidth - hAlignButtons(_buttons[FlxHorizontalAlign.RIGHT], 10, false);
371+
var offset = FlxG.stage.stageWidth / scaleX - hAlignButtons(_buttons[FlxHorizontalAlign.RIGHT], 10, false);
349372
hAlignButtons(_buttons[FlxHorizontalAlign.RIGHT], 10, true, offset);
350373
}
351374

flixel/system/macros/FlxDefines.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import haxe.io.Path;
44
import haxe.macro.Compiler;
55
import haxe.macro.Context;
66
import haxe.macro.Expr.Position;
7+
78
using StringTools;
89
#if (flixel_addons >= "3.2.2")
910
import flixel.addons.system.macros.FlxAddonDefines;
@@ -58,6 +59,11 @@ private enum UserDefines
5859
* If this flag is set to any string, that is used for the file extension
5960
*/
6061
FLX_DEFAULT_SOUND_EXT;
62+
63+
/**
64+
* Used to make the debug windows bigger
65+
*/
66+
FLX_DEBUGGER_SCALE;
6167
}
6268

6369
/**

tests/coverage/Project.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@
7979
<haxedef name="FLX_NO_HEALTH" />
8080
<haxedef name="FLX_4_LEGACY_COLLISION" />
8181
<haxedef name="FLX_DEFAULT_SOUND_EXT" />
82+
<haxedef name="FLX_DEBUGGER_SCALE" value="2" />
8283
</section>
8384
</project>

0 commit comments

Comments
 (0)