Class: DXRubySDL::Font
- Inherits:
-
Object
- Object
- DXRubySDL::Font
- Defined in:
- lib/dxruby_sdl/font.rb
Instance Attribute Summary collapse
-
#_ttf ⇒ Object
readonly
Returns the value of attribute _ttf.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #get_width(string) ⇒ Object (also: #getWidth)
-
#initialize(size, fontname = '', hash = {}) ⇒ Font
constructor
A new instance of Font.
Constructor Details
#initialize(size, fontname = '', hash = {}) ⇒ Font
Returns a new instance of Font.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dxruby_sdl/font.rb', line 10 def initialize(size, fontname = '', hash = {}) @size = size if !SDL::TTF.init? SDL::TTF.init end if !(path = (FONTS[fontname] || FONT_ALIASES[fontname])) path = FONTS.first.last end font_cache = Font.instance_variable_get('@font_cache') args = [path, size] if font_cache.key?(args) @_ttf = font_cache[args] else @_ttf = font_cache[args] = SDL::TTF.open(*args) end end |
Instance Attribute Details
#_ttf ⇒ Object (readonly)
Returns the value of attribute _ttf.
6 7 8 |
# File 'lib/dxruby_sdl/font.rb', line 6 def _ttf @_ttf end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/dxruby_sdl/font.rb', line 5 def size @size end |
Instance Method Details
#get_width(string) ⇒ Object Also known as: getWidth
28 29 30 |
# File 'lib/dxruby_sdl/font.rb', line 28 def get_width(string) return @_ttf.text_size(string).first end |