Class TextCanvas
TextCanvas extends TexturedRectangle and renders a 2D grid of
characters (rows and columns) onto a texture-mapped rectangle. Each character cell
supports independent foreground and background colors.
Characters are rendered using a monospace font at a fixed cell size
(16 x 32
texture pixels per character). The texture is a signed distance field (SDF):
the mask stores per-texel distance to the nearest glyph edge (generated once
per character by SdfGlyphCache and stamped per cell), while the
primary bitmap and a separate foreground layer carry the cell colors. The
rasterizer re-derives glyph edges per screen pixel from the distance field,
so text stays sharp at any zoom and any angle from a single render path.
Usage example
Transform location = new Transform(new Point3D(0, 0, 500));
TextCanvas canvas = new TextCanvas(location, "Hello, World!",
Color.WHITE, Color.BLACK);
shapeCollection.addShape(canvas);
// Or create a blank canvas and write to it
TextCanvas blank = new TextCanvas(location, new TextPointer(10, 40),
Color.GREEN, Color.BLACK);
blank.locate(0, 0);
blank.print("Line 1");
blank.locate(1, 0);
blank.print("Line 2");
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFont character height in world coordinates.static final intFont character height in texture pixels.static final intFont character width in world coordinates.static final intFont character width in texture pixels.Fields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.TexturedRectangle
bottomLeft, bottomRight, textureBottomLeft, textureBottomRight, textureTopLeft, textureTopRight, topLeft, topRightFields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
cachedBoundingBox, mouseInteractionController -
Constructor Summary
ConstructorsConstructorDescriptionTextCanvas(Transform location, TextPointer dimensions, Color foregroundColor, Color backgroundColor) Creates a blank text canvas with the specified dimensions.TextCanvas(Transform location, String text, Color foregroundColor, Color backgroundColor) Creates a text canvas initialized with the given text string. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the entire canvas, resetting all characters to spaces with the default colors.getSize()Returns the dimensions of this text canvas.static TextPointergetTextDimensions(String text) Computes the row and column dimensions needed to fit the given text.voidlocate(int row, int column) Moves the internal cursor to the specified row and column.voidPrints a string starting at the current cursor location, advancing the cursor after each character.voidputChar(char character) Writes a character at the current cursor location and advances the cursor.voidputChar(int row, int column, char character) Writes a character at the specified row and column using the current foreground and background colors.voidputChar(TextPointer location, char character) Writes a character at the position specified by aTextPointer.voidsetBackgroundColor(Color backgroundColor) Sets the default background color for subsequent character writes.voidsetForegroundColor(Color foregroundColor) Sets the default foreground (text) color for subsequent character writes.voidReplaces the entire canvas content with the given multi-line text string.voidsetTextColor(Color color) Sets the foreground color of the whole canvas.Methods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.TexturedRectangle
getTexture, initializeMethods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape
addShape, addShape, beforeTransformHook, collectRenderTriangles, extractSolidPolygons, getBoundingBox, getGlobalRenderListVersion, getGroup, getLocation, getSubShapesRegistry, getTransform, getTransformWeight, getViewSpaceTracker, hideGroup, intersect, postprocessRenderList, removeGroup, setBackfaceCulling, setCacheNeedsRebuild, setColor, setGroupForUngrouped, setMouseInteractionController, setRootComposite, setShadingEnabled, setTransform, showGroup, subtract, transform, unionMethods inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
invalidateBounds
-
Field Details
-
FONT_CHAR_WIDTH
public static final int FONT_CHAR_WIDTHFont character width in world coordinates.- See Also:
-
FONT_CHAR_HEIGHT
public static final int FONT_CHAR_HEIGHTFont character height in world coordinates.- See Also:
-
FONT_CHAR_WIDTH_TEXTURE_PIXELS
public static final int FONT_CHAR_WIDTH_TEXTURE_PIXELSFont character width in texture pixels.- See Also:
-
FONT_CHAR_HEIGHT_TEXTURE_PIXELS
public static final int FONT_CHAR_HEIGHT_TEXTURE_PIXELSFont character height in texture pixels.- See Also:
-
-
Constructor Details
-
TextCanvas
Creates a text canvas initialized with the given text string.The canvas dimensions are automatically computed from the text content (number of lines determines rows, the longest line determines columns).
- Parameters:
location- the 3D transform positioning this canvas in the scenetext- the initial text content (may contain newlines for multiple rows)foregroundColor- the default text colorbackgroundColor- the default background color
-
TextCanvas
public TextCanvas(Transform location, TextPointer dimensions, Color foregroundColor, Color backgroundColor) Creates a blank text canvas with the specified dimensions.The canvas is initialized with spaces in every cell, filled with the specified background color. Characters can be written using
putChar(char),print(String), orsetText(String).- Parameters:
location- the 3D transform positioning this canvas in the scenedimensions- the grid size as aTextPointerwhererowis the number of rows andcolumnis the number of columnsforegroundColor- the default text colorbackgroundColor- the default background color
-
-
Method Details
-
getTextDimensions
Computes the row and column dimensions needed to fit the given text.- Parameters:
text- the text content (may contain newlines)- Returns:
- a
TextPointerwhererowis the number of lines andcolumnis the length of the longest line
-
clear
public void clear()Clears the entire canvas, resetting all characters to spaces with the default colors.The SDF mask and both color layers are reset.
-
getSize
Returns the dimensions of this text canvas.- Returns:
- a
TextPointerwhererowis the number of rows andcolumnis the number of columns
-
locate
public void locate(int row, int column) Moves the internal cursor to the specified row and column.Subsequent calls to
putChar(char)andprint(String)will begin writing at this position.- Parameters:
row- the target row (0-based)column- the target column (0-based)
-
print
Prints a string starting at the current cursor location, advancing the cursor after each character.When the cursor reaches the end of a row, it wraps to the beginning of the next row.
- Parameters:
text- the text to print- See Also:
-
putChar
public void putChar(char character) Writes a character at the current cursor location and advances the cursor.The cursor moves one column to the right. If it exceeds the row width, it wraps to column 0 of the next row.
- Parameters:
character- the character to write
-
putChar
public void putChar(int row, int column, char character) Writes a character at the specified row and column using the current foreground and background colors.If the row or column is out of bounds, the call is silently ignored.
- Parameters:
row- the row index (0-based)column- the column index (0-based)character- the character to write
-
putChar
Writes a character at the position specified by aTextPointer.- Parameters:
location- the row and column positioncharacter- the character to write
-
setBackgroundColor
Sets the default background color for subsequent character writes.- Parameters:
backgroundColor- the new background color
-
setForegroundColor
Sets the default foreground (text) color for subsequent character writes.- Parameters:
foregroundColor- the new foreground color
-
setText
Replaces the entire canvas content with the given multi-line text string.Each line of text (separated by newlines) is written to consecutive rows, starting from row 0. Characters beyond the canvas width are ignored.
- Parameters:
text- the text to display (may contain newline characters)
-
setTextColor
Sets the foreground color of the whole canvas.Fills the SDF ink color layer; cell shapes are untouched, so text content and background colors are preserved.
- Parameters:
color- the new foreground color
-