Sprites.Media.Text

The text screen editor and its model. A text screen is a grid of character cells drawn from one font, each cell coloured by an ink and a paper attribute. Its data is { platform, mode, w, h, first, character, ink, paper, special }, where character, ink, paper and special are four flat lists, one integer to a cell, packed in row order. A character cell holds the glyph index into the font, or undefined for a blank cell. An ink or paper cell holds a colour, or undefined for the default. There are two attribute models: a per cell machine gives each cell its own ink and paper, and an inline machine, wholeCell true, lets an attribute take a whole cell and hold along the row until another overrides it. The editor reuses the shared pixel parts under Sprites.Media.Sprite for the canvas, the pan and zoom, the move, file and history windows and the info window, and the font editor's Characters window for the glyph palette; only the model, the Tools window and the character palette are text specific.

Sprites.Media.Text

Sprites.Media.Text.Atlas Array

Sprites.Media.Text.Atlas(font)

The atlas of a font: a list of glyphs, each a flat one bit cell list of the font's cell size, in charset order. Grid.Two.Tile places a glyph by its index, so the atlas is the tile set a character screen draws from. A boot helper over DecodeGlyph, plain data built once as the editor opens.

InputTypeDescription
fontObjectA charset, { name, w, h, first, glyphs }, each glyph one byte per row.

Returns a plain list of glyph cell lists, one per character.

Sprites.Media.Text.Blank Undefined

The blank cell of a character list: an absent value, undefined. A blank cell shows the paper colour and no glyph, and a fresh inline screen starts every cell blank.

undefined

Sprites.Media.Text.BlankDocument Object

Sprites.Media.Text.BlankDocument(platform, mode, first, w, h)

A new blank text document: every character, ink, paper and special cell undefined, so an inline screen opens clear and reads the default colours. A boot factory a page hands to the store, plain data rather than a live reactive.

InputTypeDescription
platformStringThe machine id to stamp on the document.
modeStringThe mode name to stamp on the document.
firstNumberThe code point of the font's first glyph.
wNumberThe screen width in characters.
hNumberThe screen height in characters.

Returns a plain { platform, mode, w, h, first, character, ink, paper, special } document.

Sprites.Media.Text.CellIndex Value

Sprites.Media.Text.CellIndex(w, x, y)

The flat index of a cell from its column and row, on a screen of a given width: row times width plus column. A composite over Sprites.Maths, for a handler that lays one cell.

InputTypeDescription
wNumberThe screen width in characters.
xNumberThe cell column.
yNumberThe cell row.

Returns a reactive number, the cell's index in a flat list.

Sprites.Media.Text.CharObjects Array

Sprites.Media.Text.CharObjects(atlas)

A list of plain character objects for the character palette: each glyph of the font as a { pixels } of its decoded one bit cells, in charset order. The font editor's characters window reads this list to draw the glyphs the char tool picks from. A boot helper over the atlas, plain data built once as the editor opens.

InputTypeDescription
atlasArrayThe font atlas, a list of glyph cell lists.

Returns a plain list of { pixels } glyph objects.

Sprites.Media.Text.Colourise Value

Sprites.Media.Text.Colourise(colours, indexed, slots)

A colour grid resolved to packed RGBA: each cell mapped through the slots for an indexed machine, or kept as it stands for a free one. A composite over Sprites.Array.Lookup, one node over the whole array, so a slot index becomes its colour while a packed colour passes through, and only the cells whose colour changed pass it on. indexed chooses the path.

InputTypeDescription
coloursValueA { w, h, cells } grid of colour values, slot indices or packed colours.
indexedBooleanTrue to read a cell as a slot index, false to read it as a packed colour.
slotsArrayThe machine's colours as packed 0xRRGGBBAA integers.

Returns a reactive { w, h, cells } grid of packed colours.

Sprites.Media.Text.DecodeGlyph Array

Sprites.Media.Text.DecodeGlyph(bytes, w, h)

One glyph decoded from a machine charset row list to a flat one bit cell list: for each row a byte, top row first, the leftmost pixel the top bit, a set bit one and a clear bit zero. A boot helper: it reads the raw bytes to build the atlas the screen tiles from.

InputTypeDescription
bytesArrayOne byte per pixel row, top row first.
wNumberThe glyph cell width.
hNumberThe glyph cell height.

Returns a plain list of w times h one bit cells.

Sprites.Media.Text.DefaultInk Number

The default ink of a fresh screen when the machine names none: white, as a packed RGBA integer, each byte a channel. A machine pack overrides it with its own colour.

0xFFFFFFFF

Sprites.Media.Text.DefaultPaper Number

The default paper of a fresh screen when the machine names none: black, as a packed RGBA integer, each byte a channel. A machine pack overrides it with its own colour.

0x000000FF

Sprites.Media.Text.Editor Void

Sprites.Media.Text.Editor(data, thumb, info, font, charWidth, charHeight, optionalModes, optionalModeName, optionalSlots, wholeCell, optionalDefaultInk, optionalDefaultPaper)

The text screen editor. Builds the screen view on the host, the pan and zoom overlay, the Tools window, the ink and paper palette windows, the file, history and characters panels, and the info window. It edits one screen, laying characters and attributes into the cells. It reuses the shared pixel parts under Sprites.Media.Sprite and the font editor's characters window, so a screen drives them the way a sprite drives the canvas. It builds interface and returns nothing; the doc fields it is given are where the edits land.

InputTypeDescription
dataValueThe doc's screen data, a two way { platform, mode, w, h, first, character, ink, paper, special }.
thumbValueA value the editor Sets to a fresh PNG data URL of the screen on every edit.
infoValueA value the editor Sets to a short mode and size summary on every edit. See Summary.
fontObjectThe character set, { name, w, h, first, glyphs }, the glyphs the screen draws from.
charWidthNumberThe character cell width in pixels.
charHeightNumberThe character cell height in pixels.
optionalModesArrayThe machine's text modes, each { name, pixelAspect, allowedWidths, allowedHeights }. Left out, one free-size mode is used.
optionalModeNameValueA two way value of the current mode's name, the doc's stored mode.
optionalSlotsArrayThe machine's colours as packed 0xRRGGBBAA integers, which makes the editor indexed: a cell holds a colour's index. Left out, a cell holds a packed colour.
wholeCellBooleanTrue when an attribute takes a whole cell and holds along the row, the inline model; false for a per cell attribute.
optionalDefaultInkNumberThe ink a cell shows with no attribute, a colour index or a packed colour.
optionalDefaultPaperNumberThe paper a cell shows with no attribute.

Returns nothing.

Sprites.Media.Text.EffectiveColour Value

Sprites.Media.Text.EffectiveColour(colours, wholeCell, fallback)

The resolved colour of every cell after the attribute model. For an inline machine, wholeCell true, each cell takes the nearest set value to its left, or the fallback; for a per cell machine each cell takes its own value, or the fallback when absent. A composite over Grid.Two.FillAcross, Grid.Two.Default and Sprites.Logic.Select, each one node over the whole array.

InputTypeDescription
coloursValueA { w, h, cells } grid of a cell's own colour, or undefined for the default.
wholeCellBooleanTrue for the inline look-left model, false for the per cell model.
fallbackNumberThe default colour a cell with no attribute shows.

Returns a reactive { w, h, cells } grid of the resolved colour of every cell.

Sprites.Media.Text.NewDocument Object

Sprites.Media.Text.NewDocument(platform, mode, font, w, h)

A new text document seeded to spaces: every character cell the space glyph, every ink, paper and special cell undefined, so a per cell screen opens on the machine's blank screen at the default colours. A boot factory, plain data for the store.

InputTypeDescription
platformStringThe machine id to stamp on the document.
modeStringThe mode name to stamp on the document.
fontObjectThe charset, read for its first code point.
wNumberThe screen width in characters.
hNumberThe screen height in characters.

Returns a plain text document seeded to spaces.

Sprites.Media.Text.PaintChar Value

Sprites.Media.Text.PaintChar(data, w, h, col, row, brush, wholeCell)

The screen with one character cell set to a glyph index, at a column and a row. When wholeCell is true a character and an attribute are exclusive in a cell, so laying a character clears the ink, paper and special of that cell; otherwise only the character changes. A composite over SetCell, Object.With and Sprites.Logic.Select, for the char tool.

InputTypeDescription
dataValueThe two way screen data.
wNumberThe screen width in characters.
hNumberThe screen height in characters.
colNumberThe cell column.
rowNumberThe cell row.
brushNumberThe glyph index to lay.
wholeCellBooleanTrue to clear the cell's attribute as the character is laid, the inline model.

Returns a reactive screen-data value with the one cell changed.

Sprites.Media.Text.PaintInk Value

Sprites.Media.Text.PaintInk(data, w, h, col, row, brush, wholeCell)

The screen with one cell's ink set to a colour, at a column and a row. When wholeCell is true the cell carries an attribute alone, so the character, paper and special of that cell clear; otherwise only the ink changes. A composite over SetCell, Object.With and Sprites.Logic.Select, for the ink tool.

InputTypeDescription
dataValueThe two way screen data.
wNumberThe screen width in characters.
hNumberThe screen height in characters.
colNumberThe cell column.
rowNumberThe cell row.
brushNumberThe ink colour to lay.
wholeCellBooleanTrue to clear the rest of the cell, the inline model.

Returns a reactive screen-data value with the one cell changed.

Sprites.Media.Text.PaintPaper Value

Sprites.Media.Text.PaintPaper(data, w, h, col, row, brush, wholeCell)

The screen with one cell's paper set to a colour, at a column and a row. When wholeCell is true the cell carries an attribute alone, so the character, ink and special of that cell clear; otherwise only the paper changes. A composite over SetCell, Object.With and Sprites.Logic.Select, for the paper tool.

InputTypeDescription
dataValueThe two way screen data.
wNumberThe screen width in characters.
hNumberThe screen height in characters.
colNumberThe cell column.
rowNumberThe cell row.
brushNumberThe paper colour to lay.
wholeCellBooleanTrue to clear the rest of the cell, the inline model.

Returns a reactive screen-data value with the one cell changed.

Sprites.Media.Text.RenderData Value

Sprites.Media.Text.RenderData(data, atlas, charWidth, charHeight, indexed, slots, wholeCell, defaultInk, defaultPaper)

The whole screen of a document drawn to packed RGBA pixels: it reads the four lists and the size, resolves the ink and paper by the attribute model, and tiles the glyphs coloured by them. A composite over EffectiveColour and ScreenPixels, the value the canvas and the thumbnail read. It takes the document, so it serves the live screen and a freshly painted candidate alike.

InputTypeDescription
dataValueThe screen data.
atlasArrayThe font atlas, the glyph tiles.
charWidthNumberThe character cell width in pixels.
charHeightNumberThe character cell height in pixels.
indexedBooleanTrue to read a colour cell as a slot index.
slotsArrayThe machine's colours as packed integers.
wholeCellBooleanThe attribute model, inline or per cell.
defaultInkNumberThe default ink.
defaultPaperNumberThe default paper.

Returns a reactive { w, h, cells } grid of packed pixels.

Sprites.Media.Text.ResizeAll Value

Sprites.Media.Text.ResizeAll(data, width, height)

The same screen resized to a new width and height in characters, cropping or padding every one of the four lists with the blank cell, undefined. A composite over Grid.Two.Resize and ReadOnly, keeping the platform, mode and first code point.

InputTypeDescription
dataValueThe two way screen data.
widthNumberThe new screen width in characters.
heightNumberThe new screen height in characters.

Returns a reactive screen-data value at the new size.

Sprites.Media.Text.ResizeList Value

Sprites.Media.Text.ResizeList(data, key, oldW, oldH, width, height)

One field of the document resized to a new width and height, cropping or padding with the blank cell. A composite over Grid.Two.Resize, shared by the four lists in ResizeAll.

InputTypeDescription
dataValueThe screen data.
keyStringThe list field, one of character, ink, paper, special.
oldWNumberThe current screen width.
oldHNumberThe current screen height.
widthNumberThe new screen width.
heightNumberThe new screen height.

Returns a reactive list at the new size.

Sprites.Media.Text.ScreenPixels Value

Sprites.Media.Text.ScreenPixels(characters, effectiveInk, effectivePaper, atlas, charWidth, charHeight, indexed, slots)

The whole screen drawn to packed RGBA pixels: every cell's glyph stamped from the atlas, its set pixels the resolved ink and its clear pixels the resolved paper. A composite: it tiles the glyph mask with Grid.Two.Tile, resolves and stretches the ink and paper to pixel size with Colourise and Grid.Two.Stretch, and picks ink or paper per pixel with Grid.Two.Choose.

InputTypeDescription
charactersValueA { w, h, cells } grid of glyph indices.
effectiveInkValueA grid of the resolved ink of every cell.
effectivePaperValueA grid of the resolved paper of every cell.
atlasArrayThe font atlas, the glyph tiles.
charWidthNumberThe character cell width in pixels.
charHeightNumberThe character cell height in pixels.
indexedBooleanTrue to read a colour cell as a slot index.
slotsArrayThe machine's colours as packed integers.

Returns a reactive { w, h, cells } grid of packed pixels, w times charWidth by h times charHeight.

Sprites.Media.Text.SetCell Value

Sprites.Media.Text.SetCell(cells, w, h, col, row, value)

One flat cell list with a single cell set to a value, at a column and a row on a screen of a width and a height. A composite over Grid.Two.Set, which clips a cell outside the screen, so an out of bounds paint changes nothing.

InputTypeDescription
cellsValueThe flat cell list.
wNumberThe screen width in characters.
hNumberThe screen height in characters.
colNumberThe cell column.
rowNumberThe cell row.
valueNumberThe value to lay, a colour, a character index, or undefined to clear.

Returns a reactive cell list with the one cell changed.

Sprites.Media.Text.Space Number

The code point of the space character, the first printable character. A new screen seeds every cell to the space glyph, so it opens on the machine's blank screen.

32

Sprites.Media.Text.Summary String

Sprites.Media.Text.Summary(modeName, w, h)

The meta info summary for a text screen: its mode and screen size as one short string, for the meta record a listing reads. A composite over Sprites.Text.Concat and Sprites.Logic.Select, dropping the mode when there is none.

InputTypeDescription
modeNameValueThe current mode's name, or absent.
wNumberThe screen width in characters.
hNumberThe screen height in characters.

Returns a reactive summary string, for example Standard · 32×24.

Sprites.Media.Text.CellImage Void

Sprites.Media.Text.CellImage(index, characterCells, inkCells, paperCells, atlas, blankGlyph, charWidth, charHeight, width)

One character cell drawn as an image: the glyph at the cell coloured by the cell's resolved ink and paper, placed as a PNG in the surface with Sprites.Image.Draw.Image. So a whole character is one image element, not a square per pixel. A blank cell, an absent character index, shows the paper alone. A composite over Sprites.Array.Choose and Sprites.Image.Draw.Image.

InputTypeDescription
indexNumberThe cell's flat index.
characterCellsValueThe glyph index of every cell.
inkCellsValueThe resolved ink colour of every cell, packed.
paperCellsValueThe resolved paper colour of every cell, packed.
atlasValueThe font atlas, the glyph tiles.
blankGlyphValueThe blank glyph an absent character shows.
charWidthNumberThe character cell width in pixels.
charHeightNumberThe character cell height in pixels.
widthNumberThe screen width in characters.

Returns nothing.

Sprites.Media.Text.CellImages Void

Sprites.Media.Text.CellImages(characterCells, inkCells, paperCells, atlas, blankGlyph, charWidth, charHeight, width, count)

The cell images: one image per character cell, built with Repeat over the cell count, so a resize rebuilds the set and each cell follows its own character, ink and paper. A composite over CellImage.

InputTypeDescription
characterCellsValueThe glyph index of every cell.
inkCellsValueThe resolved ink colour of every cell.
paperCellsValueThe resolved paper colour of every cell.
atlasValueThe font atlas.
blankGlyphValueThe blank glyph an absent character shows.
charWidthNumberThe character cell width in pixels.
charHeightNumberThe character cell height in pixels.
widthNumberThe screen width in characters.
countNumberThe cell count, width times height.

Returns nothing.

Sprites.Media.Text.GridColour String

The colour of the grid on the character cells, a faint black.

'rgba(0, 0, 0, 0.35)'

Sprites.Media.Text.GridLineWidth Number

The width of the grid lines, in world units, where one unit is one pixel of a character. The grid falls on the character cells, not the pixels.

0.4

Sprites.Media.Text.OutlineColour String

The colour of the outline around the whole screen, a dark green.

'#020d02'

Sprites.Media.Text.OutlineWidth Number

The width of the outline around the whole screen, in world units.

0.7

Sprites.Media.Text.View Void

Sprites.Media.Text.View(characterCells, inkCells, paperCells, atlas, blankGlyph, charWidth, charHeight, width, height, pan, show)

The screen view: a checkerboard backdrop, then a Vector over it with one image per character cell, a grid on the character cells, and a dark outline around the screen. One world unit is one pixel of a character, so a cell spans charWidth by charHeight units. A composite over CellImages, Sprites.Image.Draw.Grid and Sprites.Image.Draw.Rectangle.

InputTypeDescription
characterCellsValueThe glyph index of every cell.
inkCellsValueThe resolved ink colour of every cell.
paperCellsValueThe resolved paper colour of every cell.
atlasValueThe font atlas.
blankGlyphValueThe blank glyph an absent character shows.
charWidthNumberThe character cell width in pixels.
charHeightNumberThe character cell height in pixels.
widthNumberThe screen width in characters.
heightNumberThe screen height in characters.
panValueThe view centre point, { x, y }.
showValueThe units across the view.

Returns nothing.