From ed841e50a36e92ce05c6f901d4238d2958371ee0 Mon Sep 17 00:00:00 2001 From: lunarcleint Date: Sat, 22 Feb 2025 16:03:30 -0700 Subject: [PATCH] fully move to draw util !! --- source/funkin/backend/utils/DrawUtil.hx | 3 +- .../editors/character/CharacterGizmos.hx | 44 ++++++------------- source/funkin/editors/extra/AxisGizmo.hx | 2 +- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/source/funkin/backend/utils/DrawUtil.hx b/source/funkin/backend/utils/DrawUtil.hx index 0e70b745..5eba5657 100644 --- a/source/funkin/backend/utils/DrawUtil.hx +++ b/source/funkin/backend/utils/DrawUtil.hx @@ -29,7 +29,7 @@ final class DrawUtil { var distance:Float = Math.sqrt(dx * dx + dy * dy); // Math.ceil to prevent flickering - line.setPosition(Math.ceil(point1.x), Math.ceil(point1.y)); + line.setPosition(point1.x, point1.y); line.angle = angle * FlxAngle.TO_DEG; line.origin.set(0, line.frameHeight / 2); line.scale.x = distance / line.frameWidth; @@ -46,6 +46,7 @@ final class DrawUtil { } public static inline function drawRect(rect:FlxRect, thickness:Float = 1, ?color:Null) { + if (rect.width <= 0 || rect.height <= 0) return; DrawUtil.drawLine(FlxPoint.weak(rect.x, rect.y), FlxPoint.weak(rect.x + rect.width, rect.y), thickness, color); DrawUtil.drawLine(FlxPoint.weak(rect.x, rect.y), FlxPoint.weak(rect.x, rect.y + rect.height), thickness, color); DrawUtil.drawLine(FlxPoint.weak(rect.x + rect.width, rect.y), FlxPoint.weak(rect.x + rect.width, rect.y + rect.height), thickness, color); diff --git a/source/funkin/editors/character/CharacterGizmos.hx b/source/funkin/editors/character/CharacterGizmos.hx index ed3c8887..a5d9f31f 100644 --- a/source/funkin/editors/character/CharacterGizmos.hx +++ b/source/funkin/editors/character/CharacterGizmos.hx @@ -18,39 +18,23 @@ class CharacterGizmos extends FlxSprite { } public function drawHitbox() { - // TODO: ATLAS VESION OF THIS CODE - if (character._matrix == null || character.frame == null) return; - for (camera in cameras) { - character._rect.set(character._matrix.tx, character._matrix.ty, character.frame.frame.width * character._matrix.a, character.frame.frame.height * character._matrix.d); - @:privateAccess character._rect = FlxG.camera.transformRect(character._rect); - trace(character._rect); + if (character.animateAtlas != null) { + // TODO: ATLAS CALCUATIONS + character._rect.set(); + } else if (character._matrix != null && character.frame != null) { + character._rect.set(character._matrix.tx, character._matrix.ty, character.frame.frame.width * character._matrix.a, character.frame.frame.height * character._matrix.d); + character._rect.offset(-character.cameras[0].viewMarginLeft, -character.cameras[0].viewMarginTop); + character._rect.x *= character.cameras[0].zoom; + character._rect.y *= character.cameras[0].zoom; + character._rect.width *= character.cameras[0].zoom; + character._rect.height *= character.cameras[0].zoom; + } if (DrawUtil.line == null) DrawUtil.createDrawers(); - DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.75; + DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.85; - DrawUtil.drawRect(character._rect, 1, 0xFF8F8A00); - // yes i made a drawRect function for this purpose, no im not using it >:D - DrawUtil.drawLine( - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y), FlxG.camera, FlxPoint.weak()), - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y), FlxG.camera, FlxPoint.weak()), - 1, 0xFF007B8F - ); - DrawUtil.drawLine( - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y), FlxG.camera, FlxPoint.weak()), - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), - 1, 0xFF007B8F - ); - DrawUtil.drawLine( - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y), FlxG.camera, FlxPoint.weak()), - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), - 1, 0xFF007B8F - ); - DrawUtil.drawLine( - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), - CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), - 1, 0xFF007B8F - ); + DrawUtil.drawRect(character._rect, 1, 0xFF007B8F); } } @@ -60,7 +44,7 @@ class CharacterGizmos extends FlxSprite { camPos -= camera.scroll; if (DrawUtil.line == null) DrawUtil.createDrawers(); - DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.75; + DrawUtil.line.camera = camera; DrawUtil.line.alpha = 1; DrawUtil.drawLine( CoolUtil.pointToScreenPosition(FlxPoint.weak(camPos.x - 8, camPos.y), FlxG.camera, FlxPoint.weak()), diff --git a/source/funkin/editors/extra/AxisGizmo.hx b/source/funkin/editors/extra/AxisGizmo.hx index a66ece95..2d4c7b8d 100644 --- a/source/funkin/editors/extra/AxisGizmo.hx +++ b/source/funkin/editors/extra/AxisGizmo.hx @@ -8,7 +8,7 @@ class AxisGizmo extends FlxObject { for (camera in cameras) { if (DrawUtil.line == null) DrawUtil.createDrawers(); - DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.75; + DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.85; CoolUtil.pointToScreenPosition(FlxPoint.weak(), FlxG.camera, _worldPos); // Stole these colors directly from godot >:D -luanr