class TermCanvas::Canvas

Attributes

height[RW]
width[RW]

Public Class Methods

new(x:, y:, w:, h:) click to toggle source

Create a convenient window. @param x [Integer] Horizontal position of the window. From left to right. @param y [Integer] Vertical position of the window. From top to bottom. @param w [Integer] Width of the window. @param h [Integer] Height of the window.

# File lib/term_canvas.rb, line 45
def initialize(x:, y:, w:, h:)
  TermCanvas::BaseScreen.instance
  @win = Curses::Window.new(h, w, y, x)
  @x = x
  @y = y
  @width = w
  @height = h
  @objects = []
  @object_index = 0
end

Public Instance Methods

background(color) click to toggle source

@param color [Hash]

:r Red element of color of background.
:g Green element of color of background.
:b Blue element of color of background.
# File lib/term_canvas.rb, line 94
def background(color)
  object = TermCanvas::Rect.new(
    x: 0, y: 0, width: @width - 1, height: @height,
    background_color: color,
  )
  object.set_index(@object_index)
  @objects << object
  @object_index += 1
end
centerx() click to toggle source

@return [Integer] Horizontal center of the window.

# File lib/term_canvas.rb, line 64
def centerx
  @width / 2
end
centery() click to toggle source

@return [Integer] Vertical center of the window.

# File lib/term_canvas.rb, line 69
def centery
  @height / 2
end
clear() click to toggle source

Clear objects and remove from the window.

# File lib/term_canvas.rb, line 57
def clear
  @win.clear
  @objects = []
  @object_index = 0
end
close() click to toggle source
# File lib/term_canvas.rb, line 110
def close
  @win.close
end
rect(object) click to toggle source

Add rect object to the window but not display.

# File lib/term_canvas.rb, line 83
def rect(object)
  raise 'The argument must be Rect' if !(TermCanvas::Rect === object)
  object.set_index(@object_index)
  @objects << object
  @object_index += 1
end
text(object) click to toggle source

Add text object to the window but not display. @param object [Text] Text instance

# File lib/term_canvas.rb, line 75
def text(object)
  raise 'The argument must be Text' if !(TermCanvas::Text === object)
  object.set_index(@object_index)
  @objects << object
  @object_index += 1
end
update() click to toggle source

Update objects to the virtual screen.

# File lib/term_canvas.rb, line 105
def update
  draw
  @win.noutrefresh
end

Private Instance Methods

draw() click to toggle source
# File lib/term_canvas.rb, line 116
def draw
  @objects.each do |object|
    object.draw(@win)
  end
end