Class: CDK::MARQUEE
Instance Attribute Summary
Attributes included from HasTitle
Attributes included from HasScreen
#is_visible, #screen, #screen_index
Attributes included from ExitConditions
Attributes included from Bindings
Attributes included from Focusable
Attributes included from Borders
#BXAttr, #HZChar, #LLChar, #LRChar, #ULChar, #URChar, #VTChar, #border_size, #box
Class Method Summary collapse
Instance Method Summary collapse
-
#activate(mesg, delay, repeat, box) ⇒ Object
This activates the widget.
-
#deactivate ⇒ Object
This de-activates a marquee widget.
-
#destroy ⇒ Object
This destroys the widget.
-
#draw(box) ⇒ Object
This draws the marquee widget on the screen.
-
#erase ⇒ Object
This erases the widget.
-
#initialize(cdkscreen, xpos, ypos, width, box, shadow) ⇒ MARQUEE
constructor
A new instance of MARQUEE.
- #layoutWidget(xpos, ypos) ⇒ Object
- #object_type ⇒ Object
- #position ⇒ Object
-
#setBKattr(attrib) ⇒ Object
This sets the background attribute of the widget.
-
#setBox(box) ⇒ Object
This sets the widgets box attribute.
Methods inherited from CDKOBJS
#setBackgroundColor, #timeout, #validCDKObject, #validObjType
Methods included from WindowHooks
Methods included from WindowInput
#getc, #getch, #inject, #setPostProcess, #setPreProcess
Methods included from HasTitle
#cleanTitle, #drawTitle, #init_title, #setTitle
Methods included from HasScreen
#SCREEN_XPOS, #SCREEN_YPOS, #init_screen, #wrefresh
Methods included from ExitConditions
#init_exit_conditions, #resetExitType, #setExitType
Methods included from Bindings
#bind, #bindableObject, #checkBind, #cleanBindings, #init_bindings, #isBind, #unbind
Methods included from Focusable
Methods included from Borders
#getBox, #init_borders, #setBXattr, #setHZchar, #setLLchar, #setLRchar, #setULchar, #setURchar, #setVTchar
Methods included from Movement
Methods included from Converters
#char2Chtype, #charOf, #chtype2Char, #chtype2String, #decode_attribute, #encode_attribute
Methods included from Justifications
Methods included from Alignments
Constructor Details
#initialize(cdkscreen, xpos, ypos, width, box, shadow) ⇒ MARQUEE
Returns a new instance of MARQUEE.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cdk/components/marquee.rb', line 5 def initialize(cdkscreen, xpos, ypos, width, box, shadow) super() @screen = cdkscreen @parent = cdkscreen.window @win = Ncurses::WINDOW.new(1, 1, ypos, xpos) @active = true @width = width @shadow = shadow self.setBox(box) if @win.nil? self.destroy # return (0); end cdkscreen.register(:MARQUEE, self) end |
Class Method Details
Instance Method Details
#activate(mesg, delay, repeat, box) ⇒ Object
This activates the widget.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/cdk/components/marquee.rb', line 25 def activate(mesg, delay, repeat, box) mesg_length = [] start_pos = 0 first_char = 0 last_char = 1 repeat_count = 0 view_size = 0 = [] first_time = true if mesg.nil? or mesg == '' return -1 end # Keep the box info, setting BorderOf() self.setBox(box) padding = if mesg[-1] == ' ' then 0 else 1 end # Translate the string to a chtype array = char2Chtype(mesg, mesg_length, []) # Draw in the widget. self.draw(@box) view_limit = @width - (2 * @border_size) # Start doing the marquee thing... oldcurs = Ncurses.curs_set(0) while @active if first_time first_char = 0 last_char = 1 view_size = last_char - first_char start_pos = @width - view_size - @border_size first_time = false end # Draw in the characters. y = first_char (start_pos...(start_pos + view_size)).each do |x| ch = if y < mesg_length[0] then [y].ord else ' '.ord end @win.mvwaddch(@border_size, x, ch) y += 1 end wrefresh # Set my variables if mesg_length[0] < view_limit if last_char < (mesg_length[0] + padding) last_char += 1 view_size += 1 start_pos = @width - view_size - @border_size elsif start_pos > @border_size # This means the whole string is visible. start_pos -= 1 view_size = mesg_length[0] + padding else # We have to start chopping the view_size start_pos = @border_size first_char += 1 view_size -= 1 end else if start_pos > @border_size last_char += 1 view_size += 1 start_pos -= 1 elsif last_char < mesg_length[0] + padding first_char += 1 last_char += 1 start_pos = @border_size view_size = view_limit else start_pos = @border_size first_char += 1 view_size -= 1 end end # OK, let's check if we have to start over. if view_size <= 0 && first_char == (mesg_length[0] + padding) # Check if we repeat a specified number or loop indefinitely repeat_count += 1 if repeat > 0 && repeat_count >= repeat break end # Time to start over. @win.mvwaddch(@border_size, @border_size, ' '.ord) wrefresh first_time = true end # Now sleep Ncurses.napms(delay * 10) end if oldcurs < 0 oldcurs = 1 end Ncurses.curs_set(oldcurs) return 0 end |
#deactivate ⇒ Object
This de-activates a marquee widget.
130 131 132 |
# File 'lib/cdk/components/marquee.rb', line 130 def deactivate @active = false end |
#destroy ⇒ Object
This destroys the widget.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/cdk/components/marquee.rb', line 159 def destroy # Clean up the windows. CDK.deleteCursesWindow(@shadow_win) CDK.deleteCursesWindow(@win) # Clean the key bindings. self.cleanBindings(:MARQUEE) # Unregister this object. CDK::SCREEN.unregister(:MARQUEE, self) end |
#draw(box) ⇒ Object
This draws the marquee widget on the screen.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/cdk/components/marquee.rb', line 140 def draw(box) # Keep the box information. @box = box # Do we need to draw a shadow??? unless @shadow_win.nil? Draw.drawShadow(@shadow_win) end # Box it if needed. if box Draw.drawObjBox(@win, self) end # Refresh the window. wrefresh end |
#erase ⇒ Object
This erases the widget.
172 173 174 175 176 177 |
# File 'lib/cdk/components/marquee.rb', line 172 def erase if self.validCDKObject CDK.eraseCursesWindow(@win) CDK.eraseCursesWindow(@shadow_win) end end |
#layoutWidget(xpos, ypos) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/cdk/components/marquee.rb', line 202 def layoutWidget(xpos, ypos) cdkscreen = @screen parent_width = @screen.window.getmaxx CDK::MARQUEE.discardWin(@win) CDK::MARQUEE.discardWin(@shadow_win) box_width = CDK.setWidgetDimension(parent_width, @width, 0) box_height = (@border_size * 2) + 1 # Rejustify the x and y positions if we need to. xtmp = [xpos] ytmp = [ypos] alignxy(@screen.window, xtmp, ytmp, box_width, box_height) window = Ncurses::WINDOW.new(box_height, box_width, ytmp[0], xtmp[0]) unless window.nil? @win = window @box_height = box_height @box_width = box_width @win.keypad(true) # Do we want a shadow? if @shadow @shadow_win = @screen.window.subwin(box_height, box_width, ytmp[0] + 1, xtmp[0] + 1) end end end |
#object_type ⇒ Object
189 190 191 |
# File 'lib/cdk/components/marquee.rb', line 189 def object_type :MARQUEE end |
#position ⇒ Object
193 194 195 |
# File 'lib/cdk/components/marquee.rb', line 193 def position super(@win) end |
#setBKattr(attrib) ⇒ Object
This sets the background attribute of the widget.
198 199 200 |
# File 'lib/cdk/components/marquee.rb', line 198 def setBKattr(attrib) Ncurses.wbkgd(@win, attrib) end |
#setBox(box) ⇒ Object
This sets the widgets box attribute.
180 181 182 183 184 185 186 187 |
# File 'lib/cdk/components/marquee.rb', line 180 def setBox(box) xpos = if @win.nil? then 0 else @win.getbegx end ypos = if @win.nil? then 0 else @win.getbegy end super self.layoutWidget(xpos, ypos) end |