Class: Cliptic::Windows::Grid

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

Direct Known Subclasses

Interface::Logo, Main::Windows::Grid

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

Attributes inherited from Window

#centered_x, #centered_y, #col, #line, #x, #y

Instance Method Summary collapse

Methods inherited from Window

#bold, #clear, #color, #move, #refresh, #reset_attrs, #reset_pos, #setpos, #standend, #standout, #time_str, #wrap_str

Methods included from Chars

small_num

Constructor Details

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

Returns a new instance of Grid.



122
123
124
125
126
127
# File 'lib/cliptic/windows.rb', line 122

def initialize(y:, x:, line:nil, col:nil)
  @sq    = Pos.mk(y,x)
  @y, @x = sq_to_dims(y:y, x:x)
  super(y:@y, x:@x, line:line, col:col)
  @cells = make_cells(**sq)
end

Instance Attribute Details

#cellsObject (readonly)

Returns the value of attribute cells.



121
122
123
# File 'lib/cliptic/windows.rb', line 121

def cells
  @cells
end

#sqObject (readonly)

Returns the value of attribute sq.



121
122
123
# File 'lib/cliptic/windows.rb', line 121

def sq
  @sq
end

Instance Method Details

#add_str(str:, y: 0, x: 0) ⇒ Object



140
141
142
143
144
# File 'lib/cliptic/windows.rb', line 140

def add_str(str:, y:0, x:0)
  str.chars.each_with_index do |char, i|
    cell(y:y, x:x+i).write(char)
  end
end

#cell(y:, x:) ⇒ Object



145
146
147
# File 'lib/cliptic/windows.rb', line 145

def cell(y:, x:)
  cells[y][x]
end

#draw(cp: $colors[:grid]||0) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/cliptic/windows.rb', line 128

def draw(cp:$colors[:grid]||0)
  setpos.color(cp)
  1.upto(y) do |i|
    line = case i
    when 1 then top_border
    when y then bottom_border
    else i.even? ? side_border : inner_border
    end
    self << line
  end; setpos.color
  self
end