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
  • :retro (bool) — default: false

    see Gosu::Image



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

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.



262
263
264
# File 'rdoc/gosu.rb', line 262

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.



258
259
260
# File 'rdoc/gosu.rb', line 258

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.



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

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



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

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



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

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:



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

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:



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

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



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

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.



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

def text_width(text, scale_x=1); end