Sha256: 53728f42fe53fed24be1c8e4da56f905ae1ac5cef5ba87a3b16f41d44f06a3a6

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

module Vedeu

  # The size of the terminal is a limitation. Defining a canvas means we have
  # more space to 'do stuff'.
  class Canvas

    include Singleton

    # @!attribute [r] yn
    # @return [Fixnum]
    attr_reader :yn
    alias_method :bottom, :yn
    alias_method :height, :yn

    # @!attribute [r] xn
    # @return [Fixnum]
    attr_reader :xn
    alias_method :right, :xn
    alias_method :width, :xn

    # @return [Vedeu::Canvas]
    def self.canvas
      instance
    end

    # @param yn [Fixnum]
    # @param xn [Fixnum]
    # @return [Vedeu::Canvas]
    def configure(yn, xn)
      @yn = yn
      @xn = xn

      self
    end

    # @return [Array]
    def c
      [cy, cx]
    end
    alias_method :centre, :c

    # @return [Fixnum]
    def cy
      (height / 2) + y
    end
    alias_method :centre_y, :cy

    # @return [Fixnum]
    def cx
      (width / 2) + x
    end
    alias_method :centre_x, :cx

    # @return [Fixnum]
    def o
      1
    end
    alias_method :origin, :o

    # @return [Fixnum]
    def height
      (y..yn).size
    end

    # @return [Fixnum]
    def width
      (x..xn).size
    end

    # @return [Fixnum]
    def y
      1
    end
    alias_method :top, :y

    # @return [Fixnum]
    def x
      1
    end
    alias_method :left, :x

  end # Canvas

end # Vedeu

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
vedeu-0.4.28 lib/vedeu/geometry/canvas.rb
vedeu-0.4.27 lib/vedeu/geometry/canvas.rb
vedeu-0.4.26 lib/vedeu/geometry/canvas.rb
vedeu-0.4.25 lib/vedeu/geometry/canvas.rb
vedeu-0.4.24 lib/vedeu/geometry/canvas.rb
vedeu-0.4.23 lib/vedeu/geometry/canvas.rb
vedeu-0.4.22 lib/vedeu/geometry/canvas.rb
vedeu-0.4.21 lib/vedeu/geometry/canvas.rb
vedeu-0.4.20 lib/vedeu/geometry/canvas.rb
vedeu-0.4.19 lib/vedeu/geometry/canvas.rb