Class: Cliptic::Windows::Window

Inherits:
Curses::Window
  • Object
show all
Includes:
Chars
Defined in:
lib/cliptic/windows.rb

Constant Summary

Constants included from Chars

Chars::Block, Chars::HL, Chars::LL, Chars::LS, Chars::LU, Chars::MS, Chars::Nums, Chars::RL, Chars::RS, Chars::RU, Chars::TD, Chars::TL, Chars::TR, Chars::TU, Chars::Tick, Chars::VL, Chars::XX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Chars

small_num

Constructor Details

#initialize(y: 0, x: 0, line: nil, col: nil) ⇒ Window

Returns a new instance of Window.



7
8
9
10
11
12
13
14
# File 'lib/cliptic/windows.rb', line 7

def initialize(y:0, x:0, line:nil, col:nil)
  @y, @x = wrap_dims(y:y, x:x)
  @line,@col= center_pos(y:y,x:x,line:line,col:col)
  @centered_y, @centered_x = [line, col]
    .map{|pos| pos.nil?}
  super(@y, @x, @line, @col)
  keypad(true)
end

Instance Attribute Details

#centered_xObject (readonly)

Returns the value of attribute centered_x.



6
7
8
# File 'lib/cliptic/windows.rb', line 6

def centered_x
  @centered_x
end

#centered_yObject (readonly)

Returns the value of attribute centered_y.



6
7
8
# File 'lib/cliptic/windows.rb', line 6

def centered_y
  @centered_y
end

#colObject (readonly)

Returns the value of attribute col.



5
6
7
# File 'lib/cliptic/windows.rb', line 5

def col
  @col
end

#lineObject (readonly)

Returns the value of attribute line.



5
6
7
# File 'lib/cliptic/windows.rb', line 5

def line
  @line
end

#xObject (readonly)

Returns the value of attribute x.



5
6
7
# File 'lib/cliptic/windows.rb', line 5

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



5
6
7
# File 'lib/cliptic/windows.rb', line 5

def y
  @y
end

Instance Method Details

#add_str(str:, y: line, x: (@x-str.length)/2, cp: nil, bold: false) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/cliptic/windows.rb', line 46

def add_str(str:,y:line,x:(@x-str.length)/2, cp:nil, bold:false)
  color(cp) if cp 
  setpos(*wrap_str_dims(y:y, x:x, str:str))
  bold(bold)
  self << str
  noutrefresh
  reset_attrs
end

#bold(on = true) ⇒ Object



31
32
33
34
35
36
# File 'lib/cliptic/windows.rb', line 31

def bold(on=true)
  on ?
    attron(Curses::A_BOLD)  : 
    attroff(Curses::A_BOLD)
  self
end

#clearObject



54
55
56
57
58
# File 'lib/cliptic/windows.rb', line 54

def clear
  erase
  noutrefresh
  self
end

#color(cp = 0) ⇒ Object



28
29
30
# File 'lib/cliptic/windows.rb', line 28

def color(cp=0)
  color_set(cp); self
end

#draw(cp: $colors[:box]||0, clr: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cliptic/windows.rb', line 15

def draw(cp:$colors[:box]||0, clr:false)
  erase if clr
  setpos.color(cp)
  1.upto(y) do |i|
    line = case i
    when 1 then top_border
    when y then bottom_border
    else side_border
    end
    self << line
  end; setpos.color.noutrefresh
  self
end

#move(line: nil, col: nil) ⇒ Object



82
83
84
# File 'lib/cliptic/windows.rb', line 82

def move(line:nil, col:nil)
  super(*center_pos(y:y, x:x, line:line, col:col))
end

#refreshObject



71
72
73
# File 'lib/cliptic/windows.rb', line 71

def refresh
  super; self
end

#reset_attrsObject



67
68
69
70
# File 'lib/cliptic/windows.rb', line 67

def reset_attrs
  color(0).bold(false)
  self
end

#reset_posObject



74
75
76
77
78
79
80
81
# File 'lib/cliptic/windows.rb', line 74

def reset_pos
  move(
    *[centered_y, centered_x]
    .zip(total_dims, [y, x], [line, col])
    .map{|cent, tot, dim, pos| cent ? (tot-dim)/2 : pos}
  )
  refresh
end

#setpos(y = 0, x = 0) ⇒ Object



43
44
45
# File 'lib/cliptic/windows.rb', line 43

def setpos(y=0, x=0)
  super(y,x); self
end

#standendObject



88
89
90
# File 'lib/cliptic/windows.rb', line 88

def standend
  color($colors[:menu_inactive])
end

#standoutObject



85
86
87
# File 'lib/cliptic/windows.rb', line 85

def standout
  color($colors[:menu_active])
end

#time_str(str:, y:, x: (@x-str.length)/2, t: 5, cp: nil, bold: false) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/cliptic/windows.rb', line 59

def time_str(str:, y:, x:(@x-str.length)/2, t:5, cp:nil, bold:false)
  Thread.new{
    add_str(str:str, y:y, x:x, cp:cp, bold:bold)
    sleep(t)
    add_str(str:" "*str.length, y:y, x:x, cp:cp, bold:bold)
  }
  self
end

#wrap_str(str:, line:) ⇒ Object



37
38
39
40
41
42
# File 'lib/cliptic/windows.rb', line 37

def wrap_str(str:, line:)
  split_str(str).each_with_index do |l, i|
    setpos(line+i, 2)
    self << l
  end; self
end