Class: Text

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:, body:, foreground_color:, background_color:) ⇒ Text

Returns a new instance of Text.

Parameters:

  • x (Integer)

    Horizontal position of the object.

  • y (Integer)

    Vertical position of the object.

  • body (String)

    Text body.

  • foreground_color (Hash)

    :r Red element of color of text. :g Green element of color of text. :b Blue element of color of text.

  • background_color (Hash)

    :r Red element of color of background. :g Green element of color of background. :b Blue element of color of background.



15
16
17
18
19
20
21
# File 'lib/term_canvas/text.rb', line 15

def initialize(x:, y:, body:, foreground_color:, background_color:)
  @x = x
  @y = y
  @body = body
  @foreground_color = foreground_color
  @background_color = background_color
end

Instance Attribute Details

#background_colorObject (readonly)

Returns the value of attribute background_color.



2
3
4
# File 'lib/term_canvas/text.rb', line 2

def background_color
  @background_color
end

#foreground_colorObject (readonly)

Returns the value of attribute foreground_color.



2
3
4
# File 'lib/term_canvas/text.rb', line 2

def foreground_color
  @foreground_color
end

Instance Method Details

#draw(win) ⇒ Object

Parameters:

  • win (Curses::Window)

    Window to draw



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

def draw(win)
  color_pair_id = BaseScreen.instance.find_or_create_color_pair(
    foreground_color: @foreground_color,
    background_color: @background_color,
  ).id
  color_pair = Curses.color_pair(color_pair_id)
  win.setpos(@y, @x)
  win.attron(color_pair)
  win.addstr(@body)
  win.attroff(color_pair)
end