class MarsBase10::Viewport

Constants

CURSOR_INVISIBLE
CURSOR_VISIBLE

Attributes

controller[RW]
panes[R]
win[R]

Public Class Methods

new() click to toggle source
# File lib/mars_base_10/viewport.rb, line 15
def initialize
  Curses.init_screen
  Curses.curs_set(CURSOR_INVISIBLE)
  Curses.noecho   # Do not echo characters typed by the user.

  Curses.start_color if Curses.has_colors?
  Curses.init_pair(1, Curses::COLOR_RED, Curses::COLOR_BLACK)
  Curses.init_pair(2, Curses::COLOR_BLACK, Curses::COLOR_CYAN)

  @active_pane = nil
  @controller = nil

  @action_bar = nil
  @panes = []

  # this is the whole visible drawing surface.
  # we don't ever draw on this, but we need it for reference.
  @win = Curses::Window.new 0, 0, 0, 0
end

Public Instance Methods

action_bar() click to toggle source
# File lib/mars_base_10/viewport.rb, line 35
def action_bar
  return @action_bar unless @action_bar.nil?
  # Make a default action bar. Only movement for now.
  self.action_bar = ActionBar.new actions: {'j': 'Move Down', 'k': 'Move Up', 'q': 'Quit'}
end
action_bar=(an_action_bar) click to toggle source
# File lib/mars_base_10/viewport.rb, line 41
def action_bar=(an_action_bar)
  @action_bar = an_action_bar
  @action_bar.display_on viewport: self
  @action_bar
end
activate(pane:) click to toggle source
# File lib/mars_base_10/viewport.rb, line 47
def activate(pane:)
  @active_pane = pane
end
active_pane() click to toggle source

This is the pane in the Viewport which is actively accepting keyboard input.

# File lib/mars_base_10/viewport.rb, line 54
def active_pane
  @active_pane
end
add_pane(at_row: self.min_row, at_col: self.min_col, height_pct: 1, width_pct: 1) click to toggle source

Adds a new drawable area (Pane) to the viewport. By default it is anchored to the top left. (min_row, min_col)

and full screen. (height and width 100%)
# File lib/mars_base_10/viewport.rb, line 63
def add_pane(at_row: self.min_row, at_col: self.min_col, height_pct: 1, width_pct: 1)
  p = MarsBase10::Pane.new viewport:   self,
                           at_row:     at_row,
                           at_col:     at_col,
                           height_pct: height_pct,
                           width_pct:  width_pct
  @panes << p
  @active_pane = p
end
add_variable_both_pane(at_row: self.min_row, at_col: self.min_col) click to toggle source

Adds a new variable width drawable area (VariableBothPane) to the

right-hand side of the viewport.

The caller must specify the upper left corner (at_row, at_col) but

after that it will automatically adjust its width based upon how
many columns the left pane(s) use.
# File lib/mars_base_10/viewport.rb, line 90
def add_variable_both_pane(at_row: self.min_row, at_col: self.min_col)
  p = VariableBothPane.new viewport: self,
                             at_row: at_row,
                             at_col: at_col
  @panes << p
  p
end
add_variable_width_pane(at_row: self.min_row, at_col: self.min_col, height_pct:) click to toggle source
# File lib/mars_base_10/viewport.rb, line 73
def add_variable_width_pane(at_row: self.min_row, at_col: self.min_col, height_pct:)
  p = VariableWidthPane.new viewport: self,
                              at_row: at_row,
                              at_col: at_col,
                          height_pct: height_pct
  @panes << p
  p
end
close() click to toggle source
# File lib/mars_base_10/viewport.rb, line 98
def close
  Curses.close_screen
end
max_cols() click to toggle source
# File lib/mars_base_10/viewport.rb, line 102
def max_cols
  self.win.maxx
end
max_rows() click to toggle source
# File lib/mars_base_10/viewport.rb, line 106
def max_rows
  self.win.maxy - 1
end
min_col() click to toggle source
# File lib/mars_base_10/viewport.rb, line 110
def min_col
  0
end
min_row() click to toggle source
# File lib/mars_base_10/viewport.rb, line 114
def min_row
  0
end
open() click to toggle source
# File lib/mars_base_10/viewport.rb, line 118
def open
  loop do
    self.panes.each do |pane|
      pane.draw
      pane.window.refresh
    end
    self.action_bar.draw
    self.action_bar.window.refresh
    self.active_pane.process
  end
end