lib/whirled_peas/graphics/canvas.rb in whirled_peas-0.6.0 vs lib/whirled_peas/graphics/canvas.rb in whirled_peas-0.7.0
- old
+ new
@@ -2,32 +2,33 @@
module WhirledPeas
module Graphics
# Canvas represent the area of the screen a painter can paint on.
class Canvas
- attr_reader :left, :top, :width, :height, :start_left, :start_top
+ attr_reader :left, :top, :width, :height
def self.unwritable
- new(-1, -1, 0, 0, -1, -1)
+ new(-1, -1, 0, 0)
end
- def initialize(left, top, width, height, start_left, start_top)
+ def initialize(left, top, width, height)
@left = left
@top = top
@width = width
@height = height
- @start_left = start_left
- @start_top = start_top
end
def writable?
width > 0 || height > 0
end
- def child(start_left, start_top, child_width, child_height)
- child_left = start_left
- child_top = start_top
+ def child(child_left, child_top, child_width, child_height)
+ Graphics.debugger(
+ proc do
+ "Create child: #{self.inspect}.child(left=#{child_left}, top=#{child_top}, width=#{child_width}, height=#{child_height})"
+ end
+ )
if child_left >= left + width
self.class.unwritable
elsif child_left + child_width <= left
self.class.unwritable
elsif child_top >= top + height
@@ -43,24 +44,29 @@
if child_top < top
child_height -= top - child_top
child_top = top
end
child_height = [height - (child_top - top), child_height].min
- self.class.new(
+ child_canvas = self.class.new(
child_left,
child_top,
child_width,
child_height,
- start_left,
- start_top
)
+ Graphics.debugger(proc { " -> #{child_canvas.inspect}" })
+ child_canvas
end
end
# Yields a single line of formatted characters positioned on the canvas,
# verifying only characters within the canvas are included.
def stroke(stroke_left, stroke_top, raw, formatting=[], &block)
+ Graphics.debugger(
+ proc do
+ "Stroke: #{self.inspect}.stroke(left=#{stroke_left}, top=#{stroke_top}, length=#{raw.length})"
+ end
+ )
if stroke_left >= left + width
# The stroke starts to the right of the canvas
fstring = Utils::FormattedString.blank
elsif stroke_left + raw.length <= left
# The stroke ends to the left of the canvas
@@ -86,9 +92,14 @@
# Determine how many characters from the stroke will fit on the canvas
visible_length = [raw.length, width - (stroke_left - left)].min
end_index = start_index + visible_length - 1
fstring = Utils::FormattedString.new(raw[start_index..end_index], formatting)
end
+ Graphics.debugger(
+ proc do
+ " -> Stroke(left=#{stroke_left}, top=#{stroke_top}, length=#{fstring.length})"
+ end
+ )
yield stroke_left, stroke_top, fstring
end
def hash
[left, top, width, height].hash