Class: Ruby2D::Text
- Inherits:
-
Object
- Object
- Ruby2D::Text
- Includes:
- Renderable
- Defined in:
- lib/ruby2d/text.rb,
ext/ruby2d/ruby2d-opal.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#data ⇒ Object
Returns the value of attribute data.
-
#font ⇒ Object
readonly
Returns the value of attribute font.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#text ⇒ Object
Returns the value of attribute text.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes included from Renderable
Instance Method Summary collapse
- #contains?(x, y) ⇒ Boolean
- #ext_init ⇒ Object
- #ext_render ⇒ Object
- #ext_set(msg) ⇒ Object
-
#initialize(opts = {}) ⇒ Text
constructor
A new instance of Text.
Methods included from Renderable
#add, #opacity, #opacity=, #remove
Constructor Details
#initialize(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 28 |
# File 'lib/ruby2d/text.rb', line 10 def initialize(opts = {}) @x = opts[:x] || 0 @y = opts[:y] || 0 @z = opts[:z] || 0 @text = (opts[:text] || "Hello World!").to_s @size = opts[:size] || 20 @font = opts[:font] unless RUBY_ENGINE == 'opal' unless File.exists? @font raise Error, "Cannot find font file `#{@font}`" end end self.color = opts[:color] || 'white' ext_init add end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def color @color end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/ruby2d/text.rb', line 7 def data @data end |
#font ⇒ Object (readonly)
Returns the value of attribute font.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def font @font end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def height @height end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def size @size end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def text @text end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
7 8 9 |
# File 'lib/ruby2d/text.rb', line 7 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
7 8 9 |
# File 'lib/ruby2d/text.rb', line 7 def y @y end |
Instance Method Details
#contains?(x, y) ⇒ Boolean
39 40 41 |
# File 'lib/ruby2d/text.rb', line 39 def contains?(x, y) @x < x and @x + @width > x and @y < y and @y + @height > y end |
#ext_init ⇒ Object
195 196 197 198 199 200 201 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 195 def ext_init ` #{self}.data = S2D.CreateText(#{self}.font, #{self}.text, #{self}.size); #{@width} = #{self}.data.width; #{@height} = #{self}.data.height; ` end |
#ext_render ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 211 def ext_render ` #{self}.data.x = #{self}.x; #{self}.data.y = #{self}.y; #{self}.data.color.r = #{self}.color.r; #{self}.data.color.g = #{self}.color.g; #{self}.data.color.b = #{self}.color.b; #{self}.data.color.a = #{self}.color.a; S2D.DrawText(#{self}.data); ` end |
#ext_set(msg) ⇒ Object
203 204 205 206 207 208 209 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 203 def ext_set(msg) ` S2D.SetText(#{self}.data, #{msg}); #{@width} = #{self}.data.width; #{@height} = #{self}.data.height; ` end |