Module: Visuals

Includes:
Ncurses, SDL2
Defined in:
lib/curses.rb,
lib/frontend.rb,
lib/graphical.rb

Constant Summary collapse

KEY_ESCAPE =
27
KEY_RETURN =
10
KEY_TAB =
9
KEY_PAGEDOWN =
KEY_NPAGE
KEY_PAGEUP =
KEY_PPAGE
KEY_INSERT =
KEY_IC
KEY_DELETE =
KEY_DC
COLORS =

COLORS = { black: [ 0, 0, 0], red: [ 700, 400, 400], green: [ 400, 700, 400], yellow: [ 700, 700, 400], blue: [ 400, 400, 700], magenta: [ 700, 400, 700], cyan: [ 400, 700, 700], white: [ 999, 999, 999], grey: [ 618, 618, 618] }

{ 
black:   [   0,    0,    0],
red:     [ 180,  100,  100],
green:   [ 100,  180,  100],
yellow:  [ 180,  180,  100],
blue:    [ 100,  100,  180],
magenta: [ 180,  100,  180],
cyan:    [ 100,  180,  180],
white:   [ 255,  255,  255],
grey:    [ 158,  158,  158] }
WINDOW =
Window.create("visuals", 
Window::POS_CENTERED, #POS_UNDEFINED,
Window::POS_CENTERED, #POS_UNDEFINED,
1324, 768, 0)
GO =
WINDOW.create_renderer(-1, 
Renderer::Flags::ACCELERATED|Renderer::Flags::TARGETTEXTURE)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.columnObject



38
# File 'lib/curses.rb', line 38

def self.column; Ncurses.getcurx $creen end

.exitObject



40
41
42
43
44
45
46
# File 'lib/curses.rb', line 40

def self.exit
  Ncurses.echo
  Ncurses.nocbreak
  Ncurses.nl
  Ncurses.endwin
#    system "reset"
end

.heightObject



36
# File 'lib/curses.rb', line 36

def self.height; Ncurses.LINES end

.init(args = {}) ⇒ Object

def color_pair pair if id = $color_pairs.index( pair ) return id else last = ( $color_pairs << c ).count - 1 Ncurses.init_pair( last, *pair ) return last end pair = p.map{ |col| unless id = $colors.index( col ) id = ($colors << col).count - 1 Ncurses.init_color id, *col end id }
unless ( id = $color_pairs.index( pair ) ) id = ( $color_pairs << pair ).count - 1 Ncurses.init_pair id, *pair end id end



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/curses.rb', line 114

def self.init args={} 
#    SCREEN = Ncurses.initscr
  $creen = Ncurses.initscr
  Ncurses.cbreak           # provide unbuffered input
  Ncurses.noecho             # turn on input echoing
  Ncurses.nl             # turn on newline translation
#    Ncurses.nonl             # turn off newline translation
  Ncurses.curs_set 0
  Ncurses.start_color
  Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt
  Ncurses.stdscr.keypad(true)     # turn on keypad mode

  $default = [ 
    color_for( args[:foreground] || :grey80 ), 
    color_for( args[:background] || :grey10 ) ]
  $color = $default.dup

  COLORS.each_with_index{ |c,i| 
    $pairs << [ i, $default[1] ] 
    Ncurses.init_color i, *c[1] 
    Ncurses.init_pair i, i, $default[1] }
  
  Ncurses.bkgd Ncurses::COLOR_PAIR( pair_for $default )

end

.rowObject



37
# File 'lib/curses.rb', line 37

def self.row; Ncurses.getcury $creen end

.widthObject



35
# File 'lib/curses.rb', line 35

def self.width;  Ncurses.COLS end

.xObject



28
# File 'lib/graphical.rb', line 28

def self.x; $x end

.yObject



29
# File 'lib/graphical.rb', line 29

def self.y; $y end

Instance Method Details

#background(color) ⇒ Object



81
82
83
# File 'lib/curses.rb', line 81

def background color; 
  $color[1] = (color ? color_for( color ) : $default[1]); change  
end

#changeObject



76
# File 'lib/curses.rb', line 76

def change; Ncurses.color_set pair_for( $color ), 0 end

#clear(type = :screen) ⇒ Object

bg=



58
59
60
61
62
63
64
# File 'lib/graphical.rb', line 58

def clear type=:screen; 
  case type 
    when :screen; Ncurses.erase
    when :line; Ncurses.clrtoeol
    when :down; Ncurses.clrtobot
  end 
end

#color(c) ⇒ Object



88
89
90
91
92
# File 'lib/curses.rb', line 88

def color c
  c = [c] unless c.is_a? Array and c.count == 2
  foreground c[0] if c[0] 
  background c[1] if c[1] 
end

#color_for(c) ⇒ Object



32
33
34
35
36
# File 'lib/graphical.rb', line 32

def color_for c
  return unless c
  c = COLORS[c] if c.is_a?( Symbol )
  c.map{ |c| (c/1000.0*256).to_i }
end

#disable(attr) ⇒ Object



68
# File 'lib/curses.rb', line 68

def disable attr; Ncurses.attroff attr end

#enable(attr) ⇒ Object



67
# File 'lib/curses.rb', line 67

def enable attr; Ncurses.attron attr end

#foreground(color) ⇒ Object



84
85
86
# File 'lib/curses.rb', line 84

def foreground color; 
  $color[0] = (color ? color_for( color ) : $default[0]); change 
end

#get_backgroundObject



79
# File 'lib/curses.rb', line 79

def get_background; $color[1] end

#get_foregroundObject



80
# File 'lib/curses.rb', line 80

def get_foreground; $color[0] end

#move(col, row) ⇒ Object



65
# File 'lib/curses.rb', line 65

def move x=0,y=0; Ncurses.move y, x end

#read(input) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/curses.rb', line 48

def read input 
  case input
    when :key
      key = Ncurses.getch 
      key = key.chr if key.between? 32, 126 
      return key
    when :line #string
      Ncurses.echo
      Ncurses.curs_set 1        
#        Ncurses.getstr str=""
      str = Readline.readline
      Ncurses.curs_set 0
      Ncurses.noecho
      return str
  end
end

#refreshObject



66
# File 'lib/curses.rb', line 66

def refresh; Ncurses.refresh end

#show(str) ⇒ Object

solid_blended_shaded(



70
# File 'lib/graphical.rb', line 70

def show string; Ncurses.addstr string.to_s end