Class: Gosu::Font

Inherits:
Object
  • Object
show all
Defined in:
rdoc/gosu.rb

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 Image#from_text.

Instance Attribute Summary collapse

Drawing text collapse

Instance Method Summary collapse

Constructor Details

#initialize(height, options = {}) ⇒ Font #initialize(window, font_name, height) ⇒ Font

Load a font from the system fonts or a file.

(Passing a Window reference is not necessary anymore, please use the first overload from now on.)

Options Hash (options):

  • :name (String)

    the name of a system font, or a path to a TrueType Font (TTF) file. A path must contain at least one '/' character to distinguish it from a system font.



240
# File 'rdoc/gosu.rb', line 240

def initialize(height, options = {}); end

Instance Attribute Details

#heightInteger (readonly)



227
228
229
# File 'rdoc/gosu.rb', line 227

def height
  @height
end

#nameString (readonly)

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



223
224
225
# File 'rdoc/gosu.rb', line 223

def name
  @name
end

Instance Method Details

#[]=(character, image) ⇒ void

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.

This method returns an undefined value.

Overrides the image for a character.



250
# File 'rdoc/gosu.rb', line 250

def []=(character, image); end

#draw(text, x, y, z, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ void

This method returns an undefined value.

Draws a single line of text with its top left corner at (x, y).



271
# File 'rdoc/gosu.rb', line 271

def draw(text, x, y, z, scale_x=1, scale_y=1, color=0xff_ffffff, mode=:default); end

#draw_rel(text, x, y, z, rel_x, rel_y, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ void

This method returns an undefined value.

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.



288
# File 'rdoc/gosu.rb', line 288

def draw_rel(text, x, y, z, rel_x, rel_y, scale_x=1, scale_y=1, color=0xff_ffffff, mode=:default); end

#text_width(text, scale_x = 1) ⇒ Integer

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



297
# File 'rdoc/gosu.rb', line 297

def text_width(text, scale_x=1); end