Class: DXRubySDL::Font

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#_ttfObject (readonly)

Returns the value of attribute _ttf.



6
7
8
# File 'lib/dxruby_sdl/font.rb', line 6

def _ttf
  @_ttf
end

#sizeObject (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