slithernix-cdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +131 -0
- data/README.md +45 -0
- data/lib/cdk/alphalist.rb +561 -0
- data/lib/cdk/buttonbox.rb +355 -0
- data/lib/cdk/calendar.rb +770 -0
- data/lib/cdk/cdk_objs.rb +463 -0
- data/lib/cdk/dialog.rb +727 -0
- data/lib/cdk/display.rb +63 -0
- data/lib/cdk/draw.rb +233 -0
- data/lib/cdk/dscale.rb +13 -0
- data/lib/cdk/entry.rb +556 -0
- data/lib/cdk/fscale.rb +44 -0
- data/lib/cdk/fselect.rb +940 -0
- data/lib/cdk/fslider.rb +61 -0
- data/lib/cdk/histogram.rb +410 -0
- data/lib/cdk/itemlist.rb +475 -0
- data/lib/cdk/label.rb +207 -0
- data/lib/cdk/marquee.rb +241 -0
- data/lib/cdk/matrix.rb +1176 -0
- data/lib/cdk/mentry.rb +616 -0
- data/lib/cdk/menu.rb +448 -0
- data/lib/cdk/radio.rb +533 -0
- data/lib/cdk/scale.rb +529 -0
- data/lib/cdk/screen.rb +281 -0
- data/lib/cdk/scroll.rb +996 -0
- data/lib/cdk/scroller.rb +183 -0
- data/lib/cdk/selection.rb +619 -0
- data/lib/cdk/slider.rb +542 -0
- data/lib/cdk/swindow.rb +762 -0
- data/lib/cdk/template.rb +562 -0
- data/lib/cdk/traverse.rb +289 -0
- data/lib/cdk/uscale.rb +14 -0
- data/lib/cdk/uslider.rb +14 -0
- data/lib/cdk/viewer.rb +812 -0
- data/lib/cdk.rb +1015 -0
- metadata +149 -0
data/lib/cdk/marquee.rb
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
require_relative 'cdk_objs'
|
2
|
+
|
3
|
+
module CDK
|
4
|
+
class MARQUEE < CDK::CDKOBJS
|
5
|
+
def initialize(cdkscreen, xpos, ypos, width, box, shadow)
|
6
|
+
super()
|
7
|
+
|
8
|
+
@screen = cdkscreen
|
9
|
+
@parent = cdkscreen.window
|
10
|
+
@win = Curses::Window.new(1, 1, ypos, xpos)
|
11
|
+
@active = true
|
12
|
+
@width = width
|
13
|
+
@shadow = shadow
|
14
|
+
|
15
|
+
self.setBox(box)
|
16
|
+
if @win.nil?
|
17
|
+
self.destroy
|
18
|
+
# return (0);
|
19
|
+
end
|
20
|
+
|
21
|
+
cdkscreen.register(:MARQUEE, self)
|
22
|
+
end
|
23
|
+
|
24
|
+
# This activates the widget.
|
25
|
+
def activate(mesg, delay, repeat, box)
|
26
|
+
mesg_length = []
|
27
|
+
start_pos = 0
|
28
|
+
first_char = 0
|
29
|
+
last_char = 1
|
30
|
+
repeat_count = 0
|
31
|
+
view_size = 0
|
32
|
+
message = []
|
33
|
+
first_time = true
|
34
|
+
|
35
|
+
if mesg.nil? or mesg == ''
|
36
|
+
return -1
|
37
|
+
end
|
38
|
+
|
39
|
+
# Keep the box info, setting BorderOf()
|
40
|
+
self.setBox(box)
|
41
|
+
|
42
|
+
padding = if mesg[-1] == ' ' then 0 else 1 end
|
43
|
+
|
44
|
+
# Translate the string to a chtype array
|
45
|
+
message = CDK.char2Chtype(mesg, mesg_length, [])
|
46
|
+
|
47
|
+
# Draw in the widget.
|
48
|
+
self.draw(@box)
|
49
|
+
view_limit = @width - (2 * @border_size)
|
50
|
+
|
51
|
+
# Start doing the marquee thing...
|
52
|
+
oldcurs = Curses.curs_set(0)
|
53
|
+
while @active
|
54
|
+
if first_time
|
55
|
+
first_char = 0
|
56
|
+
last_char = 1
|
57
|
+
view_size = last_char - first_char
|
58
|
+
start_pos = @width - view_size - @border_size
|
59
|
+
|
60
|
+
first_time = false
|
61
|
+
end
|
62
|
+
|
63
|
+
# Draw in the characters.
|
64
|
+
y = first_char
|
65
|
+
(start_pos...(start_pos + view_size)).each do |x|
|
66
|
+
ch = if y < mesg_length[0] then message[y].ord else ' '.ord end
|
67
|
+
@win.mvwaddch(@border_size, x, ch)
|
68
|
+
y += 1
|
69
|
+
end
|
70
|
+
@win.refresh
|
71
|
+
|
72
|
+
# Set my variables
|
73
|
+
if mesg_length[0] < view_limit
|
74
|
+
if last_char < (mesg_length[0] + padding)
|
75
|
+
last_char += 1
|
76
|
+
view_size += 1
|
77
|
+
start_pos = @width - view_size - @border_size
|
78
|
+
elsif start_pos > @border_size
|
79
|
+
# This means the whole string is visible.
|
80
|
+
start_pos -= 1
|
81
|
+
view_size = mesg_length[0] + padding
|
82
|
+
else
|
83
|
+
# We have to start chopping the view_size
|
84
|
+
start_pos = @border_size
|
85
|
+
first_char += 1
|
86
|
+
view_size -= 1
|
87
|
+
end
|
88
|
+
else
|
89
|
+
if start_pos > @border_size
|
90
|
+
last_char += 1
|
91
|
+
view_size += 1
|
92
|
+
start_pos -= 1
|
93
|
+
elsif last_char < mesg_length[0] + padding
|
94
|
+
first_char += 1
|
95
|
+
last_char += 1
|
96
|
+
start_pos = @border_size
|
97
|
+
view_size = view_limit
|
98
|
+
else
|
99
|
+
start_pos = @border_size
|
100
|
+
first_char += 1
|
101
|
+
view_size -= 1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# OK, let's check if we have to start over.
|
106
|
+
if view_size <= 0 && first_char == (mesg_length[0] + padding)
|
107
|
+
# Check if we repeat a specified number or loop indefinitely
|
108
|
+
repeat_count += 1
|
109
|
+
if repeat > 0 && repeat_count >= repeat
|
110
|
+
break
|
111
|
+
end
|
112
|
+
|
113
|
+
# Time to start over.
|
114
|
+
@win.mvwaddch(@border_size, @border_size, ' '.ord)
|
115
|
+
@win.refresh
|
116
|
+
first_time = true
|
117
|
+
end
|
118
|
+
|
119
|
+
# Now sleep
|
120
|
+
Curses.napms(delay * 10)
|
121
|
+
end
|
122
|
+
if oldcurs < 0
|
123
|
+
oldcurs = 1
|
124
|
+
end
|
125
|
+
Curses.curs_set(oldcurs)
|
126
|
+
return 0
|
127
|
+
end
|
128
|
+
|
129
|
+
# This de-activates a marquee widget.
|
130
|
+
def deactivate
|
131
|
+
@active = false
|
132
|
+
end
|
133
|
+
|
134
|
+
# This moves the marquee field to the given location.
|
135
|
+
# Inherited
|
136
|
+
# def move(xplace, yplace, relative, refresh_flag)
|
137
|
+
# end
|
138
|
+
|
139
|
+
# This draws the marquee widget on the screen.
|
140
|
+
def draw(box)
|
141
|
+
# Keep the box information.
|
142
|
+
@box = box
|
143
|
+
|
144
|
+
# Do we need to draw a shadow???
|
145
|
+
unless @shadow_win.nil?
|
146
|
+
Draw.drawShadow(@shadow_win)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Box it if needed.
|
150
|
+
if box
|
151
|
+
Draw.drawObjBox(@win, self)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Refresh the window.
|
155
|
+
@win.refresh
|
156
|
+
end
|
157
|
+
|
158
|
+
# This destroys the widget.
|
159
|
+
def destroy
|
160
|
+
# Clean up the windows.
|
161
|
+
CDK.deleteCursesWindow(@shadow_win)
|
162
|
+
CDK.deleteCursesWindow(@win)
|
163
|
+
|
164
|
+
# Clean the key bindings.
|
165
|
+
self.cleanBindings(:MARQUEE)
|
166
|
+
|
167
|
+
# Unregister this object.
|
168
|
+
CDK::SCREEN.unregister(:MARQUEE, self)
|
169
|
+
end
|
170
|
+
|
171
|
+
# This erases the widget.
|
172
|
+
def erase
|
173
|
+
if self.validCDKObject
|
174
|
+
CDK.eraseCursesWindow(@win)
|
175
|
+
CDK.eraseCursesWindow(@shadow_win)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# This sets the widgets box attribute.
|
180
|
+
def setBox(box)
|
181
|
+
xpos = if @win.nil? then 0 else @win.begx end
|
182
|
+
ypos = if @win.nil? then 0 else @win.begy end
|
183
|
+
|
184
|
+
super
|
185
|
+
|
186
|
+
self.layoutWidget(xpos, ypos)
|
187
|
+
end
|
188
|
+
|
189
|
+
def object_type
|
190
|
+
:MARQUEE
|
191
|
+
end
|
192
|
+
|
193
|
+
def position
|
194
|
+
super(@win)
|
195
|
+
end
|
196
|
+
|
197
|
+
# This sets the background attribute of the widget.
|
198
|
+
def setBKattr(attrib)
|
199
|
+
Curses.wbkgd(@win, attrib)
|
200
|
+
end
|
201
|
+
|
202
|
+
def layoutWidget(xpos, ypos)
|
203
|
+
cdkscreen = @screen
|
204
|
+
parent_width = @screen.window.maxx
|
205
|
+
|
206
|
+
CDK::MARQUEE.discardWin(@win)
|
207
|
+
CDK::MARQUEE.discardWin(@shadow_win)
|
208
|
+
|
209
|
+
box_width = CDK.setWidgetDimension(parent_width, @width, 0)
|
210
|
+
box_height = (@border_size * 2) + 1
|
211
|
+
|
212
|
+
# Rejustify the x and y positions if we need to.
|
213
|
+
xtmp = [xpos]
|
214
|
+
ytmp = [ypos]
|
215
|
+
CDK.alignxy(@screen.window, xtmp, ytmp, box_width, box_height)
|
216
|
+
window = Curses::Window.new(box_height, box_width, ytmp[0], xtmp[0])
|
217
|
+
|
218
|
+
unless window.nil?
|
219
|
+
@win = window
|
220
|
+
@box_height = box_height
|
221
|
+
@box_width = box_width
|
222
|
+
|
223
|
+
@win.keypad(true)
|
224
|
+
|
225
|
+
# Do we want a shadow?
|
226
|
+
if @shadow
|
227
|
+
@shadow_win = @screen.window.subwin(box_height, box_width,
|
228
|
+
ytmp[0] + 1, xtmp[0] + 1)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def self.discardWin(winp)
|
234
|
+
unless winp.nil?
|
235
|
+
winp.erase
|
236
|
+
winp.refresh
|
237
|
+
winp.close
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|