rndk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/COPYING +137 -0
- data/Gemfile +4 -0
- data/README.md +100 -0
- data/Rakefile +3 -0
- data/TODO +68 -0
- data/demos/appointment.rb +346 -0
- data/demos/clock.rb +56 -0
- data/examples/01-hello-world.rb +56 -0
- data/examples/05-position-widget.rb +108 -0
- data/lib/rndk.rb +912 -0
- data/lib/rndk/alphalist.rb +572 -0
- data/lib/rndk/button.rb +370 -0
- data/lib/rndk/buttonbox.rb +359 -0
- data/lib/rndk/calendar.rb +766 -0
- data/lib/rndk/core/display.rb +63 -0
- data/lib/rndk/core/draw.rb +238 -0
- data/lib/rndk/core/quick_widgets.rb +106 -0
- data/lib/rndk/core/screen.rb +269 -0
- data/lib/rndk/core/traverse.rb +289 -0
- data/lib/rndk/core/widget.rb +506 -0
- data/lib/rndk/dialog.rb +367 -0
- data/lib/rndk/dscale.rb +13 -0
- data/lib/rndk/entry.rb +575 -0
- data/lib/rndk/fscale.rb +61 -0
- data/lib/rndk/fselect.rb +940 -0
- data/lib/rndk/fslider.rb +80 -0
- data/lib/rndk/graph.rb +401 -0
- data/lib/rndk/histogram.rb +412 -0
- data/lib/rndk/itemlist.rb +474 -0
- data/lib/rndk/label.rb +218 -0
- data/lib/rndk/marquee.rb +244 -0
- data/lib/rndk/matrix.rb +1189 -0
- data/lib/rndk/mentry.rb +619 -0
- data/lib/rndk/menu.rb +478 -0
- data/lib/rndk/radio.rb +538 -0
- data/lib/rndk/scale.rb +538 -0
- data/lib/rndk/scroll.rb +633 -0
- data/lib/rndk/scroller.rb +183 -0
- data/lib/rndk/selection.rb +630 -0
- data/lib/rndk/slider.rb +545 -0
- data/lib/rndk/swindow.rb +766 -0
- data/lib/rndk/template.rb +560 -0
- data/lib/rndk/uscale.rb +14 -0
- data/lib/rndk/uslider.rb +14 -0
- data/lib/rndk/version.rb +6 -0
- data/lib/rndk/viewer.rb +825 -0
- data/rndk.gemspec +35 -0
- metadata +141 -0
data/lib/rndk/fslider.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rndk/slider'
|
2
|
+
|
3
|
+
module RNDK
|
4
|
+
class FSLIDER < RNDK::SLIDER
|
5
|
+
def initialize(rndkscreen,
|
6
|
+
xplace,
|
7
|
+
yplace,
|
8
|
+
title,
|
9
|
+
label,
|
10
|
+
filler,
|
11
|
+
field_width,
|
12
|
+
start,
|
13
|
+
low,
|
14
|
+
high,
|
15
|
+
inc,
|
16
|
+
fast_inc,
|
17
|
+
digits,
|
18
|
+
box,
|
19
|
+
shadow)
|
20
|
+
|
21
|
+
@digits = digits
|
22
|
+
super(rndkscreen, xplace, yplace, title, label, filler, field_width, start, low, high, inc, fast_inc, box, shadow)
|
23
|
+
end
|
24
|
+
|
25
|
+
# This draws the widget.
|
26
|
+
def drawField
|
27
|
+
step = 1.0 * @field_width / (@high - @low)
|
28
|
+
|
29
|
+
# Determine how many filler characters need to be drawn.
|
30
|
+
filler_characters = (@current - @low) * step
|
31
|
+
|
32
|
+
Ncurses.werase(@field_win)
|
33
|
+
|
34
|
+
# Add the character to the window.
|
35
|
+
(0...filler_characters).each do |x|
|
36
|
+
Ncurses.mvwaddch(@field_win, 0, x, @filler)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Draw the value in the field.
|
40
|
+
digits = [@digits, 30].min
|
41
|
+
format = '%%.%if' % [digits]
|
42
|
+
temp = format % [@current]
|
43
|
+
|
44
|
+
Draw.writeCharAttrib(@field_win,
|
45
|
+
@field_width,
|
46
|
+
0,
|
47
|
+
temp,
|
48
|
+
Ncurses::A_NORMAL,
|
49
|
+
RNDK::HORIZONTAL,
|
50
|
+
0,
|
51
|
+
temp.size)
|
52
|
+
|
53
|
+
self.moveToEditPosition(@field_edit)
|
54
|
+
Ncurses.wrefresh(@field_win)
|
55
|
+
end
|
56
|
+
|
57
|
+
def formattedSize(value)
|
58
|
+
digits = [@digits, 30].min
|
59
|
+
format = '%%.%if' % [digits]
|
60
|
+
temp = format % [value]
|
61
|
+
return temp.size
|
62
|
+
end
|
63
|
+
|
64
|
+
def setDigits(digits)
|
65
|
+
@digits = [0, digits].max
|
66
|
+
end
|
67
|
+
|
68
|
+
def getDigits
|
69
|
+
return @digits
|
70
|
+
end
|
71
|
+
|
72
|
+
def SCAN_FMT
|
73
|
+
'%g%c'
|
74
|
+
end
|
75
|
+
|
76
|
+
def object_type
|
77
|
+
:FSLIDER
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/rndk/graph.rb
ADDED
@@ -0,0 +1,401 @@
|
|
1
|
+
require 'rndk'
|
2
|
+
|
3
|
+
module RNDK
|
4
|
+
class GRAPH < RNDK::Widget
|
5
|
+
def initialize(rndkscreen,
|
6
|
+
xplace,
|
7
|
+
yplace,
|
8
|
+
height,
|
9
|
+
width,
|
10
|
+
title,
|
11
|
+
xtitle,
|
12
|
+
ytitle)
|
13
|
+
super()
|
14
|
+
parent_width = Ncurses.getmaxx rndkscreen.window
|
15
|
+
parent_height = Ncurses.getmaxy rndkscreen.window
|
16
|
+
|
17
|
+
self.setBox(false)
|
18
|
+
|
19
|
+
box_height = RNDK.setWidgetDimension(parent_height, height, 3)
|
20
|
+
box_width = RNDK.setWidgetDimension(parent_width, width, 0)
|
21
|
+
box_width = self.setTitle(title, box_width)
|
22
|
+
box_height += @title_lines
|
23
|
+
box_width = [parent_width, box_width].min
|
24
|
+
box_height = [parent_height, box_height].min
|
25
|
+
|
26
|
+
# Rejustify the x and y positions if we need to
|
27
|
+
xtmp = [xplace]
|
28
|
+
ytmp = [yplace]
|
29
|
+
RNDK.alignxy(rndkscreen.window, xtmp, ytmp, box_width, box_height)
|
30
|
+
xpos = xtmp[0]
|
31
|
+
ypos = ytmp[0]
|
32
|
+
|
33
|
+
# Create the widget pointer
|
34
|
+
@screen = rndkscreen
|
35
|
+
@parent = rndkscreen.window
|
36
|
+
@win = Ncurses.newwin(box_height, box_width, ypos, xpos)
|
37
|
+
@box_height = box_height
|
38
|
+
@box_width = box_width
|
39
|
+
@minx = 0
|
40
|
+
@maxx = 0
|
41
|
+
@xscale = 0
|
42
|
+
@yscale = 0
|
43
|
+
@count = 0
|
44
|
+
@display_type = :LINE
|
45
|
+
|
46
|
+
if @win.nil?
|
47
|
+
self.destroy
|
48
|
+
return nil
|
49
|
+
end
|
50
|
+
Ncurses.keypad(@win, true)
|
51
|
+
|
52
|
+
# Translate the X axis title string to a chtype array
|
53
|
+
if !(xtitle.nil?) && xtitle.size > 0
|
54
|
+
xtitle_len = []
|
55
|
+
xtitle_pos = []
|
56
|
+
@xtitle = RNDK.char2Chtype(xtitle, xtitle_len, xtitle_pos)
|
57
|
+
@xtitle_len = xtitle_len[0]
|
58
|
+
@xtitle_pos = RNDK.justifyString(@box_height,
|
59
|
+
@xtitle_len, xtitle_pos[0])
|
60
|
+
else
|
61
|
+
xtitle_len = []
|
62
|
+
xtitle_pos = []
|
63
|
+
@xtitle = RNDK.char2Chtype("<C></5>X Axis", xtitle_len, xtitle_pos)
|
64
|
+
@xtitle_len = title_len[0]
|
65
|
+
@xtitle_pos = RNDK.justifyString(@box_height,
|
66
|
+
@xtitle_len, xtitle_pos[0])
|
67
|
+
end
|
68
|
+
|
69
|
+
# Translate the Y Axis title string to a chtype array
|
70
|
+
if !(ytitle.nil?) && ytitle.size > 0
|
71
|
+
ytitle_len = []
|
72
|
+
ytitle_pos = []
|
73
|
+
@ytitle = RNDK.char2Chtype(ytitle, ytitle_len, ytitle_pos)
|
74
|
+
@ytitle_len = ytitle_len[0]
|
75
|
+
@ytitle_pos = RNDK.justifyString(@box_width, @ytitle_len, ytitle_pos[0])
|
76
|
+
else
|
77
|
+
ytitle_len = []
|
78
|
+
ytitle_pos = []
|
79
|
+
@ytitle = RNDK.char2Chtype("<C></5>Y Axis", ytitle_len, ytitle_pos)
|
80
|
+
@ytitle_len = ytitle_len[0]
|
81
|
+
@ytitle_pos = RNDK.justifyString(@box_width, @ytitle_len, ytitle_pos[0])
|
82
|
+
end
|
83
|
+
|
84
|
+
@graph_char = 0
|
85
|
+
@values = []
|
86
|
+
|
87
|
+
rndkscreen.register(:GRAPH, self)
|
88
|
+
end
|
89
|
+
|
90
|
+
# This was added for the builder.
|
91
|
+
def activate(actions)
|
92
|
+
self.draw(@box)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Set multiple attributes of the widget
|
96
|
+
def set(values, count, graph_char, start_at_zero, display_type)
|
97
|
+
ret = self.setValues(values, count, start_at_zero)
|
98
|
+
self.setCharacters(graph_char)
|
99
|
+
self.setDisplayType(display_type)
|
100
|
+
return ret
|
101
|
+
end
|
102
|
+
|
103
|
+
# Set the scale factors for the graph after wee have loaded new values.
|
104
|
+
def setScales
|
105
|
+
@xscale = (@maxx - @minx) / [1, @box_height - @title_lines - 5].max
|
106
|
+
if @xscale <= 0
|
107
|
+
@xscale = 1
|
108
|
+
end
|
109
|
+
|
110
|
+
@yscale = (@box_width - 4) / [1, @count].max
|
111
|
+
if @yscale <= 0
|
112
|
+
@yscale = 1
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Set the values of the graph.
|
117
|
+
def setValues(values, count, start_at_zero)
|
118
|
+
min = 2**30
|
119
|
+
max = -2**30
|
120
|
+
|
121
|
+
# Make sure everything is happy.
|
122
|
+
if count < 0
|
123
|
+
return false
|
124
|
+
end
|
125
|
+
|
126
|
+
if !(@values.nil?) && @values.size > 0
|
127
|
+
@values = []
|
128
|
+
@count = 0
|
129
|
+
end
|
130
|
+
|
131
|
+
# Copy the X values
|
132
|
+
values.each do |value|
|
133
|
+
min = [value, @minx].min
|
134
|
+
max = [value, @maxx].max
|
135
|
+
|
136
|
+
# Copy the value.
|
137
|
+
@values << value
|
138
|
+
end
|
139
|
+
|
140
|
+
# Keep the count and min/max values
|
141
|
+
@count = count
|
142
|
+
@minx = min
|
143
|
+
@maxx = max
|
144
|
+
|
145
|
+
# Check the start at zero status.
|
146
|
+
if start_at_zero
|
147
|
+
@minx = 0
|
148
|
+
end
|
149
|
+
|
150
|
+
self.setScales
|
151
|
+
|
152
|
+
return true
|
153
|
+
end
|
154
|
+
|
155
|
+
def getValues(size)
|
156
|
+
size << @count
|
157
|
+
return @values
|
158
|
+
end
|
159
|
+
|
160
|
+
# Set the value of the graph at the given index.
|
161
|
+
def setValue(index, value, start_at_zero)
|
162
|
+
# Make sure the index is within range.
|
163
|
+
if index < 0 || index >= @count
|
164
|
+
return false
|
165
|
+
end
|
166
|
+
|
167
|
+
# Set the min, max, and value for the graph
|
168
|
+
@minx = [value, @minx].min
|
169
|
+
@maxx = [value, @maxx].max
|
170
|
+
@values[index] = value
|
171
|
+
|
172
|
+
# Check the start at zero status
|
173
|
+
if start_at_zero
|
174
|
+
@minx = 0
|
175
|
+
end
|
176
|
+
|
177
|
+
self.setScales
|
178
|
+
|
179
|
+
return true
|
180
|
+
end
|
181
|
+
|
182
|
+
def getValue(index)
|
183
|
+
if index >= 0 && index < @count then @values[index] else 0 end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Set the characters of the graph widget.
|
187
|
+
def setCharacters(characters)
|
188
|
+
char_count = []
|
189
|
+
new_tokens = RNDK.char2Chtype(characters, char_count, [])
|
190
|
+
|
191
|
+
if char_count[0] != @count
|
192
|
+
return false
|
193
|
+
end
|
194
|
+
|
195
|
+
@graph_char = new_tokens
|
196
|
+
return true
|
197
|
+
end
|
198
|
+
|
199
|
+
def getCharacters
|
200
|
+
return @graph_char
|
201
|
+
end
|
202
|
+
|
203
|
+
# Set the character of the graph widget of the given index.
|
204
|
+
def setCharacter(index, character)
|
205
|
+
# Make sure the index is within range
|
206
|
+
if index < 0 || index > @count
|
207
|
+
return false
|
208
|
+
end
|
209
|
+
|
210
|
+
# Convert the string given to us
|
211
|
+
char_count = []
|
212
|
+
new_tokens = RNDK.char2Chtype(character, char_count, [])
|
213
|
+
|
214
|
+
# Check if the number of characters back is the same as the number
|
215
|
+
# of elements in the list.
|
216
|
+
if char_count[0] != @count
|
217
|
+
return false
|
218
|
+
end
|
219
|
+
|
220
|
+
# Everything OK so far. Set the value of the array.
|
221
|
+
@graph_char[index] = new_tokens[0]
|
222
|
+
return true
|
223
|
+
end
|
224
|
+
|
225
|
+
def getCharacter(index)
|
226
|
+
return graph_char[index]
|
227
|
+
end
|
228
|
+
|
229
|
+
# Set the display type of the graph.
|
230
|
+
def setDisplayType(type)
|
231
|
+
@display_type = type
|
232
|
+
end
|
233
|
+
|
234
|
+
def getDisplayType
|
235
|
+
@display_type
|
236
|
+
end
|
237
|
+
|
238
|
+
# Set the background attribute of the widget.
|
239
|
+
def setBKattr(attrib)
|
240
|
+
Ncurses.wbkgd(@win, attrib)
|
241
|
+
end
|
242
|
+
|
243
|
+
# Move the graph field to the given location.
|
244
|
+
def move(xplace, yplace, relative, refresh_flag)
|
245
|
+
current_x = Ncurses.getbegx(@win)
|
246
|
+
current_y = Ncurses.getbegy(@win)
|
247
|
+
xpos = xplace
|
248
|
+
ypos = yplace
|
249
|
+
|
250
|
+
# If this is a relative move, then we will adjust where we want
|
251
|
+
# to move to
|
252
|
+
if relative
|
253
|
+
xpos = Ncurses.getbegx(@win) + xplace
|
254
|
+
ypos = Ncurses.getbegy(@win) + yplace
|
255
|
+
end
|
256
|
+
|
257
|
+
# Adjust the window if we need to.
|
258
|
+
xtmp = [xpos]
|
259
|
+
tymp = [ypos]
|
260
|
+
RNDK.alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
|
261
|
+
xpos = xtmp[0]
|
262
|
+
ypos = ytmp[0]
|
263
|
+
|
264
|
+
# Get the difference
|
265
|
+
xdiff = current_x - xpos
|
266
|
+
ydiff = current_y - ypos
|
267
|
+
|
268
|
+
# Move the window to the new location.
|
269
|
+
RNDK.moveCursesWindow(@win, -xdiff, -ydiff)
|
270
|
+
RNDK.moveCursesWindow(@shadow_win, -xdiff, -ydiff)
|
271
|
+
|
272
|
+
# Touch the windows so they 'move'.
|
273
|
+
RNDK::Screen.refresh_window(@screen.window)
|
274
|
+
|
275
|
+
# Reraw the windowk if they asked for it
|
276
|
+
if refresh_flag
|
277
|
+
self.draw(@box)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
# Draw the grpah widget
|
282
|
+
def draw(box)
|
283
|
+
adj = 2 + (if @xtitle.nil? || @xtitle.size == 0 then 0 else 1 end)
|
284
|
+
spacing = 0
|
285
|
+
attrib = ' '.ord | Ncurses::A_REVERSE
|
286
|
+
|
287
|
+
if box
|
288
|
+
Draw.drawObjBox(@win, self)
|
289
|
+
end
|
290
|
+
|
291
|
+
# Draw in the vertical axis
|
292
|
+
Draw.drawLine(@win,
|
293
|
+
2,
|
294
|
+
@title_lines + 1,
|
295
|
+
2,
|
296
|
+
@box_height - 3,
|
297
|
+
Ncurses::ACS_VLINE)
|
298
|
+
|
299
|
+
# Draw in the horizontal axis
|
300
|
+
Draw.drawLine(@win,
|
301
|
+
3,
|
302
|
+
@box_height - 3,
|
303
|
+
@box_width,
|
304
|
+
@box_height - 3,
|
305
|
+
Ncurses::ACS_HLINE)
|
306
|
+
|
307
|
+
self.drawTitle(@win)
|
308
|
+
|
309
|
+
# Draw in the X axis title.
|
310
|
+
if !(@xtitle.nil?) && @xtitle.size > 0
|
311
|
+
Draw.writeChtype(@win, 0, @xtitle_pos, @xtitle, RNDK::VERTICAL, 0, @xtitle_len)
|
312
|
+
attrib = @xtitle[0] & Ncurses::A_ATTRIBUTES
|
313
|
+
end
|
314
|
+
|
315
|
+
# Draw in the X axis high value
|
316
|
+
temp = "%d" % [@maxx]
|
317
|
+
Draw.writeCharAttrib(@win, 1, @title_lines + 1, temp, attrib,
|
318
|
+
RNDK::VERTICAL, 0, temp.size)
|
319
|
+
|
320
|
+
# Draw in the X axis low value.
|
321
|
+
temp = "%d" % [@minx]
|
322
|
+
Draw.writeCharAttrib(@win, 1, @box_height - 2 - temp.size, temp, attrib,
|
323
|
+
RNDK::VERTICAL, 0, temp.size)
|
324
|
+
|
325
|
+
# Draw in the Y axis title
|
326
|
+
if !(@ytitle.nil?) && @ytitle.size > 0
|
327
|
+
Draw.writeChtype(@win, @ytitle_pos, @box_height - 1, @ytitle,
|
328
|
+
RNDK::HORIZONTAL, 0, @ytitle_len)
|
329
|
+
end
|
330
|
+
|
331
|
+
# Draw in the Y axis high value.
|
332
|
+
temp = "%d" % [@count]
|
333
|
+
Draw.writeCharAttrib(@win, @box_width - temp.size - adj,
|
334
|
+
@box_height - 2, temp, attrib, RNDK::HORIZONTAL, 0, temp.size)
|
335
|
+
|
336
|
+
# Draw in the Y axis low value.
|
337
|
+
Draw.writeCharAttrib(@win, 3, @box_height - 2, "0", attrib,
|
338
|
+
RNDK::HORIZONTAL, 0, "0".size)
|
339
|
+
|
340
|
+
# If the count is zero then there aren't any points.
|
341
|
+
if @count == 0
|
342
|
+
Ncurses.wrefresh @win
|
343
|
+
return
|
344
|
+
end
|
345
|
+
|
346
|
+
spacing = (@box_width - 3) / @count # FIXME magic number (TITLE_LM)
|
347
|
+
|
348
|
+
# Draw in the graph line/plot points.
|
349
|
+
(0...@count).each do |y|
|
350
|
+
colheight = (@values[y] / @xscale) - 1
|
351
|
+
# Add the marker on the Y axis.
|
352
|
+
Ncurses.mvwaddch(@win, @box_height - 3, (y + 1) * spacing + adj,
|
353
|
+
Ncurses::ACS_TTEE)
|
354
|
+
|
355
|
+
# If this is a plot graph, all we do is draw a dot.
|
356
|
+
if @display_type == :PLOT
|
357
|
+
xpos = @box_height - 4 - colheight
|
358
|
+
ypos = (y + 1) * spacing + adj
|
359
|
+
Ncurses.mvwaddch(@win, xpos, ypos, @graph_char[y])
|
360
|
+
else
|
361
|
+
(0..@yscale).each do |x|
|
362
|
+
xpos = @box_height - 3
|
363
|
+
ypos = (y + 1) * spacing - adj
|
364
|
+
Draw.drawLine(@win, ypos, xpos - colheight, ypos, xpos,
|
365
|
+
@graph_char[y])
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# Draw in the axis corners.
|
371
|
+
Ncurses.mvwaddch(@win, @title_lines, 2, Ncurses::ACS_URCORNER)
|
372
|
+
Ncurses.mvwaddch(@win, @box_height - 3, 2, Ncurses::ACS_LLCORNER)
|
373
|
+
Ncurses.mvwaddch(@win, @box_height - 3, @box_width, Ncurses::ACS_URCORNER)
|
374
|
+
|
375
|
+
# Refresh and lets see it
|
376
|
+
Ncurses.wrefresh @win
|
377
|
+
end
|
378
|
+
|
379
|
+
def destroy
|
380
|
+
self.cleanTitle
|
381
|
+
self.cleanBindings(:GRAPH)
|
382
|
+
RNDK::Screen.unregister(:GRAPH, self)
|
383
|
+
RNDK.deleteCursesWindow(@win)
|
384
|
+
end
|
385
|
+
|
386
|
+
def erase
|
387
|
+
if self.validRNDKObject
|
388
|
+
RNDK.eraseCursesWindow(@win)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
def object_type
|
393
|
+
:GRAPH
|
394
|
+
end
|
395
|
+
|
396
|
+
def position
|
397
|
+
super(@win)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|