Manage a set of sprites to display some text

Introduced properties

fun align: Float

gamnit :: TextSprites :: align

Horizontal text alignment
fun align=(align: nullable Float)

gamnit :: TextSprites :: align=

Horizontal text alignment
fun anchor: Point3d[Float]

gamnit :: TextSprites :: anchor

Reference coordinates of this block of text
protected fun anchor=(anchor: Point3d[Float])

gamnit :: TextSprites :: anchor=

Reference coordinates of this block of text
init defaultinit(font: Font, anchor: Point3d[Float], text: nullable Text, align: nullable Float, valign: nullable Float, max_width: nullable Float, max_height: nullable Float, wrap: nullable Bool, scale: nullable Float)

gamnit :: TextSprites :: defaultinit

fun font: Font

gamnit :: TextSprites :: font

Font used to draw text
protected fun font=(font: Font)

gamnit :: TextSprites :: font=

Font used to draw text
fun force_redraw

gamnit :: TextSprites :: force_redraw

Force drawing of the text sprites
fun height: Float

gamnit :: TextSprites :: height

Height of the currently displayed text
protected fun height=(height: Float)

gamnit :: TextSprites :: height=

Height of the currently displayed text
fun max_height: nullable Float

gamnit :: TextSprites :: max_height

Maximum height of this block of text
fun max_height=(max_height: nullable Float)

gamnit :: TextSprites :: max_height=

Maximum height of this block of text
fun max_width: nullable Float

gamnit :: TextSprites :: max_width

Maximum width of each line of text
fun max_width=(max_width: nullable Float)

gamnit :: TextSprites :: max_width=

Maximum width of each line of text
fun scale: Float

gamnit :: TextSprites :: scale

Scale applied to all sprites and spacing
fun scale=(scale: nullable Float)

gamnit :: TextSprites :: scale=

Scale applied to all sprites and spacing
fun sprites: Array[Sprite]

gamnit :: TextSprites :: sprites

Last set of sprites generated to display text=
protected fun sprites=(sprites: Array[Sprite])

gamnit :: TextSprites :: sprites=

Last set of sprites generated to display text=
fun target_sprite_set: Set[Sprite]

gamnit :: TextSprites :: target_sprite_set

Sprite set where to put created sprites
fun target_sprite_set=(target_sprite_set: Set[Sprite])

gamnit :: TextSprites :: target_sprite_set=

Sprite set where to put created sprites
fun text: nullable Text

gamnit :: TextSprites :: text

Last text drawn
fun text=(text: nullable Text)

gamnit :: TextSprites :: text=

Update the text displayed by inserting new sprites into app.ui_sprites
fun valign: Float

gamnit :: TextSprites :: valign

Vertical text alignment
fun valign=(valign: nullable Float)

gamnit :: TextSprites :: valign=

Vertical text alignment
fun width: Float

gamnit :: TextSprites :: width

Width of the currently displayed text
protected fun width=(width: Float)

gamnit :: TextSprites :: width=

Width of the currently displayed text
fun wrap: Bool

gamnit :: TextSprites :: wrap

Should overflowing lines wrap to the next line?
fun wrap=(wrap: nullable Bool)

gamnit :: TextSprites :: wrap=

Should overflowing lines wrap to the next line?

Redefined properties

redef type SELF: TextSprites

gamnit $ TextSprites :: SELF

Type of this instance, automatically specialized in every class
redef init init

gamnit $ TextSprites :: init

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun align: Float

gamnit :: TextSprites :: align

Horizontal text alignment
fun align=(align: nullable Float)

gamnit :: TextSprites :: align=

Horizontal text alignment
fun anchor: Point3d[Float]

gamnit :: TextSprites :: anchor

Reference coordinates of this block of text
protected fun anchor=(anchor: Point3d[Float])

gamnit :: TextSprites :: anchor=

Reference coordinates of this block of text
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(font: Font, anchor: Point3d[Float], text: nullable Text, align: nullable Float, valign: nullable Float, max_width: nullable Float, max_height: nullable Float, wrap: nullable Bool, scale: nullable Float)

gamnit :: TextSprites :: defaultinit

fun font: Font

gamnit :: TextSprites :: font

Font used to draw text
protected fun font=(font: Font)

gamnit :: TextSprites :: font=

Font used to draw text
fun force_redraw

gamnit :: TextSprites :: force_redraw

Force drawing of the text sprites
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun height: Float

gamnit :: TextSprites :: height

Height of the currently displayed text
protected fun height=(height: Float)

gamnit :: TextSprites :: height=

Height of the currently displayed text
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun max_height: nullable Float

gamnit :: TextSprites :: max_height

Maximum height of this block of text
fun max_height=(max_height: nullable Float)

gamnit :: TextSprites :: max_height=

Maximum height of this block of text
fun max_width: nullable Float

gamnit :: TextSprites :: max_width

Maximum width of each line of text
fun max_width=(max_width: nullable Float)

gamnit :: TextSprites :: max_width=

Maximum width of each line of text
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun scale: Float

gamnit :: TextSprites :: scale

Scale applied to all sprites and spacing
fun scale=(scale: nullable Float)

gamnit :: TextSprites :: scale=

Scale applied to all sprites and spacing
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun sprites: Array[Sprite]

gamnit :: TextSprites :: sprites

Last set of sprites generated to display text=
protected fun sprites=(sprites: Array[Sprite])

gamnit :: TextSprites :: sprites=

Last set of sprites generated to display text=
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun target_sprite_set: Set[Sprite]

gamnit :: TextSprites :: target_sprite_set

Sprite set where to put created sprites
fun target_sprite_set=(target_sprite_set: Set[Sprite])

gamnit :: TextSprites :: target_sprite_set=

Sprite set where to put created sprites
fun text: nullable Text

gamnit :: TextSprites :: text

Last text drawn
fun text=(text: nullable Text)

gamnit :: TextSprites :: text=

Update the text displayed by inserting new sprites into app.ui_sprites
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun valign: Float

gamnit :: TextSprites :: valign

Vertical text alignment
fun valign=(valign: nullable Float)

gamnit :: TextSprites :: valign=

Vertical text alignment
fun width: Float

gamnit :: TextSprites :: width

Width of the currently displayed text
protected fun width=(width: Float)

gamnit :: TextSprites :: width=

Width of the currently displayed text
fun wrap: Bool

gamnit :: TextSprites :: wrap

Should overflowing lines wrap to the next line?
fun wrap=(wrap: nullable Bool)

gamnit :: TextSprites :: wrap=

Should overflowing lines wrap to the next line?
package_diagram gamnit::TextSprites TextSprites core::Object Object gamnit::TextSprites->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

gamnit $ TextSprites
# Manage a set of sprites to display some text
class TextSprites

	# Font used to draw text
	var font: Font

	# Reference coordinates of this block of text
	#
	# When left aligned, the default at `align == 0.0`, the anchor is the
	# left coordinate of the first character of the first line.
	# When right aligned, at `align == 1.0`, the anchor is the right
	# coordinate of the last character.
	# When centered, at `align == 0.5`, the anchor is at the center.
	#
	# When top aligned, the default at `valign == 0.0`, the anchor is at the
	# top of this block of text.
	# When bottom aligned, at `valign == 1.0`, the anchor is at the bottom.
	var anchor: Point3d[Float]

	# Last set of sprites generated to display `text=`
	var sprites = new Array[Sprite]

	# Sprite set where to put created sprites
	#
	# Defaults to `app::ui_sprites`, but it could also be set to a
	# `app::sprites` or a custom collection.
	var target_sprite_set: Set[Sprite] = app.ui_sprites is lazy, writable

	private var cached_text: nullable Text = null

	private var init_complete = false

	# Last text drawn
	fun text: nullable Text do return cached_text

	# Update the text displayed by inserting new sprites into `app.ui_sprites`
	#
	# Does not redraw if `text` has not changed.
	fun text=(text: nullable Text)
	is autoinit do
		# Don't redraw if text hasn't changed
		if text == cached_text then return
		cached_text = text

		if not init_complete then return

		# Clean up last used sprites
		for s in sprites do if target_sprite_set.has(s) then target_sprite_set.remove s
		sprites.clear

		if text == null then return

		font.write_into(self, text)

		# Register sprites to be drawn by `app.ui_camera`
		target_sprite_set.add_all sprites
	end

	# Horizontal text alignment
	#
	# Use 0.0 to align left (the default), 0.5 to align in the center or
	# 1.0 to align on the right.
	#
	# See: `valign`
	var align = 0.0 is optional, writable

	# Vertical text alignment
	#
	# Use 0.0 for top alignment (the default) where the text is under the `anchor`,
	# 0.5 to vertically center the text on the `anchor` or
	# or 1.0 to bottom align the text above the `anchor`.
	#
	# See: `align`
	var valign = 0.0 is optional, writable

	# Maximum width of each line of text
	#
	# The first word of each line is exempt and may overflow.
	#
	# The behavior when a line overflow depends on `wrap`.
	var max_width: nullable Float is writable

	# Maximum height of this block of text
	#
	# The first line is exempt and may overflow.
	# Overflowing lines are cut.
	var max_height: nullable Float is writable

	# Should overflowing lines wrap to the next line?
	#
	# If `true`, the default, overflowing lines continue on the next line.
	# Otherwise, lines are cut before overflowing.
	var wrap = true is optional, writable

	# Scale applied to all sprites and spacing
	#
	# Defaults to 1.0.
	var scale = 1.0 is optional, writable

	# Links in the currently displayed text
	#
	# Links are declared in a Markdown-like format:
	#
	# * `[my link]` creates a link with the name `my link`.
	# * `[pretty name](internal name)` creates a link with the
	#   name `internal_name` while showing the text `pretty name`.
	#
	# This `Map` lists the sprites composing each link.
	# These sprites can be modified as desired by the clients,
	# by changing their tints or anything else.
	var links = new Map[String, Array[Sprite]] is lazy

	# Width of the currently displayed text
	var width = 0.0

	# Height of the currently displayed text
	var height = 0.0

	# Force drawing of the text sprites
	#
	# This method may be called after changing a setting (`align`, `wrap`, etc.)
	# to update the displayed text.
	fun force_redraw
	do
		var t = cached_text
		cached_text = null
		text = t
	end

	init
	do
		init_complete = true
		force_redraw
	end
end
lib/gamnit/font.nit:33,1--167,3