Class: Metro::Font

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/metro/font.rb

Overview

Font is a wrapper class for a Gosu::Font. This allows for additional data to be stored without relying on monkey-patching on functionality.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gosu_font) ⇒ Font

Returns a new instance of Font.



9
10
11
# File 'lib/metro/font.rb', line 9

def initialize(gosu_font)
  super(gosu_font)
end

Class Method Details

.create(options) ⇒ Object

Return a font that matches the specified criteria. Using the name, size, and window a font will be generated and stored in the cache.

that describe the font.

Examples:

Creating a Font


Metro::Font.create window: model.window,
  name: "Comic Sans", size: 48

Parameters:

  • value (Hash)

    the hash that contains the ‘name`, `size` and `window`



46
47
48
49
50
51
# File 'lib/metro/font.rb', line 46

def self.create(options)
  window, name, size = create_params(options)
  gosu_font = create_gosu_font(window,name,size)
  fonts["#{name}:#{size}:#{window}"] = gosu_font
  new(gosu_font)
end

.find_or_create(options) ⇒ Object

Return a font that matches the specified criteria. Using the name, size, and window a font will be generated or retrieved from the cache.

that describe the font.

Examples:

Finding or creating a Font


Metro::Font.find_or_create window: model.window,
  name: "Times New Roman", size: 24

Parameters:

  • value (Hash)

    the hash that contains the ‘name`, `size` and `window`



28
29
30
31
32
# File 'lib/metro/font.rb', line 28

def self.find_or_create(options)
  window, name, size = create_params(options)
  gosu_font = fonts["#{name}:#{size}:#{window}"]
  gosu_font ? new(gosu_font) : create(options)
end

Instance Method Details

#sizeObject

An alias to Gosu::Font’s height method



14
# File 'lib/metro/font.rb', line 14

def size ; height ; end