Sha256: 9a9651b02bb56bba692215db6b11de3a9bbc328d9ca199ab7cad4fd51e70cccc

Contents?: true

Size: 955 Bytes

Versions: 6

Compression:

Stored size: 955 Bytes

Contents

require_relative 'canvas'

module WhirledPeas
  module Graphics
    class Renderer
      def initialize(template, width, height)
        @template = template
        @width = width
        @height = height
      end

      def paint
        # Modify the template's settings so that it fills the entire screen
        template.settings.width = width
        template.settings.height = height
        template.settings.sizing = :border
        template.settings.set_margin(left: 0, top: 0, right: 0, bottom: 0)
        strokes = [Utils::Ansi.cursor_visible(false), Utils::Ansi.cursor_pos, Utils::Ansi.clear_down]
        template.paint(Canvas.new(0, 0, width, height), 0, 0) do |left, top, fstring|
          next unless fstring.length > 0
          strokes << Utils::Ansi.cursor_pos(left: left, top: top)
          strokes << fstring
        end
        strokes.join
      end

      private

      attr_reader :template, :width, :height
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
whirled_peas-0.11.1 lib/whirled_peas/graphics/renderer.rb
whirled_peas-0.11.0 lib/whirled_peas/graphics/renderer.rb
whirled_peas-0.10.0 lib/whirled_peas/graphics/renderer.rb
whirled_peas-0.9.1 lib/whirled_peas/graphics/renderer.rb
whirled_peas-0.9.0 lib/whirled_peas/graphics/renderer.rb
whirled_peas-0.8.0 lib/whirled_peas/graphics/renderer.rb