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 '/' or '.' character to distinguish it from a system font.

  • :bold (bool) — default: false
  • :italic (bool) — default: false
  • :underline (bool) — default: false

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

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

Instance Attribute Details

#heightInteger (readonly)


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

def height
  @height
end

#nameString (readonly)

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


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

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.


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

def []=(character, image); end

#draw_markup(markup, x, y, z, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ Object

Like #draw_text, but supports the following markup tags: `bold`, `italic`, `<c=rrggbb>colors</c>`.


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

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

#draw_markup_rel(markup, x, y, z, rel_x, rel_y, scale_x = 1, scale_y = 1, color = 0xff_ffffff, mode = :default) ⇒ Object

Like #draw_text_rel, but supports the following markup tags: `bold`, `italic`, `<c=rrggbb>colors</c>`.


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

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

#draw_text(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).


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

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

#draw_text_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.


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

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

#markup_width(markup, scale_x = 1) ⇒ Object

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


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

def markup_width(markup, scale_x=1); end

#text_width(text, scale_x = 1) ⇒ Integer

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


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

def text_width(text, scale_x=1); end