Class: RubyLabs::Canvas::Rectangle

Inherits:
TkObject
  • Object
show all
Defined in:
lib/rubylabs.rb

Overview

Rectangle

A Rectangle object is a proxy for a Tk rectangle.  

There are no instance methods for Rectangles beyond those defined in the TkObject base class.

Instance Attribute Summary

Attributes inherited from TkObject

#coords, #name, #penpoint

Instance Method Summary collapse

Methods inherited from TkObject

#erase, #fill=, #lower, nextId, options, #raise, reset

Constructor Details

#initialize(x0, y0, x1, y1, args = {}) ⇒ Rectangle

Create a new rectangle with its upper left corner at (x0,y0) lower right corner at (x1,y1). Attributes of the rectangle can be passed in a hash object at the end of the argument list.

Example – create a 20x20 square with upper left corner at (10,10), with a dark green outline and yellow interior:

>> x = Canvas::Rectangle.new(10, 10, 30, 30, :fill => "yellow", :outline => "darkgreen")
=> #<RubyLabs::Canvas::Rectangle:...>

:call-seq:

x = Rectangle.new(x0, y0, x1, y1, args = {})


972
973
974
975
976
977
978
979
# File 'lib/rubylabs.rb', line 972

def initialize(x0, y0, x1, y1, args = {})
  raise "No canvas" unless @@pipe
  @name = TkObject.nextId
  @coords = [ x0, y0, x1, y1 ] 
  @penpoint = [ (x1-x0)/2, (y1-y0)/2 ]
  cmnd = "set #{@name} [.canvas create rectangle #{@coords.join(" ")} #{TkObject.options(args)}]"
  @@pipe.puts cmnd
end