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/label.rb
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
require 'rndk'
|
2
|
+
|
3
|
+
module RNDK
|
4
|
+
|
5
|
+
class LABEL < RNDK::Widget
|
6
|
+
|
7
|
+
# Raw Ncurses window.
|
8
|
+
attr_accessor :win
|
9
|
+
|
10
|
+
def initialize(rndkscreen, xplace, yplace, mesg, rows, box, shadow)
|
11
|
+
super()
|
12
|
+
|
13
|
+
parent_width = Ncurses.getmaxx(rndkscreen.window)
|
14
|
+
parent_height = Ncurses.getmaxy(rndkscreen.window)
|
15
|
+
box_width = -2**30 # -INFINITY
|
16
|
+
box_height = 0
|
17
|
+
xpos = [xplace]
|
18
|
+
ypos = [yplace]
|
19
|
+
x = 0
|
20
|
+
|
21
|
+
return nil if rows <= 0
|
22
|
+
|
23
|
+
self.setBox box
|
24
|
+
box_height = rows + 2 * @border_size
|
25
|
+
|
26
|
+
@info = []
|
27
|
+
@info_len = []
|
28
|
+
@info_pos = []
|
29
|
+
|
30
|
+
# Determine the box width.
|
31
|
+
(0...rows).each do |x|
|
32
|
+
|
33
|
+
# Translate the string to a chtype array
|
34
|
+
info_len = []
|
35
|
+
info_pos = []
|
36
|
+
@info << RNDK.char2Chtype(mesg[x], info_len, info_pos)
|
37
|
+
@info_len << info_len[0]
|
38
|
+
@info_pos << info_pos[0]
|
39
|
+
|
40
|
+
box_width = [box_width, @info_len[x]].max
|
41
|
+
end
|
42
|
+
box_width += 2 * @border_size
|
43
|
+
|
44
|
+
# Create the string alignments.
|
45
|
+
(0...rows).each do |x|
|
46
|
+
@info_pos[x] = RNDK.justifyString(box_width - 2 * @border_size,
|
47
|
+
@info_len[x],
|
48
|
+
@info_pos[x])
|
49
|
+
end
|
50
|
+
|
51
|
+
# Make sure we didn't extend beyond the dimensions of the window.
|
52
|
+
box_width = if box_width > parent_width
|
53
|
+
then parent_width
|
54
|
+
else box_width
|
55
|
+
end
|
56
|
+
box_height = if box_height > parent_height
|
57
|
+
then parent_height
|
58
|
+
else box_height
|
59
|
+
end
|
60
|
+
|
61
|
+
# Rejustify the x and y positions if we need to
|
62
|
+
RNDK.alignxy(rndkscreen.window, xpos, ypos, box_width, box_height)
|
63
|
+
|
64
|
+
@screen = rndkscreen
|
65
|
+
@parent = rndkscreen.window
|
66
|
+
@win = Ncurses.newwin(box_height, box_width, ypos[0], xpos[0])
|
67
|
+
@shadow_win = nil
|
68
|
+
@xpos = xpos[0]
|
69
|
+
@ypos = ypos[0]
|
70
|
+
@rows = rows
|
71
|
+
@box_width = box_width
|
72
|
+
@box_height = box_height
|
73
|
+
@input_window = @win
|
74
|
+
@has_focus = false
|
75
|
+
@shadow = shadow
|
76
|
+
|
77
|
+
if @win.nil?
|
78
|
+
self.destroy
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
|
82
|
+
Ncurses.keypad(@win, true)
|
83
|
+
|
84
|
+
# If a shadow was requested, then create the shadow window.
|
85
|
+
if shadow
|
86
|
+
@shadow_win = Ncurses.newwin(box_height,
|
87
|
+
box_width,
|
88
|
+
ypos[0] + 1,
|
89
|
+
xpos[0] + 1)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Register this
|
93
|
+
rndkscreen.register(:LABEL, self)
|
94
|
+
end
|
95
|
+
|
96
|
+
# This was added for the builder.
|
97
|
+
def activate(actions)
|
98
|
+
self.draw(@box)
|
99
|
+
end
|
100
|
+
|
101
|
+
# This sets multiple attributes of the widget
|
102
|
+
def set(mesg, lines, box)
|
103
|
+
self.setMessage(mesg, lines)
|
104
|
+
self.setBox(box)
|
105
|
+
end
|
106
|
+
|
107
|
+
# This sets the information within the label.
|
108
|
+
def setMessage(info, info_size)
|
109
|
+
|
110
|
+
# Clean out the old message.
|
111
|
+
(0...@rows).each do |x|
|
112
|
+
@info[x] = ''
|
113
|
+
@info_pos[x] = 0
|
114
|
+
@info_len[x] = 0
|
115
|
+
end
|
116
|
+
|
117
|
+
@rows = if info_size < @rows
|
118
|
+
then info_size
|
119
|
+
else @rows
|
120
|
+
end
|
121
|
+
|
122
|
+
# Copy in the new message.
|
123
|
+
(0...@rows).each do |x|
|
124
|
+
info_len = []
|
125
|
+
info_pos = []
|
126
|
+
@info[x] = RNDK.char2Chtype(info[x], info_len, info_pos)
|
127
|
+
@info_len[x] = info_len[0]
|
128
|
+
@info_pos[x] = RNDK.justifyString(@box_width - 2 * @border_size,
|
129
|
+
@info_len[x],
|
130
|
+
info_pos[0])
|
131
|
+
end
|
132
|
+
|
133
|
+
# Redraw the label widget.
|
134
|
+
self.erase
|
135
|
+
self.draw(@box)
|
136
|
+
end
|
137
|
+
|
138
|
+
def getMessage(size)
|
139
|
+
size << @rows
|
140
|
+
return @info
|
141
|
+
end
|
142
|
+
|
143
|
+
def object_type
|
144
|
+
:LABEL
|
145
|
+
end
|
146
|
+
|
147
|
+
def position
|
148
|
+
super(@win)
|
149
|
+
end
|
150
|
+
|
151
|
+
# This sets the background attribute of the widget.
|
152
|
+
def setBKattr(attrib)
|
153
|
+
Ncurses.wbkgd(@win, attrib)
|
154
|
+
end
|
155
|
+
|
156
|
+
# This draws the label widget.
|
157
|
+
def draw(box)
|
158
|
+
|
159
|
+
# Is there a shadow?
|
160
|
+
Draw.drawShadow(@shadow_win) unless @shadow_win.nil?
|
161
|
+
|
162
|
+
# Box the widget if asked.
|
163
|
+
Draw.drawObjBox(@win, self) if @box
|
164
|
+
|
165
|
+
# Draw in the message.
|
166
|
+
(0...@rows).each do |x|
|
167
|
+
Draw.writeChtype(@win,
|
168
|
+
@info_pos[x] + @border_size,
|
169
|
+
x + @border_size,
|
170
|
+
@info[x],
|
171
|
+
RNDK::HORIZONTAL,
|
172
|
+
0,
|
173
|
+
@info_len[x])
|
174
|
+
end
|
175
|
+
|
176
|
+
Ncurses.wrefresh @win
|
177
|
+
end
|
178
|
+
|
179
|
+
# This erases the label widget
|
180
|
+
def erase
|
181
|
+
RNDK.eraseCursesWindow(@win)
|
182
|
+
RNDK.eraseCursesWindow(@shadow_win)
|
183
|
+
end
|
184
|
+
|
185
|
+
# This moves the label field to the given location
|
186
|
+
# Inherited
|
187
|
+
# def move(xplace, yplace, relative, refresh_flag)
|
188
|
+
# end
|
189
|
+
|
190
|
+
# This destroys the label object pointer.
|
191
|
+
def destroy
|
192
|
+
RNDK.deleteCursesWindow(@shadow_win)
|
193
|
+
RNDK.deleteCursesWindow(@win)
|
194
|
+
|
195
|
+
self.cleanBindings(:LABEL)
|
196
|
+
|
197
|
+
RNDK::Screen.unregister(:LABEL, self)
|
198
|
+
end
|
199
|
+
|
200
|
+
# This pauses until a user hits a key...
|
201
|
+
def wait(key)
|
202
|
+
function_key = []
|
203
|
+
|
204
|
+
if key.ord == 0
|
205
|
+
code = self.getch(function_key)
|
206
|
+
|
207
|
+
else
|
208
|
+
# Only exit when a specific key is hit
|
209
|
+
while true
|
210
|
+
code = self.getch(function_key)
|
211
|
+
break if code == key.ord
|
212
|
+
end
|
213
|
+
end
|
214
|
+
code
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
data/lib/rndk/marquee.rb
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
require 'rndk'
|
2
|
+
|
3
|
+
module RNDK
|
4
|
+
class MARQUEE < RNDK::Widget
|
5
|
+
def initialize(rndkscreen, xpos, ypos, width, box, shadow)
|
6
|
+
super()
|
7
|
+
|
8
|
+
@screen = rndkscreen
|
9
|
+
@parent = rndkscreen.window
|
10
|
+
@win = Ncurses.newwin(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
|
+
rndkscreen.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 = RNDK.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 = Ncurses.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
|
+
Ncurses.mvwaddch(@win, @border_size, x, ch)
|
68
|
+
y += 1
|
69
|
+
end
|
70
|
+
Ncurses.wrefresh @win
|
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
|
+
Ncurses.mvwaddch(@win, @border_size, @border_size, ' '.ord)
|
115
|
+
Ncurses.wrefresh @win
|
116
|
+
first_time = true
|
117
|
+
end
|
118
|
+
|
119
|
+
# Now sleep
|
120
|
+
Ncurses.napms(delay * 10)
|
121
|
+
end
|
122
|
+
if oldcurs < 0
|
123
|
+
oldcurs = 1
|
124
|
+
end
|
125
|
+
Ncurses.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
|
+
Ncurses.wrefresh @win
|
156
|
+
end
|
157
|
+
|
158
|
+
# This destroys the widget.
|
159
|
+
def destroy
|
160
|
+
# Clean up the windows.
|
161
|
+
RNDK.deleteCursesWindow(@shadow_win)
|
162
|
+
RNDK.deleteCursesWindow(@win)
|
163
|
+
|
164
|
+
# Clean the key bindings.
|
165
|
+
self.cleanBindings(:MARQUEE)
|
166
|
+
|
167
|
+
# Unregister this object.
|
168
|
+
RNDK::Screen.unregister(:MARQUEE, self)
|
169
|
+
end
|
170
|
+
|
171
|
+
# This erases the widget.
|
172
|
+
def erase
|
173
|
+
if self.validRNDKObject
|
174
|
+
RNDK.eraseCursesWindow(@win)
|
175
|
+
RNDK.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 Ncurses.getbegx(@win) end
|
182
|
+
ypos = if @win.nil? then 0 else Ncurses.getbegy(@win) 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
|
+
Ncurses.wbkgd(@win, attrib)
|
200
|
+
end
|
201
|
+
|
202
|
+
def layoutWidget(xpos, ypos)
|
203
|
+
rndkscreen = @screen
|
204
|
+
parent_width = Ncurses.getmaxx(@screen.window)
|
205
|
+
|
206
|
+
RNDK::MARQUEE.discardWin(@win)
|
207
|
+
RNDK::MARQUEE.discardWin(@shadow_win)
|
208
|
+
|
209
|
+
box_width = RNDK.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
|
+
RNDK.alignxy(@screen.window, xtmp, ytmp, box_width, box_height)
|
216
|
+
window = Ncurses.newwin(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
|
+
Ncurses.keypad(@win, true)
|
224
|
+
|
225
|
+
# Do we want a shadow?
|
226
|
+
if @shadow
|
227
|
+
@shadow_win = Ncurses.subwin(@screen.window,
|
228
|
+
box_height,
|
229
|
+
box_width,
|
230
|
+
ytmp[0] + 1,
|
231
|
+
xtmp[0] + 1)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def self.discardWin(winp)
|
237
|
+
unless winp.nil?
|
238
|
+
Ncurses.werase(winp)
|
239
|
+
Ncurses.wrefresh(winp)
|
240
|
+
Ncurses.delwin(winp)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|