Skip to content

Commit

Permalink
Add create sprite and overlay support
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Apr 17, 2024
1 parent 79bb059 commit e0da39e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
33 changes: 33 additions & 0 deletions fancy_demo/fancy.asc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,39 @@ void DrawFancyTextWrapped(this DrawingSurface*, int x, int y, int width, int col
_draw_tokens(tk_arr, tk_count, fs, this, text, -1, width, config);
}


void DrawFancyText(this DrawingSurface*, int x, int y, int color, FontType font, const string text)
{
this.DrawFancyTextWrapped(x, y, FANCY_INFINITE_WIDTH, color, font, text);
}

DynamicSprite* CreateFromFancyTextWrapped(static DynamicSprite, int width, int color, FontType font, const string text)
{
FancyTextToken* tk_arr[] = _NewTxtTok();
FancyState* fs = NewState(0, 0);
FancyDrawingConfig* config = FancyDrawingConfig.Create(font, color);
int tk_count = _parse_text(tk_arr, text, config);
tk_count = _do_word_wrapping(tk_arr, tk_count, fs, text, width);
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);
surf.Release();
return spr;
}

DynamicSprite* CreateFromFancyText(static DynamicSprite, int color, FontType font, const string text)
{
DynamicSprite.CreateFromFancyTextWrapped(FANCY_INFINITE_WIDTH, color, font, text);
}

Overlay* CreateFancyTextual(static Overlay, int x, int y, int width, FontType font, int color, const string text)
{
DynamicSprite* spr = DynamicSprite.CreateFromFancyTextWrapped(width, color, font, text);
Overlay* ovr = Overlay.CreateGraphical(x, y, spr.Graphic, true, true);
spr.Delete();
return ovr;
}

void FancyTextBase::SetDrawingConfig(FancyDrawingConfig* config)
{
if(config == null) {
Expand Down
14 changes: 13 additions & 1 deletion fancy_demo/fancy.ash
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ managed struct FancyState {
// ---------------- fancy module public interface -----------------------
// ----------------------------------------------------------------------

/// Draw the text parsing fancyness
/// Draw the text from a fancy string with word-wrap at set width
import void DrawFancyTextWrapped(this DrawingSurface*, int x, int y, int width, int color, FontType font, const string text);

/// Draw the text from a fancy string
import void DrawFancyText(this DrawingSurface*, int x, int y, int color, FontType font, const string text);

/// Create a sprite with the text of a fancy string wwith word-wrap at set width
import DynamicSprite* CreateFromFancyTextWrapped(static DynamicSprite, int width, int color, FontType font, const string text);

/// Create a sprite with the text of a fancy string
import DynamicSprite* CreateFromFancyText(static DynamicSprite, int color, FontType font, const string text);

/// Creates a screen overlay from fancy text
import Overlay* CreateFancyTextual(static Overlay, int x, int y, int width, FontType font, int color, const string text);

managed struct FancyDrawingConfig {
int Font, TextColor, OutlineColor, OutlineWidth, LineSpacing, TextAlign;
/// Create minimal fancy drawing configuration
Expand Down
3 changes: 3 additions & 0 deletions fancy_demo/room1.asc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function hGlowingOrb_Look(Hotspot *thisHotspot, CursorMode mode)
}

FancyTypedText fttb;
Overlay* ovr;

function room_AfterFadeIn()
{
Expand All @@ -19,6 +20,8 @@ function room_AfterFadeIn()
fttb.SetDrawingConfig(FancyDrawingConfig.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.CreateFancyTextual(100, 100, 50, eFontNormal, 65535, "[c:61025]A [o:33153]key[/o] [s:2042][/c]!");
}

void repeatedly_execute_always()
Expand Down

0 comments on commit e0da39e

Please sign in to comment.