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

Parameters:

  • height (Integer)

    the height of the font, in pixels.

  • options (Hash) (defaults to: {})

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


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

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

Instance Attribute Details

#heightInteger (readonly)

Returns the font's height in pixels.

Returns:

  • (Integer)

    the font's height in pixels.



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.

Returns:

  • (String)

    the font's name.



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.

Parameters:

  • character (String)

    the character to replace.

  • image (Image)

    the image to use for the character.



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

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



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

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



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

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

Parameters:

  • text (String)
  • x (Number)

    the X coordinate

  • y (Number)

    the Y coordinate

  • z (Number)

    the Z-order.

  • scale_x (Float) (defaults to: 1)

    the horizontal scaling factor.

  • scale_y (Float) (defaults to: 1)

    the vertical scaling factor.

  • color (Color, Integer) (defaults to: 0xff_ffffff)
  • mode (:default, :additive) (defaults to: :default)

    the blending mode to use.

See Also:



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

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.

Parameters:

  • rel_x (Float)

    the horizontal alignment.

  • rel_y (Float)

    the vertical alignment.

See Also:



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

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



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

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.

Parameters:

  • text (String)

Returns:

  • (Integer)

    the width of the text, in pixels.



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

def text_width(text, scale_x=1); end