Class: Ruby2D::Text

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/ruby2d/text.rb

Instance Attribute Summary collapse

Attributes included from Renderable

#color, #height, #width, #z

Instance Method Summary collapse

Methods included from Renderable

#a, #a=, #add, #b, #b=, #contains?, #g, #g=, #opacity, #opacity=, #r, #r=, #remove

Constructor Details

#initialize(text, opts = {}) ⇒ Text

Returns a new instance of Text.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby2d/text.rb', line 10

def initialize(text, opts = {})
  @x = opts[:x] || 0
  @y = opts[:y] || 0
  @z = opts[:z] || 0
  @text = text.to_s
  @size = opts[:size] || 20
  @rotate = opts[:rotate] || 0
  self.color = opts[:color] || 'white'
  self.opacity = opts[:opacity] if opts[:opacity]
  @font = opts[:font] || Font.default
  unless File.exist? @font
    raise Error, "Cannot find font file `#{@font}`"
  end
  unless ext_init
    raise Error, "Text `#{@text}` cannot be created"
  end
  unless opts[:show] == false then add end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def data
  @data
end

#fontObject (readonly)

Returns the value of attribute font.



7
8
9
# File 'lib/ruby2d/text.rb', line 7

def font
  @font
end

#rotateObject

Returns the value of attribute rotate.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def rotate
  @rotate
end

#sizeObject

Returns the value of attribute size.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def size
  @size
end

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/ruby2d/text.rb', line 7

def text
  @text
end

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def x
  @x
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def y
  @y
end

Instance Method Details

#draw(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby2d/text.rb', line 34

def draw(opts = {})
  opts[:rotate] = opts[:rotate] || @rotate
  unless opts[:color]
    opts[:color] = [1.0, 1.0, 1.0, 1.0]
  end

  self.class.ext_draw([
    self, opts[:x], opts[:y], opts[:rotate],
    opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
  ])
end