text

package
v0.1.0-preview.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package text provides text rendering utilities including bitmap fonts for sign display.

Package text provides text rendering utilities including sign rendering for Ultima V.

Index

Constants

View Source
const (
	// BitmapCharWidth is the width of each character in the source font (pixels)
	BitmapCharWidth = 8
	// BitmapCharHeight is the height of each character in the source font (pixels)
	BitmapCharHeight = 8
	// BitmapCharsPerRow is the number of characters per row in the sprite sheet
	BitmapCharsPerRow = 16
	// BitmapTotalChars is the total number of characters in the font
	BitmapTotalChars = 128
)
View Source
const (
	// DefaultMaxCacheEntries is the default maximum number of cached text images
	DefaultMaxCacheEntries = 512
	// DefaultMaxCacheBytes bounds cache-held pixel payload and owned text keys.
	DefaultMaxCacheBytes = 16 * 1024 * 1024
)
View Source
const (
	// FontScaleNormal is the default font scale (1.0x)
	FontScaleNormal float64 = 1.0
	// FontScaleHeader is used for section headers (1.25x larger)
	FontScaleHeader float64 = 1.25
)

FontScale constants for semantic text sizing

Variables

View Source
var IntroChoices = []string{
	"Journey Onward",
	"Select Save Game",
	"Import from Legacy",
	"Set Data Directory",
	"Create New Character",
	"Configure",
	"Ultima V Introduction",
	"Acknowledgments",
	"Return to the View",
}

IntroChoices defines the adapted Redux title-menu order.

REDUX DEVIATION: The original menu exposes six choices (ref:INTRO-0001). Redux adds save, import, data-path, and Configuration entries to its nine-choice title menu.

Functions

func ClearTextCache

func ClearTextCache()

ClearTextCache clears all cached text images (e.g., on resolution change)

func DecodeSignTranslation

func DecodeSignTranslation(rawText []byte) [][]ColorSegment

DecodeSignTranslation projects the very same logical cells used by RenderSign. It never changes source bytes or records the decoded inscription in history.

func GetCachedText

func GetCachedText(content string, face text.Face, options *text.LayoutOptions, textColor color.Color) *ebiten.Image

GetCachedText returns a cached text image or renders and caches a new one

func GetIntroFontSize

func GetIntroFontSize() float64

GetIntroFontSize calculates the font point size needed to fill the target height at 1:1 scale (no geometric stretching). This ensures crisp text rendering.

func GetScaleFactorByWindowSize

func GetScaleFactorByWindowSize(dm *display.DisplayManager) float64

func GetScaledNumberToResolution

func GetScaledNumberToResolution(dm *display.DisplayManager, defaultFontPoint float64) float64

func GetScaledNumberToWidth

func GetScaledNumberToWidth(width int, defaultValue float64) float64

GetScaledNumberToWidth scales a standard UI value for a logical render width.

func IntroMenuFramePlacement

func IntroMenuFramePlacement() sprites.PercentBasedPlacement

IntroMenuFramePlacement returns the title-menu frame bounds.

func ScaledCharHeight

func ScaledCharHeight(scale float64) float64

ScaledCharHeight returns the height of a character at the given scale.

func ScaledCharWidth

func ScaledCharWidth(scale float64) float64

ScaledCharWidth returns the width of a character at the given scale.

func StringWidthInChars

func StringWidthInChars(text string) int

StringWidthInChars returns the width of a string in character units.

func StringWidthScaled

func StringWidthScaled(text string, scale float64) float64

StringWidthScaled returns the pixel width of a string at the given scale.

Types

type BitmapFont

type BitmapFont struct {
	// contains filtered or unexported fields
}

BitmapFont represents a loaded bitmap font from a PNG sprite sheet. Each character is 8×8 pixels in the source, but can be scaled when rendering.

func (*BitmapFont) DrawChar

func (bf *BitmapFont) DrawChar(dst *ebiten.Image, charIndex int, x, y float64, scale float64, colorR, colorG, colorB float32) float64

DrawChar draws a single character at the specified position with the given scale. The character is drawn with the specified color tint. Returns the width of the drawn character (scaled).

func (*BitmapFont) DrawString

func (bf *BitmapFont) DrawString(dst *ebiten.Image, text string, x, y float64, scale float64, colorR, colorG, colorB float32) float64

DrawString draws a string at the specified position with the given scale. useRunic controls whether high-bit-clear bytes use runic font (true) or IBM font (false for both). Returns the total width of the drawn string.

func (*BitmapFont) GetCharImage

func (bf *BitmapFont) GetCharImage(charIndex int) *ebiten.Image

GetCharImage returns the sub-image for a given character index (0-127). Returns nil for out-of-range indices.

type BitmapFonts

type BitmapFonts struct {
	Runic *BitmapFont
	IBM   *BitmapFont
}

BitmapFonts holds the loaded runic and IBM bitmap fonts for sign rendering.

func GetBitmapFonts

func GetBitmapFonts() *BitmapFonts

GetBitmapFonts returns the singleton BitmapFonts instance, loading fonts on first call.

type CacheEntry

type CacheEntry struct {
	// contains filtered or unexported fields
}

CacheEntry represents a single cached text image with LRU tracking

type CacheKey

type CacheKey struct {
	// contains filtered or unexported fields
}

CacheKey is a comparable rendering identity; its fields remain cache-owned.

type ColorSegment

type ColorSegment struct {
	Text      string
	Color     color.Color
	FontType  FontType // Defaults to FontTypeNormal (zero value)
	FontScale float64  // Scale multiplier for font size (0 or 1.0 = normal, 1.25 = header)
}

ColorSegment represents a piece of text with a specific color and font type

type CreditParagraph

type CreditParagraph struct {
	Heading string
	Label   string
	Value   string
}

CreditParagraph is content only. Layout, scrolling and input belong to the reader. Empty paragraphs provide spacing; labels and values have distinct roles.

func OriginalAndReduxCredits

func OriginalAndReduxCredits() []CreditParagraph

OriginalAndReduxCredits preserves the names/role wording printed in the original STARTSC.16 center panel, plus the Book of Lore music acknowledgment. Evidence and contributor provenance: docs/gamefacts/STARTUP_MENU_AND_INTRODUCTIONS.md.

func SpecialThanksCredits

func SpecialThanksCredits() []CreditParagraph

SpecialThanksCredits closes the continuous document on a readable resting row.

type FontType

type FontType int

FontType indicates which font to use for rendering a text segment

const (
	// FontTypeNormal uses the standard TrueType font
	FontTypeNormal FontType = iota
	// FontTypeRunic uses the bitmap runic font (8x8 scaled)
	FontTypeRunic
	// FontTypeIBM uses the bitmap IBM font (8x8 scaled).
	FontTypeIBM
	// FontTypeCommandPrompt draws the original one-cell bitmap input marker.
	FontTypeCommandPrompt
)

type JournalHistoryRow

type JournalHistoryRow struct {
	Message      int
	SourceOffset int
	Text         string
}

JournalHistoryRow maps one measured display row to a logical message and its UTF-8 byte offset. Explicit blank separators have Message -1.

func WrapJournalHistory

func WrapJournalHistory(history string, font *UltimaFont, width int) []JournalHistoryRow

WrapJournalHistory reflows the detached source, never the rail's hyphenated rows. A single glyph wider than width is retained alone so reading progresses.

type LineBuilder

type LineBuilder struct {
	// contains filtered or unexported fields
}

LineBuilder provides a fluent API for building multi-colored text lines

func (*LineBuilder) AvatarSpoken

func (lb *LineBuilder) AvatarSpoken(text string) *LineBuilder

AvatarSpoken adds light green text segment for player/avatar dialogue

func (*LineBuilder) AvatarSpokenf

func (lb *LineBuilder) AvatarSpokenf(format string, args ...interface{}) *LineBuilder

AvatarSpokenf adds formatted light green text segment for player/avatar dialogue

func (*LineBuilder) AvatarWhatHeDid

func (lb *LineBuilder) AvatarWhatHeDid(text string) *LineBuilder

AvatarSpoken adds light green text segment for player/avatar dialogue

func (*LineBuilder) AvatarWhatHeDidf

func (lb *LineBuilder) AvatarWhatHeDidf(format string, args ...interface{}) *LineBuilder

AvatarSpokenf adds formatted light green text segment for player/avatar dialogue

func (*LineBuilder) Blue

func (lb *LineBuilder) Blue(text string) *LineBuilder

Blue adds blue text segment

func (*LineBuilder) Bluef

func (lb *LineBuilder) Bluef(format string, args ...interface{}) *LineBuilder

Bluef adds formatted blue text segment

func (*LineBuilder) Brown

func (lb *LineBuilder) Brown(text string) *LineBuilder

Brown adds brown text segment

func (*LineBuilder) Brownf

func (lb *LineBuilder) Brownf(format string, args ...interface{}) *LineBuilder

Brownf adds formatted brown text segment

func (*LineBuilder) CommandPromptMarker

func (lb *LineBuilder) CommandPromptMarker(markerColor color.Color) *LineBuilder

CommandPromptMarker adds the one-column bitmap marker using the supplied outline color.

func (*LineBuilder) Cyan

func (lb *LineBuilder) Cyan(text string) *LineBuilder

Cyan adds cyan text segment

func (*LineBuilder) Cyanf

func (lb *LineBuilder) Cyanf(format string, args ...interface{}) *LineBuilder

Cyanf adds formatted cyan text segment

func (*LineBuilder) DarkGray

func (lb *LineBuilder) DarkGray(text string) *LineBuilder

DarkGray adds dark gray text segment

func (*LineBuilder) DarkGrayf

func (lb *LineBuilder) DarkGrayf(format string, args ...interface{}) *LineBuilder

DarkGrayf adds formatted dark gray text segment

func (*LineBuilder) Done

func (lb *LineBuilder) Done()

Done commits the built line to the parent Output Note: AddStyledText automatically handles word wrapping at word boundaries, so text longer than Output.maxCharsPerLine will be split across multiple lines.

func (*LineBuilder) EquipmentIcon

func (lb *LineBuilder) EquipmentIcon(equipment references.Equipment) *LineBuilder

EquipmentIcon adds a single runic character representing a specific equipment item. Uses the equipment-specific Runic display code; ref:EQUIP-0003. For example, a Bow shows a bow icon, a Halberd shows a halberd icon, etc.

func (*LineBuilder) EquipmentIconWithColor

func (lb *LineBuilder) EquipmentIconWithColor(equipment references.Equipment, textColor color.Color) *LineBuilder

EquipmentIconWithColor adds a single runic character representing a specific equipment item with a specific color. Uses the equipment-specific Runic display code; ref:EQUIP-0003.

func (*LineBuilder) GetSegments

func (lb *LineBuilder) GetSegments() []ColorSegment

GetSegments returns the current segments for debugging purposes

func (*LineBuilder) Green

func (lb *LineBuilder) Green(text string) *LineBuilder

Green adds green text segment

func (*LineBuilder) Greenf

func (lb *LineBuilder) Greenf(format string, args ...interface{}) *LineBuilder

Greenf adds formatted green text segment

func (*LineBuilder) Header

func (lb *LineBuilder) Header(text string) *LineBuilder

Header adds text with a larger font (1.25x scale) for section headers. Default color is white.

func (*LineBuilder) HeaderWithColor

func (lb *LineBuilder) HeaderWithColor(text string, textColor color.Color) *LineBuilder

HeaderWithColor adds header text with a larger font (1.25x scale) and custom color.

func (*LineBuilder) Headerf

func (lb *LineBuilder) Headerf(format string, args ...interface{}) *LineBuilder

Headerf adds formatted header text with a larger font (1.25x scale). Default color is white.

func (*LineBuilder) IBM

func (lb *LineBuilder) IBM(text string) *LineBuilder

IBM adds an IBM text segment using the fixed 8x8 bitmap font. Color is inherited from the previous segment, defaulting to white.

func (*LineBuilder) IBMWithColor

func (lb *LineBuilder) IBMWithColor(text string, textColor color.Color) *LineBuilder

IBMWithColor adds an IBM bitmap text segment with a specific color.

func (*LineBuilder) LightBlue

func (lb *LineBuilder) LightBlue(text string) *LineBuilder

LightBlue adds light blue text segment

func (*LineBuilder) LightBluef

func (lb *LineBuilder) LightBluef(format string, args ...interface{}) *LineBuilder

LightBluef adds formatted light blue text segment

func (*LineBuilder) LightCyan

func (lb *LineBuilder) LightCyan(text string) *LineBuilder

LightCyan adds light cyan text segment

func (*LineBuilder) LightCyanf

func (lb *LineBuilder) LightCyanf(format string, args ...interface{}) *LineBuilder

LightCyanf adds formatted light cyan text segment

func (*LineBuilder) LightGray

func (lb *LineBuilder) LightGray(text string) *LineBuilder

LightGray adds light gray text segment

func (*LineBuilder) LightGrayf

func (lb *LineBuilder) LightGrayf(format string, args ...interface{}) *LineBuilder

LightGrayf adds formatted light gray text segment

func (*LineBuilder) LightGreen

func (lb *LineBuilder) LightGreen(text string) *LineBuilder

LightGreen adds light green text segment

func (*LineBuilder) LightGreenf

func (lb *LineBuilder) LightGreenf(format string, args ...interface{}) *LineBuilder

LightGreenf adds formatted light green text segment

func (*LineBuilder) LightRed

func (lb *LineBuilder) LightRed(text string) *LineBuilder

LightRed adds light red text segment

func (*LineBuilder) LightRedf

func (lb *LineBuilder) LightRedf(format string, args ...interface{}) *LineBuilder

LightRedf adds formatted light red text segment

func (*LineBuilder) Magenta

func (lb *LineBuilder) Magenta(text string) *LineBuilder

Magenta adds magenta text segment

func (*LineBuilder) Magentaf

func (lb *LineBuilder) Magentaf(format string, args ...interface{}) *LineBuilder

Magentaf adds formatted magenta text segment

func (*LineBuilder) NewLine

func (lb *LineBuilder) NewLine() *LineBuilder

NewLine commits the current line and starts a new blank line for spacing

func (*LineBuilder) QuoteEnd

func (lb *LineBuilder) QuoteEnd() *LineBuilder

QuoteEnd adds closing quotation mark with specified color

func (*LineBuilder) QuoteEndWithColor

func (lb *LineBuilder) QuoteEndWithColor(textColor color.Color) *LineBuilder

QuoteEndWithColor adds closing quotation mark with specified color

func (*LineBuilder) QuoteStart

func (lb *LineBuilder) QuoteStart() *LineBuilder

QuoteStart adds opening quotation mark with specified color

func (*LineBuilder) QuoteStartWithColor

func (lb *LineBuilder) QuoteStartWithColor(textColor color.Color) *LineBuilder

func (*LineBuilder) Red

func (lb *LineBuilder) Red(text string) *LineBuilder

Red adds red text segment

func (*LineBuilder) Redf

func (lb *LineBuilder) Redf(format string, args ...interface{}) *LineBuilder

Redf adds formatted red text segment

func (*LineBuilder) Runic

func (lb *LineBuilder) Runic(text string) *LineBuilder

Runic adds a runic text segment using the bitmap runic font. The text will be rendered using the runic font at a scale matching the TTF line height. Color is inherited from the previous segment, defaulting to EGABrown if no previous segment.

func (*LineBuilder) RunicWithColor

func (lb *LineBuilder) RunicWithColor(text string, textColor color.Color) *LineBuilder

RunicWithColor adds a runic text segment with a specific color. The text will be rendered using the bitmap runic font.

func (*LineBuilder) Runicf

func (lb *LineBuilder) Runicf(format string, args ...interface{}) *LineBuilder

Runicf adds a formatted runic text segment. Color is inherited from the previous segment, defaulting to EGABrown if no previous segment.

func (*LineBuilder) SetPlainTextCallback

func (lb *LineBuilder) SetPlainTextCallback(callback func(string))

SetPlainTextCallback sets an optional callback to receive plain text version of the line This enables dual output: colored text to primary output, plain text to callback destination

func (*LineBuilder) SlotIcon

func (lb *LineBuilder) SlotIcon(slot references.EquipmentSlot) *LineBuilder

SlotIcon adds a single runic character representing an equipment slot type. The icon is rendered using the runic bitmap font with the specified color. If no color is specified, uses the previous segment's color or defaults to EGABrown.

func (*LineBuilder) SlotIconWithColor

func (lb *LineBuilder) SlotIconWithColor(slot references.EquipmentSlot, textColor color.Color) *LineBuilder

SlotIconWithColor adds a single runic character representing an equipment slot type with a specific color.

func (*LineBuilder) Spoken

func (lb *LineBuilder) Spoken(text string) *LineBuilder

White adds white text segment

func (*LineBuilder) Spokenf

func (lb *LineBuilder) Spokenf(text string, args ...interface{}) *LineBuilder

White adds white text segment

func (*LineBuilder) Text

func (lb *LineBuilder) Text(text string, textColor color.Color) *LineBuilder

Text adds a text segment with specified color

func (*LineBuilder) Textf

func (lb *LineBuilder) Textf(format string, textColor color.Color, args ...interface{}) *LineBuilder

Textf adds a formatted text segment with specified color

func (*LineBuilder) White

func (lb *LineBuilder) White(text string) *LineBuilder

White adds white text segment

func (*LineBuilder) Whitef

func (lb *LineBuilder) Whitef(format string, args ...interface{}) *LineBuilder

Whitef adds formatted white text segment

func (*LineBuilder) WithAlignment

func (lb *LineBuilder) WithAlignment(alignment text.Align) *LineBuilder

WithAlignment sets the horizontal alignment for the line

func (*LineBuilder) WithContinuationIndent

func (lb *LineBuilder) WithContinuationIndent(columns int) *LineBuilder

WithContinuationIndent reserves columns before physical rows created by wrapping.

func (*LineBuilder) WordWrap

func (lb *LineBuilder) WordWrap() *LineBuilder

WordWrap is a self-documenting marker indicating the caller expects word wrapping. Note: AddStyledText already wraps text automatically at word boundaries using Output.maxCharsPerLine, so this method doesn't change runtime behavior. Use it to make intent explicit in calling code.

func (*LineBuilder) Yellow

func (lb *LineBuilder) Yellow(text string) *LineBuilder

Yellow adds yellow text segment

func (*LineBuilder) Yellowf

func (lb *LineBuilder) Yellowf(format string, args ...interface{}) *LineBuilder

Yellowf adds formatted yellow text segment

type Output

type Output struct {
	Font *UltimaFont
	// contains filtered or unexported fields
}

func NewOutput

func NewOutput(font *UltimaFont, lineSpacing float64, maxLines, maxCharsPerLine int) *Output

func (*Output) AddCommandPrompt

func (o *Output) AddCommandPrompt(command string)

AddCommandPrompt starts a line with the original one-cell bitmap input marker.

func (*Output) AddRowStrNoTrim deprecated

func (o *Output) AddRowStrNoTrim(outputStr string, bTrim bool)

Deprecated: AddRowStrNoTrim is deprecated. Use AddText() or AddTextRaw() instead. AddText() trims whitespace, AddTextRaw() preserves it.

func (*Output) AddStyledPrompt

func (o *Output) AddStyledPrompt(segments []ColorSegment, alignment text.Align)

AddStyledPrompt adds multi-color text for prompts (advances to next line after) Same as AddStyledText but semantically clearer for prompt use cases After writing the prompt, nextLineToIndex points to the next empty slot, allowing AppendText() to append user input to the prompt line

func (*Output) AddStyledText

func (o *Output) AddStyledText(segments []ColorSegment, alignment text.Align)

AddStyledText adds multi-color text with alignment and line advancement Use this for colored text segments (e.g., green prompts, white responses)

func (*Output) AddText

func (o *Output) AddText(text string)

AddText adds text to the output buffer with wrapping, trimming, and line advancement This is the primary method for adding single-color text output Automatically handles newlines, word wrapping, and advances nextLineToIndex

func (*Output) AddTextRaw

func (o *Output) AddTextRaw(text string)

AddTextRaw adds text without trimming whitespace Use this for conversation dialogs and other cases where leading/trailing whitespace is intentional

func (*Output) AddTextWithColor

func (o *Output) AddTextWithColor(text string, textColor color.Color)

AddTextWithColor adds text with a specific color, overriding the default Automatically handles wrapping and line advancement

func (*Output) AppendCommandHintOnce

func (o *Output) AppendCommandHintOnce(hint string)

AppendCommandHintOnce keeps guidance in the command's current append stream. Each new command prompt, including a retry, permits exactly one hint.

func (*Output) AppendLine

func (o *Output) AppendLine() *LineBuilder

AppendLine returns a LineBuilder for creating multi-colored lines

func (*Output) AppendStyledText

func (o *Output) AppendStyledText(addedSegments []ColorSegment)

AppendStyledText appends styled text at the end of the current output row. The caller owns deciding whether the source stream has a block boundary.

func (*Output) AppendText

func (o *Output) AppendText(text string)

AppendText appends text to the current line WITHOUT advancing nextLineToIndex Use this to add user input after a prompt on the same line Call AddText("\n") afterward to advance to the next line

func (*Output) Clear

func (o *Output) Clear()

func (*Output) DrawPanelContent

func (o *Output) DrawPanelContent(screen *ebiten.Image, point image.Point, textRectWidth int, horizAlign text.Align)

DrawPanelContent renders text using PHYSICAL indices (no circular buffer logic). Use this for fresh panel content that should always start at the top of the panel. Unlike DrawScrollingBuffer which uses circular buffer indexing for scrolling message buffers, this method renders content from physical index 0 upward.

Typical usage pattern:

output.Reset()  // Clear and reset index to 0
output.AppendLine().Yellow("Title").Done()
output.AppendLine().White("Content").Done()
output.DrawPanelContent(screen, point, width, horizAlign)

func (*Output) DrawPanelContentRange

func (o *Output) DrawPanelContentRange(
	screen *ebiten.Image,
	point image.Point,
	textRectWidth int,
	horizAlign text.Align,
	startLine int,
	lineCount int,
)

DrawPanelContentRange renders a bounded physical line range from fresh panel content. It is intended for capacity-based paging after Reset and AppendLine population.

func (*Output) DrawScrollingBuffer

func (o *Output) DrawScrollingBuffer(screen *ebiten.Image, point image.Point, textRectWidth int, bShowEmptyNewLines bool, horizAlign, vertAlign text.Align)

func (*Output) DrawScrollingBufferWithHeight

func (o *Output) DrawScrollingBufferWithHeight(screen *ebiten.Image, point image.Point, textRectWidth, textRectHeight int, bShowEmptyNewLines bool, horizAlign, vertAlign text.Align)

DrawScrollingBufferWithHeight renders text with optional bottom-up alignment If textRectHeight > 0 and vertAlign == AlignEnd, text is positioned from bottom and grows upward Trailing empty/whitespace-only lines are skipped during rendering (not deleted from buffer) Buffer naturally overwrites old lines via circular indexing when new content is added

func (*Output) DrawText

func (o *Output) DrawText(screen *ebiten.Image, textStr string, op *ebiten.DrawImageOptions)

func (*Output) DrawTextCenter

func (o *Output) DrawTextCenter(screen *ebiten.Image, textStr string, op *ebiten.DrawImageOptions)

func (*Output) DrawTextRightToLeft

func (o *Output) DrawTextRightToLeft(screen *ebiten.Image, textStr string, op *ebiten.DrawImageOptions)

func (*Output) EnableJournalHistory

func (o *Output) EnableJournalHistory()

EnableJournalHistory opts this output into plain main-rail retention. Existing wrapped rows are deliberately not imported as logical messages.

func (*Output) FirstPanelLineWithColor

func (o *Output) FirstPanelLineWithColor(start, end int, target color.Color) (int, bool)

FirstPanelLineWithColor locates highlighted text after physical wrapping. This lets a reader reveal the actual rendered match instead of estimating its page.

func (*Output) GetFontHeight

func (o *Output) GetFontHeight() float64

GetFontHeight returns the actual font height in pixels (ascent + descent). This represents the height of rendered glyphs, not including line gap.

func (*Output) GetLengthOfCurrentRowStr

func (o *Output) GetLengthOfCurrentRowStr() int

func (*Output) GetLineCapacity

func (o *Output) GetLineCapacity(height int) int

GetLineCapacity returns the greatest number of complete lines that fit in height.

func (*Output) GetLineSpacing

func (o *Output) GetLineSpacing() float64

GetLineSpacing returns the line spacing (baseline-to-baseline distance) used for this output. This is the value passed to NewOutput or SetFont.

func (*Output) GetOutputStr

func (o *Output) GetOutputStr(bShowEmptyNewLines bool) string

func (*Output) GetPanelContentLineCount

func (o *Output) GetPanelContentLineCount() int

GetPanelContentLineCount returns the physical row count used by DrawPanelContent.

func (*Output) GetTotalHeightForLines

func (o *Output) GetTotalHeightForLines(n int) float64

GetTotalHeightForLines calculates the total height for N lines of text. Formula: (N-1) × lineSpacing + fontHeight This accounts for N-1 gaps between baselines plus the actual text height.

func (*Output) GetVisibleScrollingLineCount

func (o *Output) GetVisibleScrollingLineCount(textRectHeight int) int

GetVisibleScrollingLineCount returns the rows rendered by DrawScrollingBufferWithHeight.

func (*Output) JournalHistory

func (o *Output) JournalHistory() string

JournalHistory returns a detached canonical snapshot, without unfinished blank padding.

func (*Output) MeasureLineSegments

func (o *Output) MeasureLineSegments(segments []ColorSegment) float64

MeasureLineSegments uses the renderer's font, scale and bitmap-glyph advances. Use it to budget a single mixed text/icon row before committing its Output line.

func (*Output) RecolorCurrentLine

func (o *Output) RecolorCurrentLine(lineColor color.Color)

RecolorCurrentLine applies one color to all content on the current line. TextInput uses this for syntax coloring after its editable text has been represented as styled segments.

func (*Output) ReflowRetained

func (o *Output) ReflowRetained(font *UltimaFont, spacing float64, chars int)

ReflowRetained rebuilds the live buffer with new typography, preserving source boundaries, colours and Runic segments. No engine or action is invoked.

func (*Output) RemoveRightSideCharacter

func (o *Output) RemoveRightSideCharacter()

func (*Output) Reset

func (o *Output) Reset()

Reset clears all content AND resets the line index to 0 Use this when starting fresh content that should render from the top

func (*Output) RestoreJournalHistory

func (o *Output) RestoreJournalHistory(history string) error

RestoreJournalHistory validates before replacing either projection. Disabled outputs remain disabled; restoration never enables modal transcript capture.

func (*Output) RetainLogicalHistory

func (o *Output) RetainLogicalHistory(maxEntries, maxBytes int)

RetainLogicalHistory starts bounded retention for subsequent insertions.

func (*Output) RetainedHistoryPanel

func (o *Output) RetainedHistoryPanel() *Output

RetainedHistoryPanel produces chronological physical rows for keyboard paging. The conservative row bound includes explicit newlines and one-glyph wrapping.

func (*Output) SetColor

func (o *Output) SetColor(color color.Color)

func (*Output) SetDebugOptions

func (o *Output) SetDebugOptions(debugOptions *references.DebugOptions)

SetDebugOptions sets the debug options for rendering placeholders Pass nil to disable debug features

func (*Output) SetFont

func (o *Output) SetFont(font *UltimaFont, lineSpacing float64)

func (*Output) SetHyphenateLongWords

func (o *Output) SetHyphenateLongWords(enabled bool)

SetHyphenateLongWords controls whether wrapping adds a visual hyphen when an uninterrupted token crosses the configured character width.

func (*Output) SetMaxCharsPerLine

func (o *Output) SetMaxCharsPerLine(maxCharsPerLine int)

SetMaxCharsPerLine updates the word-wrapping width for subsequently appended text.

func (*Output) WrappedCopy

func (o *Output) WrappedCopy(maxCharsPerLine int) *Output

WrappedCopy rewraps retained rows in chronological order without changing o. Empty edge rows are omitted; interior blank rows and original row boundaries are preserved. Re-layout should always copy the retained source, not a prior wrapped copy, because original rows are never joined when widening.

func (*Output) WrappedCopyForWidth

func (o *Output) WrappedCopyForWidth(pixelWidth int) *Output

WrappedCopyForWidth uses the widest retained glyph (at least a normal M) to choose a conservative character capacity, then delegates to WrappedCopy. A single glyph wider than pixelWidth is retained on its own row.

type OutputHistory

type OutputHistory struct {
	// contains filtered or unexported fields
}

OutputHistory retains only already-inserted logical text, not wrapped rows or gameplay callbacks. It is opt-in and owned by one transient presentation.

type SignRenderResult

type SignRenderResult struct {
	Image  *ebiten.Image
	Width  int
	Height int

	// TranslationRows is the semantic inscription from the same parsed cells
	// used to draw a translated sign, without its decorative-only rows.
	TranslationRows [][]ColorSegment
}

SignRenderResult contains the rendered sign image and metadata.

type SignRenderer

type SignRenderer struct {
	// contains filtered or unexported fields
}

SignRenderer renders sign text using bitmap fonts with runic/normal character support.

func NewSignRenderer

func NewSignRenderer(scale float64) *SignRenderer

NewSignRenderer creates a renderer for the responsive warm sign treatment. Scale determines the size multiplier for the 8x8 pixel characters.

func (*SignRenderer) CalculateSignDimensions

func (sr *SignRenderer) CalculateSignDimensions(rawText []byte) (width, height int)

CalculateSignDimensions returns the dimensions a sign would have without rendering.

func (*SignRenderer) CreateTestImage

func (sr *SignRenderer) CreateTestImage(text string) *ebiten.Image

CreateTestImage creates a test image with sample text for debugging.

func (*SignRenderer) GetCharacterDimensions

func (sr *SignRenderer) GetCharacterDimensions() (width, height float64)

GetCharacterDimensions returns the scaled character dimensions.

func (*SignRenderer) RenderSign

func (sr *SignRenderer) RenderSign(rawText []byte) *SignRenderResult

RenderSign renders the raw sign text to an image. Handles runic/normal font switching, border macros, and line breaks.

func (*SignRenderer) RenderSignRecord

func (sr *SignRenderer) RenderSignRecord(sign *references.SignRecord) *SignRenderResult

RenderSignRecord renders a SignRecord to an image.

func (*SignRenderer) RenderTranslatedSign

func (sr *SignRenderer) RenderTranslatedSign(rawText []byte) *SignRenderResult

RenderTranslatedSign replaces only understood runic lettering in the source artwork. The original cells still determine every row and the image bounds.

type StyledLine

type StyledLine struct {
	Segments  []ColorSegment // Non-empty for multi-color lines
	Text      string         // Used for simple single-color lines
	Color     color.Color    // Default color for simple lines
	Alignment text.Align     // Horizontal alignment (default: AlignStart for left-aligned)
}

StyledLine holds either a simple single-color line or multi-color segments

type TextCache

type TextCache struct {
	// contains filtered or unexported fields
}

TextCache manages cached rendered text images with LRU eviction This cache is designed to be reusable for other graphics (tiles, sprites) in the future

func NewTextCache

func NewTextCache(maxEntries int) *TextCache

NewTextCache creates a new cache with specified maximum entries

func NewTextCacheWithBudget

func NewTextCacheWithBudget(maxEntries, maxBytes int) *TextCache

NewTextCacheWithBudget bounds entries and accounted bytes, not total GPU memory.

func (*TextCache) Clear

func (tc *TextCache) Clear()

Clear removes all entries from the cache

func (*TextCache) GetOrRender

func (tc *TextCache) GetOrRender(params TextRenderParams) *ebiten.Image

GetOrRender returns cached image or renders new one, updating LRU order

func (*TextCache) Size

func (tc *TextCache) Size() int

Size returns the current number of cached entries (useful for testing/debugging)

type TextMeasurement

type TextMeasurement struct {
	Lines        int     // Number of lines (after wrapping/newlines)
	MaxLineWidth float64 // Width of longest line in pixels
	MaxLineChars int     // Character count of longest line
	TotalHeight  float64 // Total height including line spacing
}

TextMeasurement holds the measured dimensions of text content

func MeasureText

func MeasureText(text string, font *UltimaFont, lineSpacing float64, maxCharsPerLine int) TextMeasurement

MeasureText analyzes text content and returns dimension requirements. If maxCharsPerLine > 0, text will be wrapped at word boundaries. If maxCharsPerLine == 0, no wrapping is applied (only explicit newlines).

func MeasureTextUnwrapped

func MeasureTextUnwrapped(text string, font *UltimaFont, lineSpacing float64) TextMeasurement

MeasureTextUnwrapped measures text without any wrapping. Only explicit newlines create new lines.

type TextRenderParams

type TextRenderParams struct {
	Content string
	Face    text.Face
	Options *text.LayoutOptions
	Color   color.Color
}

TextRenderParams represents parameters for text rendering that can be cached

func (TextRenderParams) CacheKey

func (t TextRenderParams) CacheKey() CacheKey

CacheKey uses numeric colours and value layout options without formatting. Faces must keep opaque feature/variation settings immutable while cached; replace the face or ClearTextCache after changing those engine-private settings.

type UltimaFont

type UltimaFont struct {
	TextFace *text.GoTextFace
	// contains filtered or unexported fields
}

func NewUltimaFont

func NewUltimaFont(size float64) *UltimaFont

func (*UltimaFont) CharsForWidth

func (f *UltimaFont) CharsForWidth(pixelWidth int) int

CharsForWidth calculates how many characters fit in a given pixel width. Uses 'M' as the reference character (em-width) for conservative estimation. Returns a minimum of 10 to prevent pathological edge cases.

func (*UltimaFont) DrawIntroChoices

func (f *UltimaFont) DrawIntroChoices(screen *ebiten.Image, nSelection int, enabledChoices []bool)

DrawIntroChoices renders the intro menu with selected and disabled choice states.

func (*UltimaFont) MeasureString

func (f *UltimaFont) MeasureString(str string) (width, height float64)

MeasureString returns the width and height of the given text string in pixels. This is a convenience wrapper around text.Measure for use in dialog sizing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL