Class: Metro::Model::FontProperty
- Defined in:
- lib/metro/models/properties/font_property.rb
Overview
A font property maintains a Gosu::Font.
A font property also defines a ‘font_size` property and a `font_name` property which allows a more direct interface. Changing these values will update the font the next time that it is drawn.
A font is stored in the properties as a hash representation and is converted into a Gosu::Font when it is retrieved within the system. When retrieving a font the Font Property will attempt to use a font that already exists that meets that criteria.
The fonts are cached within the font property to help performance by reducing the unncessary creation of similar fonts.
Constant Summary
Constants included from Units
Instance Attribute Summary
Attributes inherited from Property
Class Method Summary collapse
-
.font_for(value) ⇒ Object
Return a font that matches the specified criteria.
Instance Method Summary collapse
-
#default_font ⇒ Object
The default font to use when a value has not been provided.
-
#default_font_name ⇒ Object
Use the specified default font name or fall back to Gosu’s default font name.
-
#default_font_size ⇒ Object
Use the specified default font size or fall back to 40.
Methods inherited from Property
define_property, defined_properties, get, #get, get_or_set, gets, hash_with_default_to_nil, inherited, #initialize, properties, properties_hash, property, #set, set, sets
Constructor Details
This class inherits a constructor from Metro::Model::Property
Class Method Details
.font_for(value) ⇒ Object
Return a font that matches the specified criteria. Usig the name, size, and window a font will be generated or retrieved from the cache.
123 124 125 |
# File 'lib/metro/models/properties/font_property.rb', line 123 def self.font_for(value) Font.find_or_create(value) end |
Instance Method Details
#default_font ⇒ Object
Returns the default font to use when a value has not been provided.
97 98 99 100 101 |
# File 'lib/metro/models/properties/font_property.rb', line 97 def default_font self.class.font_for name: default_font_name, size: default_font_size, window: model.window end |
#default_font_name ⇒ Object
Use the specified default font name or fall back to Gosu’s default font name.
113 114 115 |
# File 'lib/metro/models/properties/font_property.rb', line 113 def default_font_name ([:default] and [:default][:name]) ? [:default][:name] : Gosu::default_font_name end |
#default_font_size ⇒ Object
Use the specified default font size or fall back to 40.
106 107 108 |
# File 'lib/metro/models/properties/font_property.rb', line 106 def default_font_size ([:default] and [:default][:size]) ? [:default][:size] : 40 end |