Module: Cura::Termbox::Pencil

Defined in:
lib/cura/termbox/pencil.rb

Overview

TODO: terminal_code(9) should be 9 or 256 depending on the termbox configuration

Instance Method Summary collapse

Instance Method Details

#draw_character(x, y, character, foreground = Cura::Color.black, background = Cura::Color.white, bold = false, underline = false) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cura/termbox/pencil.rb', line 37

def draw_character(x, y, character, foreground=Cura::Color.black, background=Cura::Color.white, bold=false, underline=false)
  x          = x.to_i
  y          = y.to_i
  foreground = ColorMapper.code(foreground, 256) if foreground.is_a?(Color)
  background = ColorMapper.code(background, 256) if background.is_a?(Color)

  character = character.to_s[0].codepoints.first
  character ||= 0

  foreground |= ::Termbox::TB_BOLD if bold
  foreground |= ::Termbox::TB_UNDERLINE if underline

  ::Termbox.tb_change_cell(x, y, character, foreground, background)
end

#draw_point(x, y, color = Cura::Color.black) ⇒ Object

Change a point relative to this component’s coordinates.



11
12
13
14
15
16
17
# File 'lib/cura/termbox/pencil.rb', line 11

def draw_point(x, y, color=Cura::Color.black)
  x     = x.to_i
  y     = y.to_i
  color = ColorMapper.code(color, 256) if color.is_a?(Color)

  ::Termbox.tb_change_cell(x, y, 0, color, color)
end

#draw_rectangle(x, y, width, height, color = Cura::Color.black) ⇒ Object

Change a rectangle of points relative to this component’s coordinates.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cura/termbox/pencil.rb', line 20

def draw_rectangle(x, y, width, height, color=Cura::Color.black)
  x      = x.to_i
  y      = y.to_i
  width  = width.to_i
  height = height.to_i
  color = ColorMapper.code(color, 256) if color.is_a?(Color)

  width  = 1 if width < 1
  height = 1 if height < 1

  width.times do |x_offset|
    height.times do |y_offset|
      ::Termbox.tb_change_cell(x + x_offset, y + y_offset, 0, color, color)
    end
  end
end

#draw_text(x, y, text, foreground = Cura::Color.black, background = Cura::Color.white, bold = false, underline = false) ⇒ Object



52
53
54
55
56
# File 'lib/cura/termbox/pencil.rb', line 52

def draw_text(x, y, text, foreground=Cura::Color.black, background=Cura::Color.white, bold=false, underline=false)
  text.to_s.each_char do |character|
    draw_character(x, y, character, foreground, background, bold, underline)
  end
end