This Font
does not implement all settings of TextSprites
.
gamnit :: TileSetFont :: advance
Distance between the beginning of a letter tile and the beginning of the next letter tilegamnit :: TileSetFont :: defaultinit
gamnit :: TileSetFont :: hspace
Additional space to insert horizontally between charactersgamnit :: TileSetFont :: hspace=
Additional space to insert horizontally between charactersgamnit :: TileSetFont :: text_height
Distance between the top of the first line to the bottom of the last line intext
gamnit :: TileSetFont :: text_width
Distance between the beginning and the end of the longest line oftext
gamnit :: TileSetFont :: vspace
Additional space to insert vertically between charactersgamnit :: TileSetFont :: vspace=
Additional space to insert vertically between charactersgamnit $ TileSetFont :: SELF
Type of this instance, automatically specialized in every classgamnit $ TileSetFont :: write_into
Backend writing service, clients should useTextSprites.text=
gamnit :: TileSetFont :: advance
Distance between the beginning of a letter tile and the beginning of the next letter tilecore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
gamnit :: Font :: defaultinit
gamnit :: TileSetFont :: defaultinit
core :: Object :: defaultinit
gamnit :: TileSet :: defaultinit
gamnit :: TileSetFont :: hspace
Additional space to insert horizontally between charactersgamnit :: TileSetFont :: hspace=
Additional space to insert horizontally between characterscore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).gamnit :: Font :: partial_line_mod
Line spacing modifier forpld
and plu
gamnit :: Font :: partial_line_mod=
Line spacing modifier forpld
and plu
gamnit :: TileSet :: subtextures=
Cache of the subtextures of tilesgamnit :: TileSetFont :: text_height
Distance between the top of the first line to the bottom of the last line intext
gamnit :: TileSetFont :: text_width
Distance between the beginning and the end of the longest line oftext
gamnit :: TileSetFont :: vspace
Additional space to insert vertically between charactersgamnit :: TileSetFont :: vspace=
Additional space to insert vertically between charactersgamnit :: Font :: write_into
Backend writing service, clients should useTextSprites.text=
# A monospace bitmap font where glyphs are stored in a tileset
#
# This `Font` does not implement all settings of `TextSprites`.
class TileSetFont
super TileSet
super Font
# Set the characters present in `texture`
#
# Last all characters from left to right, then top to bottom.
# Line skip `\n`, are ignored and space ' ' skips holes in the tileset.
fun chars=(chars: Text)
is autoinit do
chars_cleaned = chars.replace("\n", "")
end
# Character present in the texture, set by `chars=`
private var chars_cleaned: Text is noautoinit
# Additional space to insert horizontally between characters
#
# A negative value may display overlapped tiles.
var hspace: Numeric = 0.0 is writable
# Additional space to insert vertically between characters
#
# A negative value may display overlapped tiles.
var vspace: Numeric = 0.0 is writable
# The glyph/tile/texture associated to `char`
#
# Returns null if `char` is not in `chars`.
fun char(char: Char): nullable Texture
do
var i = chars_cleaned.index_of(char)
if i == -1 then return null
return subtextures[i]
end
# Distance between the beginning of a letter tile and the beginning of the next letter tile
fun advance: Float do return width.to_f + hspace.to_f
# Distance between the beginning and the end of the longest line of `text`
fun text_width(text: Text): Numeric
do
var lines = text.split('\n')
if lines.is_empty then return 0
var longest = 0
for line in lines do longest = longest.max(line.length)
return longest.mul(advance)
end
# Distance between the top of the first line to the bottom of the last line in `text`
fun text_height(text: Text): Numeric
do
if text.is_empty then return 0
var n_lines = text.chars.count('\n')
return (n_lines+1).mul(height.add(vspace)).sub(vspace)
end
redef fun write_into(text_sprites, text)
do
# Build new sprites
var dx = advance/2.0
var dy = hspace.to_f/2.0
for c in text do
if c == '\n' then
dy -= height.to_f + vspace.to_f
dx = advance/2.0
continue
else if c == pld then
dy -= (height.to_f + vspace.to_f) * partial_line_mod.to_f
continue
else if c == plu then
dy += (height.to_f + vspace.to_f) * partial_line_mod.to_f
continue
else if c.is_whitespace then
dx += advance
continue
end
var tex = char(c)
if tex == null then
# Try to fallback to '?'
tex = char('?')
if tex == null then continue
end
text_sprites.sprites.add new Sprite(tex, text_sprites.anchor.offset(dx, dy, 0))
dx += advance
end
end
end
lib/gamnit/tileset.nit:60,1--155,3