Types
MosaicPattern = seq[seq[int]]
Mosaic = ref object of RootObj fSurface: Surface ## Source surface fDim: Dim ## Dimensions of the surface tileDim*, offset*: Dim ## \ ## Dimensions of a single mosaic tile, and offset from the edge.
RepeatPattern = seq[tuple[rows, cols: int, data: seq[int]]]
-
RepeatPattern meaning:
RepeatPattern = seq[tuple[rows, cols: int, data: seq[int]]]
- rows repeat this row rows times
- cols repeat this data sequence cols times,
gradually increasing the index.
- data for each item repeat increasing index item times.
Example:
patternRepeat(@[ (1, 2, @[1, 2, 1]), (2, 2, @[1, 2, 1]), (1, 2, @[1, 2, 1]), ])
will return:
@[ @[0, 1, 1, 2, 3, 4, 4, 5], @[6, 7, 7, 8, 9, 10, 10, 11], @[6, 7, 7, 8, 9, 10, 10, 11], @[12, 13, 13, 14, 15, 16, 16, 17] ]
Procs
proc free(mosaic: Mosaic) {...}{.raises: [], tags: [].}
proc init(mosaic: Mosaic) {...}{.raises: [], tags: [].}
proc load(mosaic: Mosaic; file: string; tileDim: Dim; offset: Dim = (0, 0)): bool {...}{. raises: [], tags: [].}
-
Load mosaic graphic source from a file.
tileDim dimensions of a single mosaic tile.
offset offset from the edge.
Return true on success, or false otherwise.
proc load(mosaic: Mosaic; src: ptr RWops; tileDim: Dim; offset: Dim = (0, 0); freeSrc: bool = true): bool {...}{.raises: [], tags: [].}
proc newMosaic(): Mosaic {...}{.raises: [], tags: [].}
proc newMosaic(file: string; tileDim: Dim; offset: Dim = (0, 0)): Mosaic {...}{.raises: [], tags: [].}
-
Create a new Mosaic and load tileset from a file.
tileDim the size of a single tile.
offset offset from the edge of the tileset.
proc newMosaic(src: ptr RWops; tileDim: Dim; offset: Dim = (0, 0); freeSrc: bool = true): Mosaic {...}{. raises: [], tags: [].}
proc dim(mosaic: Mosaic): Dim {...}{.inline, raises: [], tags: [].}
proc renderSurface(mosaic: Mosaic; pattern: MosaicPattern): Surface {...}{.raises: [], tags: [].}
- Return a new Surface created with mosaic tiles by a given pattern.
proc render(mosaic: Mosaic; pattern: MosaicPattern): Texture {...}{.raises: [], tags: [].}
- Return a new Texture created with mosaic tiles by a given pattern.
proc patternRepeat(repeat: RepeatPattern): MosaicPattern {...}{.raises: [], tags: [].}
-
Generate a repeating pattern. Useful for generating GUI elements of different sizes with Mosaic.
See also: RepeatPattern type.
proc patternStretchBorder(w, h: int; nx = 2; ny = 3): MosaicPattern {...}{.raises: [], tags: [].}
-
Generate a repeating pattern by repeating border items of 3x3 matrix (used for GUI buttons, etc.)
w, h strethed parts repeat count.
nx, ny number of elements in the matrix.