Class: RETerm::Window
- Inherits:
-
Object
- Object
- RETerm::Window
- Includes:
- EventDispatcher
- Defined in:
- lib/reterm/window.rb
Overview
Windows are areas rendered on screen, associated with components to be rendered in them. They specify the position to start drawing component as well as the maximum width and height. A border may be drawn around a window and a ColorPair associated.
If Layout is added to a Window, children may subsequently be added. This should be performed via the Layout#add_child method.
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#cols ⇒ Object
Return window cols.
-
#component ⇒ Object
Returns the value of attribute component.
-
#hborder ⇒ Object
Returns the value of attribute hborder.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#rows ⇒ Object
Return window rows.
-
#vborder ⇒ Object
Returns the value of attribute vborder.
-
#win ⇒ Object
readonly
Returns the value of attribute win.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
-
.all ⇒ Object
Static method returning all tracked windows.
-
.top ⇒ Object
Static method returning top level windows.
Instance Method Summary collapse
-
#activate! ⇒ Object
Activate window component.
-
#border! ⇒ Object
Draw Border around window.
-
#cdk? ⇒ Boolean
Return bool indicating if cdk is enabled for this window/component.
-
#cdk_scr ⇒ Object
Return cdk screen (only used by CDK components).
-
#clear! ⇒ Object
Clear window by removing all children and reinitializing window space.
-
#colored? ⇒ Boolean
Return bool indiciating if colors are set.
-
#colors=(c) ⇒ Object
Set window color.
-
#component? ⇒ Boolean
Return bool indicating if this window has a component associated with it.
-
#create_child(h = {}) ⇒ Object
Create child window, this method should not be invoked by end-user, rather it is is invoked the Layout#add_child is called.
-
#del_child(child) ⇒ Object
Remove child window, like #add_child, this is used internally and should not be invoked by the end user.
-
#dimensions ⇒ Object
Return window dimensions as an array containing rows & cols.
-
#draw! ⇒ Object
Draw component in window.
-
#erase ⇒ Object
Erase window drawing area.
-
#finalize! ⇒ Object
Invoke window finalization routine by destroying it and all children.
-
#getch ⇒ Object
Blocking call to capture next character from window.
-
#initialize(args = {}) ⇒ Window
constructor
Instantiate Window with given args.
-
#mvaddstr(*a) ⇒ Object
Write string at specified loc.
-
#no_border! ⇒ Object
Remove Border around window.
-
#parent? ⇒ Boolean
Return boolean if this window is a child of another.
-
#refresh ⇒ Object
Refresh / resynchronize window and all children.
Methods included from EventDispatcher
Constructor Details
#initialize(args = {}) ⇒ Window
Instantiate Window with given args. None are required, but unless :rows, :cols, :x, or :y is specified, window will be created in it’s default position.
This method will generate a unique id for each window and add it to a static registery for subsequent tracking.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/reterm/window.rb', line 80 def initialize(args={}) @@registry ||= [] @@registry << self @rows = args[:rows] || (Terminal.rows - 1) @cols = args[:cols] || (Terminal.cols - 1) @x = args[:x] || 0 @y = args[:y] || 0 @vborder = args[:vborder] || 0 @hborder = args[:hborder] || 0 self.component = args[:component] if args.key?(:component) if args[:parent] @parent = args[:parent] @win = parent.win.derwin(@rows, @cols, @y, @x) else @parent = nil @win = Ncurses::WINDOW.new(@rows, @cols, @y, @x) end Ncurses::keypad(@win, true) @children = [] @@wid ||= 0 @@wid += 1 @window_id = @@wid end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
40 41 42 |
# File 'lib/reterm/window.rb', line 40 def children @children end |
#cols ⇒ Object
Return window cols
246 247 248 |
# File 'lib/reterm/window.rb', line 246 def cols @cols end |
#component ⇒ Object
Returns the value of attribute component.
35 36 37 |
# File 'lib/reterm/window.rb', line 35 def component @component end |
#hborder ⇒ Object
Returns the value of attribute hborder.
33 34 35 |
# File 'lib/reterm/window.rb', line 33 def hborder @hborder end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
39 40 41 |
# File 'lib/reterm/window.rb', line 39 def parent @parent end |
#rows ⇒ Object
Return window rows
241 242 243 |
# File 'lib/reterm/window.rb', line 241 def rows @rows end |
#vborder ⇒ Object
Returns the value of attribute vborder.
32 33 34 |
# File 'lib/reterm/window.rb', line 32 def vborder @vborder end |
#win ⇒ Object (readonly)
Returns the value of attribute win.
37 38 39 |
# File 'lib/reterm/window.rb', line 37 def win @win end |
#x ⇒ Object
Returns the value of attribute x.
30 31 32 |
# File 'lib/reterm/window.rb', line 30 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
30 31 32 |
# File 'lib/reterm/window.rb', line 30 def y @y end |
Class Method Details
.all ⇒ Object
Static method returning all tracked windows
137 138 139 140 |
# File 'lib/reterm/window.rb', line 137 def self.all @@registry ||= [] @@registry end |
.top ⇒ Object
Static method returning top level windows
143 144 145 146 |
# File 'lib/reterm/window.rb', line 143 def self.top @@registry ||= [] @@registry.select { |w| !w.parent? } end |
Instance Method Details
#activate! ⇒ Object
Activate window component
256 257 258 |
# File 'lib/reterm/window.rb', line 256 def activate! component.activate! end |
#border! ⇒ Object
Draw Border around window
196 197 198 |
# File 'lib/reterm/window.rb', line 196 def border! @win.box(@vborder, @hborder) end |
#cdk? ⇒ Boolean
Return bool indicating if cdk is enabled for this window/component
132 133 134 |
# File 'lib/reterm/window.rb', line 132 def cdk? !!@cdk_scr end |
#cdk_scr ⇒ Object
Return cdk screen (only used by CDK components)
126 127 128 129 |
# File 'lib/reterm/window.rb', line 126 def cdk_scr enable_cdk! @cdk_scr ||= CDK::SCREEN.new(@win) end |
#clear! ⇒ Object
Clear window by removing all children and reinitializing window space
168 169 170 171 172 173 174 175 |
# File 'lib/reterm/window.rb', line 168 def clear! children.each { |c| del_child(c) } @children = [] erase end |
#colored? ⇒ Boolean
Return bool indiciating if colors are set
211 212 213 |
# File 'lib/reterm/window.rb', line 211 def colored? !!@colors end |
#colors=(c) ⇒ Object
Set window color
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/reterm/window.rb', line 216 def colors=(c) @colors = c.is_a?(ColorPair) ? c : ColorPair.for(c) @win.bkgd(Ncurses.COLOR_PAIR(@colors.id)) component.colors = @colors if component? children.each { |ch| ch.colors = c } end |
#component? ⇒ Boolean
Return bool indicating if this window has a component associated with it
44 45 46 |
# File 'lib/reterm/window.rb', line 44 def component? !!@component end |
#create_child(h = {}) ⇒ Object
Create child window, this method should not be invoked by end-user, rather it is is invoked the Layout#add_child is called.
151 152 153 154 155 156 |
# File 'lib/reterm/window.rb', line 151 def create_child(h={}) c = self.class.new h.merge(:parent => self) c.colors = @colors if colored? children << c c end |
#del_child(child) ⇒ Object
Remove child window, like #add_child, this is used internally and should not be invoked by the end user
160 161 162 163 164 165 |
# File 'lib/reterm/window.rb', line 160 def del_child(child) @children.delete(child) @@registry.delete(child) child.finalize! child.win.delwin end |
#dimensions ⇒ Object
Return window dimensions as an array containing rows & cols
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/reterm/window.rb', line 228 def dimensions @dimensions ||= begin rows = [] cols = [] @win.getmaxyx(rows, cols) rows = rows.first cols = cols.first [rows, cols] end end |
#draw! ⇒ Object
Draw component in window
251 252 253 |
# File 'lib/reterm/window.rb', line 251 def draw! component.draw! if component? end |
#erase ⇒ Object
Erase window drawing area
178 179 180 |
# File 'lib/reterm/window.rb', line 178 def erase @win.werase end |
#finalize! ⇒ Object
Invoke window finalization routine by destroying it and all children
117 118 119 120 121 122 123 |
# File 'lib/reterm/window.rb', line 117 def finalize! children.each { |c| del_child c cdk_scr.destroy if cdk? component.finalize! if component? } end |
#getch ⇒ Object
Blocking call to capture next character from window
201 202 203 |
# File 'lib/reterm/window.rb', line 201 def getch @win.getch end |
#mvaddstr(*a) ⇒ Object
Write string at specified loc
206 207 208 |
# File 'lib/reterm/window.rb', line 206 def mvaddstr(*a) @win.mvaddstr(*a) end |
#no_border! ⇒ Object
Remove Border around window
191 192 193 |
# File 'lib/reterm/window.rb', line 191 def no_border! @win.border(' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord, ' '.ord) end |
#parent? ⇒ Boolean
Return boolean if this window is a child of another
57 58 59 |
# File 'lib/reterm/window.rb', line 57 def parent? !!@parent end |
#refresh ⇒ Object
Refresh / resynchronize window and all children
183 184 185 186 187 188 |
# File 'lib/reterm/window.rb', line 183 def refresh @win.refresh children.each { |c| c.refresh } end |