Class: Gosu::Font

Inherits:
Object
  • Object
show all
Includes:
Chingu::NamedResource
Defined in:
lib/chingu/assets.rb

Class Method Summary collapse

Methods included from Chingu::NamedResource

included, #name, #name=

Class Method Details

.self.[](name, size) ⇒ Object .self.[](size) ⇒ Object

Overloads:

  • .self.[](name, size) ⇒ Object

    Get a font with the given name and size.

    Parameters:

    • name (String)

      Name of the font (or path to TTF font)

    • size (Number)

      Size of the font.

  • .self.[](size) ⇒ Object

    Get a font of a given size using the Gosu.default_font_name.

    Parameters:

    • size (Number)

      Size of the font.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/chingu/assets.rb', line 67

def self.[]( *args )
  case args.size
  when 1
    name = Gosu.default_font_name
    size = args[0]
  when 2
    name, size = args
  else
    raise ArgumentError, "wrong number of arguments (#{args.size} for 1 or 2)"
  end

  result = @resources[[name, size]]

  if result.nil?
    result = autoload(name, size)
    if result
      self[name, size] = result
      result.name = name
    end
  end

  return result
end

.[]=(name, size, font) ⇒ Object

Save a font with the given name and size.

Parameters:

  • name (String)

    Name of the font (or path to TTF font)

  • size (Number)

    Size of the font.

  • font (Gosu::Font)

    Font object to save.



95
96
97
# File 'lib/chingu/assets.rb', line 95

def self.[]=( name, size, font )
  @resources[[name, size]] = font
end

.autoload(name, size) ⇒ Object

Load a font with the given name and size.

Parameters:

  • name (String)

    Name of the font (or path to TTF font)

  • size (Number)

    Size of the font.



49
50
51
52
53
54
55
56
57
# File 'lib/chingu/assets.rb', line 49

def self.autoload(name, size)
  font_name = if path = find_file(name)
    path # Use the full path, found in the autoload dirs.
  else
    name # Font not found in the path. Assume it is an OS font.
  end

  return Gosu::Font.new($window, font_name, size)
end