Class: DXRuby::Tiled::TextObject

Inherits:
TMEObject
  • Object
show all
Defined in:
lib/dxruby_tiled/object.rb

Instance Attribute Summary collapse

Attributes inherited from TMEObject

#id, #name, #properties, #type

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, width, height, text, options = {}) ⇒ TextObject

Returns a new instance of TextObject.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/dxruby_tiled/object.rb', line 142

def initialize(x, y, width, height, text, options = {})
  options[:width]  = width
  options[:height] = height
  super x, y, options
  @text = text
  @fontfamily = options[:fontfamily] || ""
  @pixelsize  = options[:pixelsize] || 16
  @wrap       = !!options[:wrap] # unsupported

  @color      = (options[:color] || "000000").sub("#", "").scan(/../).map{ |c| c.to_i(16) }
  @bold       = !!options[:bold]
  @italic     = !!options[:italic]
  @underline  = !!options[:underline] # unsupported

  @strikeout  = !!options[:strikeout] # unsupported

  @kerning    = options[:kerning] != false # unsupported

  @halign     = options[:halign] || "left" # unsupported

  @valign     = options[:valign] || "top" # unsupported

  
  @font = DXRuby::Font.new(@pixelsize, @fontfamily,
    weight: @bold, italic: @italic, auto_fitting: true
  )
  self.collision = [0, 0, @width, @height]
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



136
137
138
# File 'lib/dxruby_tiled/object.rb', line 136

def text
  @text
end

Class Method Details

.create_from_hash(hash) ⇒ Object



138
139
140
# File 'lib/dxruby_tiled/object.rb', line 138

def self.create_from_hash(hash)
  self.new(hash[:x], hash[:y], hash[:width], hash[:height], hash[:text][:text], hash[:text])
end

Instance Method Details

#drawObject



165
166
167
168
169
# File 'lib/dxruby_tiled/object.rb', line 165

def draw
  self.target.draw_font(self.x, self.y, @text, @font,
    color: @color, center_x: 0, center_y: 0, angle: self.angle, z: self.z
  )
end