Class: VER::Pad
Overview
Pad This is EXPERIMENTAL A pad cannot be used interchangeable since some application functions such as wrefresh are illegal. Cannot expect the application to take care. Internally we can make it easier. Mostly a pad is used to map to one portion of the screen. So we allow that to be defined once. Then only start row and col of pad change. Maybe we should check pad coordinates so no errors Also check screen coordinates (if we know) We need padheight and padwidth only to ensure we don’t keep recreating. Howevre, when comp’s height increases, then decreases, pad height remains larger but we keep printing an extra row in copywin. so Pad needs to maintain comp height and padheight.
Instance Attribute Summary collapse
-
#left ⇒ Object
top and left correspond to screen’s top and left wich will mostly be fixed.
- #otherwin ⇒ Object readonly
-
#padheight ⇒ Object
readonly
dimensions the pad was created with, used so we don’t keep recreating pad, only if increase.
-
#padwidth ⇒ Object
readonly
dimensions the pad was created with, used so we don’t keep recreating pad, only if increase.
-
#pmincol ⇒ Object
start row and col correspond to pad’s top and left which will change if scrolling.
-
#pminrow ⇒ Object
start row and col correspond to pad’s top and left which will change if scrolling.
-
#sheight ⇒ Object
screen’s height and width, now it reflects components height and width.
-
#swidth ⇒ Object
screen’s height and width, now it reflects components height and width.
-
#top ⇒ Object
top and left correspond to screen’s top and left wich will mostly be fixed.
Attributes inherited from Window
#height, #layout, #modified, #name, #panel, #width, #window_type
Class Method Summary collapse
-
.create_for_window(win) ⇒ Object
used if pad and window are same size only creates a similar sized window assumes window is backed by this pad.
- .create_with_layout(layout) ⇒ Object
Instance Method Summary collapse
-
#copy_pad_to_win ⇒ Object
copy the window to the pad (assumes we are writing onto win and keeping pad as backup also assuming only one win so, window not passed as param.
- #copy_win_to_pad ⇒ Object
- #init_vars ⇒ Object
-
#initialize(height, width) ⇒ Pad
constructor
attr_accessor :name # more for debugging log files.
-
#overwrite_window ⇒ Object
Used to overwrite the pad onto the screen window A window should have been specified as window to back (@see set_backing_window) or (@see create_with_window).
-
#print_border(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
convenience method so that pad can use print_border but remove screen’s row and col Please note that this requires that buffer have latest top and left.
- #print_border_only(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
-
#printstring(row, col, value, color, attrib = Ncurses::A_NORMAL) ⇒ Object
Pls remove the raise once the program is working, extra line can slow things down Keep it on when testing.
-
#rb_mvaddch(row, col, char) ⇒ Object
use in place of mvaddch if your widget could be using a pad or window.
-
#rb_mvwhline(row, col, char, width) ⇒ Object
use in place of mvwhline if your widget could be using a pad or window.
-
#rb_mvwvline(row, col, char, width) ⇒ Object
use in place of mvwvline if your widget could be using a pad or window.
-
#resize(ht = 0, w = 0) ⇒ Pad
increases the pad size, since the widget may have been resized checks that one of ht or width has been increased destroys earlier pad and returns new one Updates sheight and swidth even if reduced so copywin works fine.
-
#set_backing_window(win) ⇒ Object
specify the window or subwin that the pad is writing to 2010-02-20 22:45 - actually since there are pad methods smaxrow used on otherwin therefor it can only be a Pad !! NOTE.
-
#set_pad_top_left(top, left = -1) ⇒ Object
start row and col correspond to pad’s top and left which will change if scrolling However, if we use this as a backing store for subwindows it could remain the same.
-
#set_screen_max_row_col(mr, mc) ⇒ Object
added user setting screens max row and col (e.g splitpanes first component).
-
#set_screen_row_col(top, left = -1) ⇒ Object
(also: #set_screen_pad_left)
top and left correspond to screen’s top and left wich will mostly be fixed.
-
#smaxcol ⇒ Object
return screen max col which will be used for writing to window.
-
#smaxrow ⇒ Object
return screen max row which will be used for writing to window XXX what if user sets/overrides sheight.
-
#wrefresh ⇒ Object
trying to make things as easy as possible returns -1 if error in prefresh.
Methods inherited from Window
#_subwin, #clear, #clear_error, #color=, create_window, #default_for, #derwin, #destroy, #get_window, #getch, #getchar, #hide, #highlight_line, #layout_value, #method_missing, #move, #on_top, #pos, #print, #print_border_mb, #print_empty_line, #print_error_message, #print_line, #print_status_message, #print_yx, #prv_print_border_only, #prv_printstring, #puts, #refresh, #reset_layout, #resize_with, root_window, #show, #show_colored_chunks, #to_s, #ungetch, #visible?, #wnoutrefresh, #x, #x=, #y, #y=
Constructor Details
#initialize(height, width) ⇒ Pad
attr_accessor :name # more for debugging log files. 2010-02-02 19:58
539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/ver/window.rb', line 539 def initialize(height, width) @visible = true # do we set height and width ?? XXX @window = Ncurses.newpad(height, width) @padheight = height @padwidth = width @height = height @width = width @sheight = height @swidth = width init_vars end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class VER::Window
Instance Attribute Details
#left ⇒ Object
top and left correspond to screen’s top and left wich will mostly be fixed
530 531 532 |
# File 'lib/ver/window.rb', line 530 def left @left end |
#otherwin ⇒ Object (readonly)
535 536 537 |
# File 'lib/ver/window.rb', line 535 def otherwin @otherwin end |
#padheight ⇒ Object (readonly)
dimensions the pad was created with, used so we don’t keep recreating pad, only if increase.
537 538 539 |
# File 'lib/ver/window.rb', line 537 def padheight @padheight end |
#padwidth ⇒ Object (readonly)
dimensions the pad was created with, used so we don’t keep recreating pad, only if increase.
537 538 539 |
# File 'lib/ver/window.rb', line 537 def padwidth @padwidth end |
#pmincol ⇒ Object
start row and col correspond to pad’s top and left which will change if scrolling
532 533 534 |
# File 'lib/ver/window.rb', line 532 def pmincol @pmincol end |
#pminrow ⇒ Object
start row and col correspond to pad’s top and left which will change if scrolling
532 533 534 |
# File 'lib/ver/window.rb', line 532 def pminrow @pminrow end |
#sheight ⇒ Object
screen’s height and width, now it reflects components height and width
534 535 536 |
# File 'lib/ver/window.rb', line 534 def sheight @sheight end |
#swidth ⇒ Object
screen’s height and width, now it reflects components height and width
534 535 536 |
# File 'lib/ver/window.rb', line 534 def swidth @swidth end |
#top ⇒ Object
top and left correspond to screen’s top and left wich will mostly be fixed
530 531 532 |
# File 'lib/ver/window.rb', line 530 def top @top end |
Class Method Details
.create_for_window(win) ⇒ Object
used if pad and window are same size only creates a similar sized window assumes window is backed by this pad
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/ver/window.rb', line 593 def self.create_for_window(win) # get coordinates for win @otherwin = win smaxx = win.getmaxx() smaxy = win.getmaxy() top = win.getminx() left = win.getminy() sheight = win.height swidth = win.width # make pad based on size of window window = Pad.create_with_layout(layout = { :height => sheight, :width => swidth, :top => top, :left => sleft }) window.sheight = sheight window.swidth = swidth return window end |
Instance Method Details
#copy_pad_to_win ⇒ Object
copy the window to the pad (assumes we are writing onto win and keeping pad as backup also assuming only one win so, window not passed as param
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/ver/window.rb', line 682 def copy_pad_to_win # check that we don't exceed other windows height/maxrow smr = smaxrow() # SHIT, this means the otherwin has to be a Pad, cannot be a window osw = @otherwin.width osh = @otherwin.height osh = @height if osh == 0 # root window has 0 osw = @width if osw == 0 # root window has 0 osmr = @otherwin.smaxrow() rescue osh # TRYING for windows osmc = @otherwin.smaxcol() rescue osw if smr >= osmr $log.debug " adjusted smr from #{smr} to #{osmr} -1 causing issues in viewfooter" smr = osmr-1 # XXX causing issues in viewport, wont print footer with this end if smr > @sheight + @top -1 -@pminrow # 2010-01-17 13:27 smr = @sheight + @top -1 -@pminrow $log.debug " adjusted smr to #{smr} to prevent crash " end smc = smaxcol() $log.debug " SMC original = #{smc} " if smc >= osmc smc = osmc-1 smc = @width # XXX ??? THIS WAS WORKING< but throwing error in viewport case smc = [osmc-1, @width].min # yet another hack $log.debug " SMC o-1 #{osmc-1} wdth #{@width}, smc #{smc} " end ### XXX commented out since it doesn't let a comp print fully if widget expanded (splitpane) #smc = osw -1 if smc >= osw; # added 2009-11-02 17:01 for tabbedpanes # dang, this is coming up a lot. 2010-01-16 20:34 # the second scrollpane was one row too large in testsplit3a.rb if smr - @top > @padheight $log.debug " fixing smr to padheight 2010-01-16 20:35 HOPE THIS DOESNT BREAK ANYTHING" smr = @padheight end @pminrow = 0 if @pminrow < 0 @pmincol = 0 if @pmincol < 0 $log.debug " COPYING #{self.name} to #{@otherwin.name} " $log.debug " calling copy pad #{@pminrow} #{@pmincol}, #{@top} #{@left}, #{smr} #{smc} self #{self.name} " $log.debug " calling copy pad H: #{@height} W: #{@width}, PH #{@padheight} PW #{@padwidth} WIN:#{@window} " # $log.debug " -otherwin target copy pad #{@otherwin.pminrow} #{@otherwin.pmincol}, #{@otherwin.top} #{@otherwin.left}, #{osmr} #{osmc} OTHERWIN:#{@otherwin.name} " ret="-" #if ret == -1 #x XXX $log.debug " #{ret} otherwin copy pad #{@otherwin.pminrow} #{@otherwin.pmincol}, #{@otherwin.top} #{@otherwin.left}, #{osmr} #{osmc} " $log.debug " #{ret} otherwin copy pad H: #{osh} W: #{osw}" if @top >= osh $log.debug " #{ret} ERROR top exceeds other ht #{@top} H: #{osh} " end if @left >= osw $log.debug " #{ret} ERROR left exceeds other wt #{@left} W: #{osw} " end if smr >= osh $log.debug " #{ret} ERROR smrow exceeds other ht #{smr} H: #{osh} " smr = osh() -1 # testing 2010-01-31 21:47 , again 2010-02-05 20:22 end if smc >= osw $log.debug " #{ret} ERROR smcol exceeds other wt #{smc} W: #{osw} " end if smc - @left > @padwidth $log.debug " #{ret} ERROR smcol - left exceeds padwidth #{smc}- #{@left} PW: #{@padwidth} " end if smr - @top > @padheight $log.debug " #{ret} ERROR smr - top exceeds padheight #{smr}- #{@top} PH: #{@padheight} " end ret = @window.copywin(@otherwin.get_window,@pminrow,@pmincol, @top, @left, smr, smc, 0) $log.debug " copywin ret #{ret} " # 2010-01-11 19:42 one more cause of -1 coming is that padheight (actual height which never # changes unless pad increases) or padwidth is smaller than area being printed. Solution: increase # buffer by increasing widgets w or h. smc - left should not exceed padwidth. smr-top should not # exceed padheight #end @modified = false return ret end |
#copy_win_to_pad ⇒ Object
756 757 758 759 760 761 762 763 764 765 |
# File 'lib/ver/window.rb', line 756 def copy_win_to_pad smr = smaxrow() if smr >= @window.smaxrow() smr = @window.smaxrow()-1 end $log.debug " copy_win_to_pad #{@otherwin.name}, #{@window.name}, pminr:#{@pminrow} pminc:#{@pmincol} top:#{@top} left:#{@left} smr:#{smr} " ret = @otherwin.copywin(@window.get_window,@pminrow,@pmincol, @top, @left, smr, smaxcol(), 1) @modified = false return ret end |
#init_vars ⇒ Object
551 552 553 554 555 556 557 558 559 |
# File 'lib/ver/window.rb', line 551 def init_vars super @top ||= 0; @left ||= 0 @pmincol ||= 0 # pad will print from this col @pminrow ||= 0 # pad will print from this row @window_type = :PAD @name ||="#{self}" $log.debug " PAD constructor #{self} , #{@window} " end |
#overwrite_window ⇒ Object
Used to overwrite the pad onto the screen window A window should have been specified as window to back (@see set_backing_window) or (@see create_with_window)
769 770 771 |
# File 'lib/ver/window.rb', line 769 def overwrite_window return @window.overwrite(@otherwin.get_window) end |
#print_border(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
convenience method so that pad can use print_border but remove screen’s row and col
Please note that this requires that buffer have latest top and left.
795 796 797 798 799 800 |
# File 'lib/ver/window.rb', line 795 def print_border row, col, height, width, color, att=Ncurses::A_NORMAL $log.debug " pad printborder #{row} - #{@top} , #{col} - #{@left}, #{height} , #{width} " raise "print_border: row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left #$log.warn "print_border: row < top, pls correct code #{row} #{@top} " if row < @top super(row - @top, col - @left, height, width, color, att) end |
#print_border_only(row, col, height, width, color, att = Ncurses::A_NORMAL) ⇒ Object
801 802 803 804 805 |
# File 'lib/ver/window.rb', line 801 def print_border_only row, col, height, width, color, att=Ncurses::A_NORMAL $log.debug " pad printborder_only #{row} - #{@top} , #{col} - #{@left}, #{height} , #{width} " raise "print_border row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left super(row - @top, col - @left, height, width, color, att) end |
#printstring(row, col, value, color, attrib = Ncurses::A_NORMAL) ⇒ Object
Pls remove the raise once the program is working, extra line can slow things down Keep it on when testing. If the raise is thrown, it means your object could be positioned higher than it should be, or at some point you have increased top, without increasing the objects row.
787 788 789 790 791 792 |
# File 'lib/ver/window.rb', line 787 def printstring(row,col,value,color,attrib=Ncurses::A_NORMAL) #$log.debug " pad printstring #{row} - #{@top} , #{col} - #{@left} " raise "printstring row < top, pls correct code #{row} #{@top}, #{col} #{@left} " if row < @top or col < @left #$log.warn "printstring row < top, pls correct code #{row} #{@top} " if row < @top super(row - @top, col - @left, value, color, attrib) end |
#rb_mvaddch(row, col, char) ⇒ Object
use in place of mvaddch if your widget could be using a pad or window
815 816 817 |
# File 'lib/ver/window.rb', line 815 def rb_mvaddch row, col, char super(row-@top, col-@left, char) end |
#rb_mvwhline(row, col, char, width) ⇒ Object
use in place of mvwhline if your widget could be using a pad or window
807 808 809 |
# File 'lib/ver/window.rb', line 807 def rb_mvwhline row, col, char, width super(row-@top, col-@left, char, width) end |
#rb_mvwvline(row, col, char, width) ⇒ Object
use in place of mvwvline if your widget could be using a pad or window
811 812 813 |
# File 'lib/ver/window.rb', line 811 def rb_mvwvline row, col, char, width super(row-@top, col-@left, char, width) end |
#resize(ht = 0, w = 0) ⇒ Pad
increases the pad size, since the widget may have been resized checks that one of ht or width has been increased destroys earlier pad and returns new one Updates sheight and swidth even if reduced so copywin works fine.
576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/ver/window.rb', line 576 def resize(ht = 0, w = 0) # update sheight and swidth even if reduced, so that pad doesn't overwrite. @sheight = ht if ht > 0 @swidth = w if w > 0 return if ht < @padheight and w < @padwidth @padheight = ht if ht > @padheight @padwidth = w if w > @padwidth destroy $log.debug " L502 resize, creating newpad with #{@padheight} and #{@padwidth} " @window = Ncurses.newpad(@padheight, @padwidth) $log.debug " L502 resize created #{@window} " return @window end |
#set_backing_window(win) ⇒ Object
specify the window or subwin that the pad is writing to 2010-02-20 22:45 - actually since there are pad methods smaxrow used on otherwin therefor it can only be a Pad !! NOTE
660 661 662 663 664 |
# File 'lib/ver/window.rb', line 660 def set_backing_window win @otherwin = win # XX should we extract the coordinates and use for printing ?? # or for setting maxrow and maxcol end |
#set_pad_top_left(top, left = -1) ⇒ Object
start row and col correspond to pad’s top and left which will change if scrolling However, if we use this as a backing store for subwindows it could remain the same
635 636 637 638 639 |
# File 'lib/ver/window.rb', line 635 def set_pad_top_left top, left=-1 $log.debug "#{@name} inside set_pad_top_left to #{top} #{left} earlier #{@pminrow}, #{@pmincol}" @pminrow = top unless top < 0 @pmincol = left unless left < 0 end |
#set_screen_max_row_col(mr, mc) ⇒ Object
added user setting screens max row and col (e.g splitpanes first component)
619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'lib/ver/window.rb', line 619 def set_screen_max_row_col mr, mc $log.debug "#{@name} set_screen_max_row_col #{mr},#{mc}. earlier #{@screen_maxrow}, #{@screen_maxcol} " # added || check on 2010-01-09 18:39 since crashing if mr > sh + top .. # I removed the check, since it results in a blank area on screen since the # widget has not expanded itself. Without the check it will crash on copywin so you # should increase widget size or disallow calling this in this situation. if mr > (@sheight + @top -1 -@pminrow) $log.warn " ->>> ** set_screen_max_row_col #{mr} > #{@sheight} + #{@top} -1 - #{@pminrow} ** " $log.warn " ->>> can result in error in copy_win or in some rows not displaying" return # some situations actually require this ... end unless mr.nil? @screen_maxrow = mr unless mr.nil? # || mr > (@sheight + @top -1 -@pminrow) @screen_maxcol = mc unless mc.nil? end |
#set_screen_row_col(top, left = -1) ⇒ Object Also known as: set_screen_pad_left
top and left correspond to screen’s top and left wich will mostly be fixed. In cases where the component may float around, as in Splitpanes second component this would be set using component’s row and col.
612 613 614 615 |
# File 'lib/ver/window.rb', line 612 def set_screen_row_col top, left=-1 @top = top @left = left unless left < 0 end |
#smaxcol ⇒ Object
return screen max col which will be used for writing to window
650 651 652 653 654 655 |
# File 'lib/ver/window.rb', line 650 def smaxcol #$log.debug " ... niside smaxcol #{@swidth} + #{@left} -1 " #@swidth + @left -1 # $log.debug " ... niside smaxcol #{@swidth} + #{@left} -1 - #{@pmincol} " @screen_maxcol || @swidth + @left -1 - @pmincol end |
#smaxrow ⇒ Object
return screen max row which will be used for writing to window XXX what if user sets/overrides sheight
642 643 644 645 646 647 |
# File 'lib/ver/window.rb', line 642 def smaxrow #$log.debug " ... niside smaxrow #{@sheight} + #{@top} -1 " #@sheight + @top -1 $log.debug "smr: #{@screen_maxrow} ... niside smaxrow #{@sheight} + #{@top} -1 - #{@pminrow}" @screen_maxrow || @sheight + @top -1 -@pminrow end |
#wrefresh ⇒ Object
trying to make things as easy as possible returns -1 if error in prefresh
667 668 669 670 671 672 673 674 675 676 |
# File 'lib/ver/window.rb', line 667 def wrefresh $log.debug " inside pad's wrefresh #{@window}. minr,minc,top,left,smaxr,c: #{@pminrow}, #{@pmincol}, #{@top} #{@left} #{smaxrow()} #{smaxcol()} self: #{self.name} " # caution, prefresh uses maxrow and maxcol not height and width # so we have to add top and less one since we are zero based ret = @window.prefresh(@pminrow, @pmincol, @top, @left, smaxrow(), smaxcol()) $log.warn " WREFRESH returns -1 ERROR - width or height must be exceeding " if ret == -1 @modified = false return ret end |