Class: TermCanvas::Rect

Inherits:
Object
  • Object
show all
Defined in:
lib/term_canvas/rect.rb

Instance Attribute Summary collapse

Attributes inherited from Object

#index

Instance Method Summary collapse

Methods inherited from Object

#position_offset, #position_override, #set_index

Constructor Details

#initialize(x:, y:, width:, height:, background_color:) ⇒ Rect

Returns a new instance of Rect.

Parameters:

  • x (Integer)

    Horizontal position of the object.

  • y (Integer)

    Vertical position of the object.

  • background_color (Hash)

    :r Red element of color of background.

  • background_color (Hash)

    :g Green element of color of background.

  • background_color (Hash)

    :b Blue element of color of background.



10
11
12
13
14
15
16
# File 'lib/term_canvas/rect.rb', line 10

def initialize(x:, y:, width:, height:, background_color:)
  @x = x
  @y = y
  @width = width
  @height = height
  @background_color = background_color
end

Instance Attribute Details

#background_colorObject (readonly)

Returns the value of attribute background_color.



3
4
5
# File 'lib/term_canvas/rect.rb', line 3

def background_color
  @background_color
end

Instance Method Details

#draw(win) ⇒ Object

Parameters:

  • win (Curses::Window)

    Window to draw



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/term_canvas/rect.rb', line 23

def draw(win)
  color_pair_id = TermCanvas::BaseScreen.instance.find_or_create_color_pair(
    background_color: @background_color,
  ).id
  color_pair = Curses.color_pair(color_pair_id)
  win.setpos(@y, @x)
  win.attron(color_pair)
  @height.times do
    win.addstr(" " * @width)
    win.setpos(win.cury + 1, @x)
  end
  win.attroff(color_pair)
end

#foreground_colorObject



18
19
20
# File 'lib/term_canvas/rect.rb', line 18

def foreground_color
  nil
end