Sha256: 29447b1b04c299090a679f53d55f530e786e4c30174924cee035b076cbe1eebb

Contents?: true

Size: 913 Bytes

Versions: 3

Compression:

Stored size: 913 Bytes

Contents

require_relative 'stroke'

module WhirledPeas
  module UI
    class Canvas
      attr_reader :left, :top, :width, :height

      def initialize(left, top, width, height)
        @left = left
        @top = top
        @width = width
        @height = height
      end

      def stroke(left, top, chars)
        if left >= self.left + self.width || left + chars.length <= self.left
          Stroke::EMPTY
        elsif top < self.top || top >= self.top + self.height
          Stroke::EMPTY
        else
          if left < self.left
            chars = chars[self.left - left..-1]
            left = self.left
          end
          num_chars = [self.left + self.width, left + chars.length].min - left
          Stroke.new(left, top, Ansi.first(chars, num_chars))
        end
      end

      def inspect
        "Canvas(left=#{left}, top=#{top}, width=#{width}, height=#{height})"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
whirled_peas-0.2.0 lib/whirled_peas/ui/canvas.rb
whirled_peas-0.1.1 lib/whirled_peas/ui/canvas.rb
whirled_peas-0.1.0 lib/whirled_peas/ui/canvas.rb