class DrawSvg::Rectangle
TODO: Consider only having Polygon w/ a Rectangle
wrapper.
Attributes
location2[R]
Public Class Methods
new(parent, location, location2, opts={})
click to toggle source
Calls superclass method
DrawSvg::Item::new
# File lib/drawsvg.rb, line 193 def initialize parent, location, location2, opts={} super(parent, location) @location2 = Point.new(location2) @opts = opts @draw_from = @opts.delete(:draw_from) || :top_left @snap = @opts.has_key?(:snap) ? @opts.delete(:snap) : true end
Public Instance Methods
draw()
click to toggle source
# File lib/drawsvg.rb, line 200 def draw; end
p1()
click to toggle source
top left corner
# File lib/drawsvg.rb, line 205 def p1 p = @snap ? location : (location * scale) if @draw_from == :bottom_left p + Point[0, (location2*scale).y] else p end end
p1_absolute()
click to toggle source
# File lib/drawsvg.rb, line 220 def p1_absolute parent.absolute_location + p1 end
p1_svg()
click to toggle source
# File lib/drawsvg.rb, line 226 def p1_svg Point.new(p1_absolute.x, (canvas.height - p1_absolute.y)).round end
p2()
click to toggle source
bottom right corner
# File lib/drawsvg.rb, line 214 def p2 p1 + p2_relative end
p2_absolute()
click to toggle source
# File lib/drawsvg.rb, line 223 def p2_absolute parent.absolute_location + p2 end
p2_relative()
click to toggle source
# File lib/drawsvg.rb, line 217 def p2_relative location2*scale end
p2_svg()
click to toggle source
# File lib/drawsvg.rb, line 229 def p2_svg p2_relative.round end
to_svg(img)
click to toggle source
# File lib/drawsvg.rb, line 201 def to_svg img img.rectangle(p1_svg.x, p1_svg.y, p2_svg.x, p2_svg.y, Rasem::SVGImage::DefaultStyles[:rect].merge(@opts)) end