Sha256: 45e1150a983a6868066f0b6ff7bcd81ad786e6174023fe226a2b603ba2d6ad09

Contents?: true

Size: 1.94 KB

Versions: 8

Compression:

Stored size: 1.94 KB

Contents

module Vedeu

  # Provides the mechanisms to clear an interface or group of interfaces.
  #
  module Clear

    # Clear the named interface.
    #
    class NamedInterface

      class << self

        # @return [void]
        # @see #initialize
        def render(name)
          new(name).render
        end
        alias_method :clear_by_name, :render
        alias_method :by_name, :render

      end # Eigenclass

      # Return a new instance of Vedeu::Clear::NamedInterface.
      #
      # @param name [String] The name of the interface to clear.
      # @return [Vedeu::Clear::NamedInterface]
      def initialize(name)
        @name = name
      end

      # @return [void]
      def render
        output
      end

      protected

      # @!attribute [r] name
      # @return [String]
      attr_reader :name

      private

      # @see Vedeu::Geometries#by_name
      def geometry
        @geometry ||= Vedeu.geometries.by_name(name)
      end

      # @see Vedeu::Interfaces#by_name
      def interface
        @interface ||= Vedeu.interfaces.by_name(name)
      end

      # For each visible line of the interface, set the foreground and
      # background colours to those specified when the interface was defined,
      # then starting write space characters over the area which the interface
      # occupies.
      #
      # @return [Array<Array<Vedeu::Views::Char>>]
      def output
        Vedeu.timer("Clearing: '#{name}'") do
          @y      = geometry.y
          @x      = geometry.x
          @width  = geometry.width
          @height = geometry.height
          @colour = interface.colour

          @clear ||= Array.new(@height) do |iy|
            Array.new(@width) do |ix|
              Vedeu::Views::Char.new(value:    ' ',
                                     colour:   @colour,
                                     position: [@y + iy, @x + ix])
            end
          end
        end
      end

    end # NamedInterface

  end # Clear

end # Vedeu

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vedeu-0.5.12 lib/vedeu/output/clear/named_interface.rb
vedeu-0.5.11 lib/vedeu/output/clear/named_interface.rb
vedeu-0.5.10 lib/vedeu/output/clear/named_interface.rb
vedeu-0.5.9 lib/vedeu/output/clear/named_interface.rb
vedeu-0.5.8 lib/vedeu/output/clear/named_interface.rb
vedeu-0.5.7 lib/vedeu/output/clear/named_interface.rb
vedeu-0.5.6 lib/vedeu/output/clear/named_interface.rb
vedeu-0.5.5 lib/vedeu/output/clear/named_interface.rb