class Gosu::Font
- Gosu::Font
- Reference
- Object
Overview
A Font can be used to draw text on a Window object very flexibly.
Fonts are ideal for small texts that change regularly.
For large, static texts you should use Gosu::Image#from_text
.
Defined in:
gosu/font.crConstructors
-
.new(height : Int32, name : String = Gosu.default_font_name, bold : Bool = false, italic : Bool = false, underline : Bool = false)
Load a font from the system fonts or a file.
Instance Method Summary
-
#[]=(codepoint : String, image : Gosu::Image)
Overrides the image for a character.
-
#draw_markup(markup : String, x : Int32 | Float64, y : Int32 | Float64, z : Int32 | Float64, scale_x : Int32 | Float64 = 1, scale_y : Int32 | Float64 = 1, color : Gosu::Color | Int64 | UInt32 = Gosu::Color::WHITE, mode : Symbol = :default)
Like
#draw_text
, but supports the following markup tags: bold, italic, and <c=rrggbb>colors. -
#draw_markup_rel(markup : String, x : Int32 | Float64, y : Int32 | Float64, z : Int32 | Float64, rel_x : Int32 | Float64, rel_y : Int32 | Float64, scale_x : Int32 | Float64 = 1, scale_y : Int32 | Float64 = 1, color : Gosu::Color | Int64 | UInt32 = Gosu::Color::WHITE, mode : Symbol = :default)
Like
#draw_text_rel
, but supports the following markup tags: bold, italic, and <c=rrggbb>colors. -
#draw_text(text : String, x : Int32 | Float64, y : Int32 | Float64, z : Int32 | Float64, scale_x : Int32 | Float64 = 1, scale_y : Int32 | Float64 = 1, color : Gosu::Color | Int64 | UInt32 = Gosu::Color::WHITE, mode : Symbol = :default)
Draws a single line of text with its top left corner at (x, y).
-
#draw_text_rel(text : String, x : Int32 | Float64, y : Int32 | Float64, z : Int32 | Float64, rel_x : Int32 | Float64, rel_y : Int32 | Float64, scale_x : Int32 | Float64 = 1, scale_y : Int32 | Float64 = 1, color : Gosu::Color | Int64 | UInt32 = Gosu::Color::WHITE, mode : Symbol = :default)
Draws a single line of text relative to (x, y).
-
#height : Int32
Returns the font's height in pixels.
-
#markup_width(markup) : Float64
Like
#text_width
, but supports the following markup tags: bold, italic, and <c=rrggbb>colors. -
#name : String
Returns the font's name.
-
#text_width(text) : Float64
Returns the width of a single line of text, in pixels, if it were drawn.
Constructor Detail
Load a font from the system fonts or a file.
height: the height of the font, in pixels.
name: the name of a system font, or a path to a TrueType Font (TTF) file. A path must contain at least one '/' or '.' character to distinguish it from a system font.
Instance Method Detail
Overrides the image for a character.
NOTE For any given character, this method MUST NOT be called more than once, and MUST NOT be called if a string containing the character has already been drawn.
Like #draw_text
, but supports the following markup tags: bold, italic, and <c=rrggbb>colors.
Like #draw_text_rel
, but supports the following markup tags: bold, italic, and <c=rrggbb>colors.
Draws a single line of text with its top left corner at (x, y).
SEE: #draw_text_rel
NOTE https://github.com/gosu/gosu/wiki/Basic-Concepts#drawing-with-colours Drawing with colors, explained in the Gosu Wiki
NOTE https://github.com/gosu/gosu/wiki/Basic-Concepts#z-ordering Z-ordering explained in the Gosu Wiki
Draws a single line of text relative to (x, y).
The text is aligned to the drawing location according to the rel_x
and rel_y
parameters: a value of 0.0 corresponds to top and left, while 1.0 corresponds to bottom and right. A value of 0.5 naturally corresponds to the center of the text.
All real numbers are valid alignment values and will be interpolated (or extrapolated) accordingly.
SEE: #draw_text
NOTE https://github.com/gosu/gosu/wiki/Basic-Concepts#drawing-with-colours Drawing with colors, explained in the Gosu Wiki
NOTE https://github.com/gosu/gosu/wiki/Basic-Concepts#z-ordering Z-ordering explained in the Gosu Wiki
Like #text_width
, but supports the following markup tags: bold, italic, and <c=rrggbb>colors.
Returns the width of a single line of text, in pixels, if it were drawn.