class TermCanvas::Text

Attributes

background_color[R]
foreground_color[R]

Public Class Methods

new(x:, y:, body:, foreground_color:, background_color:) click to toggle source

@param x [Integer] Horizontal position of the object. @param y [Integer] Vertical position of the object. @param body [String] Text body. @param foreground_color [Hash]

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

@param background_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/text.rb, line 16
def initialize(x:, y:, body:, foreground_color:, background_color:)
  @x = x
  @y = y
  @body = body
  @foreground_color = foreground_color
  @background_color = background_color
end

Public Instance Methods

draw(win) click to toggle source

@param win [Curses::Window] Window to draw

# File lib/term_canvas/text.rb, line 25
def draw(win)
  color_pair_id = TermCanvas::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