class GosuEnhanced::Region
Hold a rectangular region specified by a Point and a Size
Most functions are delegated to the constituent Point and Size
Attributes
Top left corner
Overall Width and Height
Public Class Methods
Create a new region with specified pos
as top left corner and size
as width and height. The stored positions are copies of the passed position and size to avoid aliasing.
Alternatively, can be initialized with 2 +Point+s.
# File lib/gosu_enhanced/region.rb, line 24 def initialize(pos, size) size = Size.new(size.x - pos.x, size.y - pos.y) if size.respond_to? :x @position = pos.dup @size = size.dup end
Public Instance Methods
Return whether the region contains the specified row
and col
Alternatively, can be passed a Point
# File lib/gosu_enhanced/region.rb, line 33 def contains?(col, row = nil) return contains_point?(col) if col.respond_to? :x col.between?(left, left + width - 1) && row.between?(top, top + height - 1) end
Draw a rectangle on the specified surface
at the specified z_order
and with the specified colour
# File lib/gosu_enhanced/region.rb, line 57 def draw(surface, z_order, colour) surface.draw_rectangle(position, size, z_order, colour) end
Duplicate a Region
, must be done explicitly to avoid aliasing.
# File lib/gosu_enhanced/region.rb, line 51 def dup Region.new(position, size) end
Return the leftmost co-ordinate
# File lib/gosu_enhanced/region.rb, line 46 def left position.x end
Return a string representation of the region's position and size
# File lib/gosu_enhanced/region.rb, line 62 def to_s "<GosuEnhanced::Region: #{position}, #{size}>" end
Return the topmost co-ordinate
# File lib/gosu_enhanced/region.rb, line 41 def top position.y end
Private Instance Methods
Return whether the passed Point pt
is contained within the current Region
.
# File lib/gosu_enhanced/region.rb, line 70 def contains_point?(pt) pt.x.between?(left, left + width - 1) && pt.y.between?(top, top + height - 1) end