Skip to content

Commit

Permalink
consider outline width and allow to add a padding
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Apr 19, 2024
1 parent 5f4d14d commit 8dbaead
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions fancy_demo/fancy.asc
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ int _do_word_wrapping(FancyTextToken* tk_arr[], int tk_count, FancyState* fs, St
return tk_count;
}

void _adjust_state_sizes_to_config(FancyState* fs, FancyConfig* cfg)
{
int adjust = cfg.OutlineWidth + cfg.Padding;
fs.BoxWidth += adjust*2;
fs.BoxHeight += adjust*2;
fs.X += adjust;
fs.Y += adjust;
}

void _draw_string_outline(this DrawingSurface*, int x, int y, FontType font, String text, int outline_color, int outline_width)
{
this.DrawingColor = outline_color;
Expand Down Expand Up @@ -622,6 +631,9 @@ DynamicSprite* CreateFromFancyStringWrapped(static DynamicSprite, int width, Fan
FancyState* fs = NewState(0, 0);
int tk_count = _parse_text(tk_arr, text, config);
tk_count = _do_word_wrapping(tk_arr, tk_count, fs, text, width);

_adjust_state_sizes_to_config(fs, config); // fix outline and margin

DynamicSprite* spr = DynamicSprite.Create(fs.BoxWidth, fs.BoxHeight, true);
DrawingSurface* surf = spr.GetDrawingSurface();
_draw_tokens(tk_arr, tk_count, fs, surf, text, -1, width, config);
Expand Down
2 changes: 1 addition & 1 deletion fancy_demo/fancy.ash
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ managed struct FancyState {
managed struct FancyConfig {
FontType Font;
Alignment TextAlign;
int TextColor, OutlineColor, OutlineWidth, LineSpacing;
int TextColor, OutlineColor, OutlineWidth, LineSpacing, Padding;
/// Create minimal fancy drawing configuration
static import FancyConfig* Create(FontType font, int color, int outline_color = COLOR_TRANSPARENT, int outline_width = 1, Alignment align = eAlignBottomLeft, int line_spacing = 0); // $AUTOCOMPLETESTATICONLY$
};
Expand Down
6 changes: 4 additions & 2 deletions fancy_demo/room1.asc
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ function room_AfterFadeIn()

// surface extension
DrawingSurface* surf = Room.GetDrawingSurfaceForBackground();
surf.DrawFancyStringWrapped(10, 170, 60, FancyConfig.Create(eFontSpeechWithoutOutline, 65535), "[c:61025]A [o:33153]key[/o] [s:2042][/c]!");
FancyConfig* cfg = FancyConfig.Create(eFontSpeechWithoutOutline, 65535);
cfg.Padding = 2;
surf.DrawFancyStringWrapped(10, 170, 60, cfg, "[c:61025]A [o:33153]key[/o] [s:2042][/c]!");

// using text base
fttb.SetDrawingConfig(FancyConfig.Create(eFontSpeechWithoutOutline, 22422));
fttb.SetDrawingArea(48, 48, 200);
fttb.Start("Hello!\n[o:8560]Can you find me the [c:27647]blue cup [s:2041][/c][/o]?\nI lost it in the [c:red]dangerous [f:0]planet[/f][/c], somewhere.");

ovr = Overlay.CreateFancyTextBox(100, 100, 50, FancyConfig.Create(eFontNormal, 65535), "[c:61025]A [o:33153]key[/o] [s:2042][/c]!", Fancy9Piece.CreateFromTextWindowGui(gTextBorder));
ovr = Overlay.CreateFancyTextBox(100, 100, 50, cfg, "[c:61025]A [o:33153]key[/o] [s:2042][/c]!", Fancy9Piece.CreateFromTextWindowGui(gTextBorder));
}

void repeatedly_execute_always()
Expand Down

0 comments on commit 8dbaead

Please sign in to comment.