class Gosu::Font

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.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.

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.


[View source]

Instance Method Detail

def []=(codepoint : String, image : Gosu::Image) #

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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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).

SEE: #draw_text_rel

SEE: Gosu::Image.from_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


[View source]
def 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).

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


[View source]
def height : Int32 #

Returns the font's height in pixels.


[View source]
def markup_width(markup) : Float64 #

Like #text_width, but supports the following markup tags: bold, italic, and <c=rrggbb>colors.


[View source]
def name : String #

Returns the font's name. This may be the name of a system font or a filename.


[View source]
def text_width(text) : Float64 #

Returns the width of a single line of text, in pixels, if it were drawn.


[View source]