Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions flixel/text/FlxBitmapText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,20 @@ class FlxBitmapText extends FlxSprite
func( 0, i); // lower-middle
func( i, i); // lower-right
}
case OUTLINE_CARDINAL:
// Render an outline around the text (4 draws | LEFT, RIGHT, UP, DOWN)
var iterations:Int = Std.int(borderSize * borderQuality);
iterations = (iterations <= 0) ? 1 : iterations;
final delta = Std.int(borderSize / iterations);
for (iter in 0...iterations)
{
final i = delta * (iter + 1);
func(-i, 0); // middle-left
func(i * 2, 0); // middle-right
func(-i, -i); // upper-middle
func(0, i * 2); // lower-middle
Comment on lines +1301 to +1305
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to test this locally, but I'm surprised by i*2 and upper middle being -i, -i. Looking at OUTLINE_FAST I would have expected the following

Suggested change
final i = delta * (iter + 1);
func(-i, 0); // middle-left
func(i * 2, 0); // middle-right
func(-i, -i); // upper-middle
func(0, i * 2); // lower-middle
final i = delta * (iter + 1);
func(-i, 0); // left
func( i, 0); // right
func( 0, -i); // up
func( 0, i); // down

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely a mistake on my end
i did not realize that FlxBitmapText seems to absolute instead of incremental like FlxText

}

case OUTLINE_FAST:
// Render an outline around the text in each corner (4 draws)
var iterations:Int = Std.int(borderSize * borderQuality);
Expand Down
28 changes: 25 additions & 3 deletions flixel/text/FlxText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ class FlxText extends FlxSprite
borderWidth += Math.abs(offsetX);
borderHeight += Math.abs(offsetY);

case OUTLINE_FAST | OUTLINE:
case OUTLINE_FAST | OUTLINE | OUTLINE_CARDINAL:
borderWidth += Math.abs(borderSize) * 2;
borderHeight += Math.abs(borderSize) * 2;

Expand Down Expand Up @@ -1095,10 +1095,10 @@ class FlxText extends FlxSprite
_graphicOffset.x = offsetX < 0 ? -offsetX : 0;
_graphicOffset.y = offsetY < 0 ? -offsetY : 0;

case OUTLINE_FAST | OUTLINE if (borderSize < 0):
case OUTLINE_FAST | OUTLINE | OUTLINE_CARDINAL if (borderSize < 0):
_graphicOffset.set(-borderSize, -borderSize);

case NONE | OUTLINE_FAST | OUTLINE:
case NONE | OUTLINE_FAST | OUTLINE | OUTLINE_CARDINAL:
_graphicOffset.set(0, 0);
}
_matrix.translate(_graphicOffset.x, _graphicOffset.y);
Expand Down Expand Up @@ -1176,6 +1176,24 @@ class FlxText extends FlxSprite
_matrix.translate(curDelta, 0); // return to center
}

case OUTLINE_CARDINAL:
// Render an outline around the text
// (do 4 offset draw calls just in all cardinal directions)
applyFormats(_formatAdjusted, true);

final iterations = FlxMath.maxInt(1, Std.int(borderSize * borderQuality));
var i = iterations + 1;
while (i-- > 1)
{
final curDelta = borderSize / iterations * i;
copyTextWithOffset(-curDelta, 0); // middle-left
copyTextWithOffset(curDelta * 2, 0); // middle-right
copyTextWithOffset(-curDelta, -curDelta); // upper-middle
copyTextWithOffset(0, curDelta * 2); // lower-middle

_matrix.translate(0, -curDelta); // return to center
}

case OUTLINE_FAST:
// Render an outline around the text
// (do 4 diagonal offset draw calls)
Expand Down Expand Up @@ -1384,6 +1402,10 @@ enum FlxTextBorderStyle
* Outline on all 8 sides
*/
OUTLINE;
/**
* Outline on all 4 cardinal directions (UP, DOWN, LEFT, RIGHT)
*/
OUTLINE_CARDINAL;

/**
* Outline, optimized using only 4 draw calls
Expand Down
Loading