rndk 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -4
  3. data/TODO +21 -1
  4. data/demos/appointment.rb +279 -299
  5. data/demos/clock.rb +13 -8
  6. data/demos/rss-reader.rb +84 -0
  7. data/examples/01-hello-world.rb +13 -11
  8. data/examples/02-colors.rb +14 -21
  9. data/examples/03-markup.rb +7 -7
  10. data/examples/04-quick-widgets.rb +2 -2
  11. data/examples/05-position-widget.rb +50 -31
  12. data/examples/06-callbacks.rb +77 -0
  13. data/examples/07-traverse.rb +90 -0
  14. data/examples/10-all-widgets.rb +165 -0
  15. data/examples/calendar.rb +20 -32
  16. data/examples/entry.rb +15 -20
  17. data/examples/label.rb +11 -11
  18. data/examples/scroll.rb +16 -60
  19. data/examples/slider.rb +18 -19
  20. data/examples/viewer.rb +65 -0
  21. data/lib/rndk.rb +28 -7
  22. data/lib/rndk/alphalist.rb +309 -313
  23. data/lib/rndk/button.rb +239 -157
  24. data/lib/rndk/buttonbox.rb +136 -103
  25. data/lib/rndk/calendar.rb +246 -203
  26. data/lib/rndk/core/color.rb +63 -13
  27. data/lib/rndk/core/display.rb +1 -1
  28. data/lib/rndk/core/draw.rb +11 -11
  29. data/lib/rndk/core/markup.rb +21 -21
  30. data/lib/rndk/core/quick_widgets.rb +75 -96
  31. data/lib/rndk/core/screen.rb +145 -102
  32. data/lib/rndk/core/traverse.rb +150 -136
  33. data/lib/rndk/core/utils.rb +5 -6
  34. data/lib/rndk/core/widget.rb +207 -191
  35. data/lib/rndk/core/widget_bind.rb +108 -0
  36. data/lib/rndk/dialog.rb +88 -56
  37. data/lib/rndk/entry.rb +79 -64
  38. data/lib/rndk/fscale.rb +38 -20
  39. data/lib/rndk/fslider.rb +38 -23
  40. data/lib/rndk/graph.rb +92 -53
  41. data/lib/rndk/itemlist.rb +80 -62
  42. data/lib/rndk/label.rb +111 -77
  43. data/lib/rndk/radio.rb +138 -128
  44. data/lib/rndk/scale.rb +123 -122
  45. data/lib/rndk/scroll.rb +444 -391
  46. data/lib/rndk/scroller.rb +21 -21
  47. data/lib/rndk/slider.rb +149 -140
  48. data/lib/rndk/template.rb +74 -61
  49. data/lib/rndk/version.rb +1 -1
  50. data/lib/rndk/viewer.rb +499 -298
  51. metadata +8 -14
  52. data/demos/fileview.rb +0 -141
  53. data/lib/rndk/dscale.rb +0 -13
  54. data/lib/rndk/fselect.rb +0 -938
  55. data/lib/rndk/histogram.rb +0 -412
  56. data/lib/rndk/marquee.rb +0 -244
  57. data/lib/rndk/matrix.rb +0 -1189
  58. data/lib/rndk/mentry.rb +0 -619
  59. data/lib/rndk/menu.rb +0 -478
  60. data/lib/rndk/selection.rb +0 -630
  61. data/lib/rndk/swindow.rb +0 -766
  62. data/lib/rndk/uscale.rb +0 -14
  63. data/lib/rndk/uslider.rb +0 -14
@@ -1,412 +0,0 @@
1
- require 'rndk'
2
-
3
- module RNDK
4
- class HISTOGRAM < Widget
5
- def initialize(rndkscreen, xplace, yplace, height, width, orient,
6
- title, box, shadow)
7
- super()
8
- parent_width = Ncurses.getmaxx(rndkscreen.window)
9
- parent_height = Ncurses.getmaxy(rndkscreen.window)
10
-
11
- self.set_box(box)
12
-
13
- box_height = RNDK.setWidgetDimension(parent_height, height, 2)
14
- old_height = box_height
15
-
16
- box_width = RNDK.setWidgetDimension(parent_width, width, 0)
17
- old_width = box_width
18
-
19
- box_width = self.set_title(title, -(box_width + 1))
20
-
21
- # Increment the height by number of lines in in the title
22
- box_height += @title_lines
23
-
24
- # Make sure we didn't extend beyond the dimensions of the window.
25
- box_width = if box_width > parent_width
26
- then old_width
27
- else box_width
28
- end
29
- box_height = if box_height > parent_height
30
- then old_height
31
- else box_height
32
- end
33
-
34
- # Rejustify the x and y positions if we need to.
35
- xtmp = [xplace]
36
- ytmp = [yplace]
37
- RNDK.alignxy(rndkscreen.window, xtmp, ytmp, box_width, box_height)
38
- xpos = xtmp[0]
39
- ypos = ytmp[0]
40
-
41
- # Set up the histogram data
42
- @screen = rndkscreen
43
- @parent = rndkscreen.window
44
- @win = Ncurses.newwin(box_height, box_width, ypos, xpos)
45
- @shadow_win = nil
46
- @box_width = box_width
47
- @box_height = box_height
48
- @field_width = box_width - 2 * @border_size
49
- @field_height = box_height - @title_lines - 2 * @border_size
50
- @orient = orient
51
- @shadow = shadow
52
-
53
- # Is the window nil
54
- if @win.nil?
55
- self.destroy
56
- return nil
57
- end
58
-
59
- Ncurses.keypad(@win, true)
60
-
61
- # Set up some default values.
62
- @filler = '#'.ord | Ncurses::A_REVERSE
63
- @stats_attr = Ncurses::A_NORMAL
64
- @stats_pos = RNDK::TOP
65
- @view_type = :REAL
66
- @high = 0
67
- @low = 0
68
- @value = 0
69
- @lowx = 0
70
- @lowy = 0
71
- @highx = 0
72
- @highy = 0
73
- @curx = 0
74
- @cury = 0
75
- @low_string = ''
76
- @high_string = ''
77
- @cur_string = ''
78
-
79
- # Do we want a shadow?
80
- if shadow
81
- @shadow_win = Ncurses.newwin(box_height,
82
- box_width,
83
- ypos + 1,
84
- xpos + 1)
85
- end
86
-
87
- rndkscreen.register(:HISTOGRAM, self)
88
- end
89
-
90
- # This was added for the builder
91
- def activate(actions)
92
- self.draw(@box)
93
- end
94
-
95
- # Set various widget attributes
96
- def set(view_type, stats_pos, stats_attr, low, high, value, filler, box)
97
- self.setDisplayType(view_type)
98
- self.setStatsPos(stats_pos)
99
- self.setValue(low, high, value)
100
- self.setFillerChar(filler)
101
- self.setStatsAttr(stats_attr)
102
- self.set_box(box)
103
- end
104
-
105
- # Set the values for the widget.
106
- def setValue(low, high, value)
107
- # We should error check the information we have.
108
- @low = if low <= high then low else 0 end
109
- @high = if low <= high then high else 0 end
110
- @value = if low <= value && value <= high then value else 0 end
111
- # Determine the percentage of the given value.
112
- @percent = if @high == 0 then 0 else 1.0 * @value / @high end
113
-
114
- # Determine the size of the histogram bar.
115
- if @orient == RNDK::VERTICAL
116
- @bar_size = @percent * @field_height
117
- else
118
- @bar_size = @percent * @field_width
119
- end
120
-
121
- # We have a number of variables which determine the personality of the
122
- # histogram. We have to go through each one methodically, and set them
123
- # correctly. This section does this.
124
- if @view_type != :NONE
125
- if @orient == RNDK::VERTICAL
126
- if @stats_pos == RNDK::LEFT || @stats_pos == RNDK::BOTTOM
127
- # Set the low label attributes.
128
- @low_string = @low.to_s
129
- @lowx = 1
130
- @lowy = @box_height - @low_string.size - 1
131
-
132
- # Set the high label attributes
133
- @high_string = @high.to_s
134
- @highx = 1
135
- @highy = @title_lines + 1
136
-
137
- string = ''
138
- # Set the current value attributes.
139
- string = if @view_type == :PERCENT
140
- then "%3.1f%%" % [1.0 * @percent * 100]
141
- elsif @view_type == :FRACTION
142
- string = "%d/%d" % [@value, @high]
143
- else string = @value.to_s
144
- end
145
- @cur_string = string
146
- @curx = 1
147
- @cury = (@field_height - string.size) / 2 + @title_lines + 1
148
- elsif @stats_pos == RNDK::CENTER
149
- # Set the lower label attributes
150
- @low_string = @low.to_s
151
- @lowx = @field_width / 2 + 1
152
- @lowy = @box_height - @low_string.size - 1
153
-
154
- # Set the high label attributes
155
- @high_string = @high.to_s
156
- @highx = @field_width / 2 + 1
157
- @highy = @title_lines + 1
158
-
159
- # Set the stats label attributes
160
- string = if @view_type == :PERCENT
161
- then "%3.2f%%" % [1.0 * @percent * 100]
162
- elsif @view_type == :FRACTIOn
163
- "%d/%d" % [@value, @high]
164
- else @value.to_s
165
- end
166
-
167
- @cur_string = string
168
- @curx = @field_width / 2 + 1
169
- @cury = (@field_height - string.size) / 2 + @title_lines + 1
170
- elsif @stats_pos == RNDK::RIGHT || @stats_pos == RNDK::TOP
171
- # Set the low label attributes.
172
- @low_string = @low.to_s
173
- @lowx = @field_width
174
- @lowy = @box_height - @low_string.size - 1
175
-
176
- # Set the high label attributes.
177
- @high_string = @high.to_s
178
- @highx = @field_width
179
- @highy = @title_lines + 1
180
-
181
- # Set the stats label attributes.
182
- string = if @view_type == :PERCENT
183
- then "%3.2f%%" % [1.0 * @percent * 100]
184
- elsif @view_type == :FRACTION
185
- "%d/%d" % [@value, @high]
186
- else @value.to_s
187
- end
188
- @cur_string = string
189
- @curx = @field_width
190
- @cury = (@field_height - string.size) / 2 + @title_lines + 1
191
- end
192
- else
193
- # Alignment is HORIZONTAL
194
- if @stats_pos == RNDK::TOP || @stats_pos == RNDK::RIGHT
195
- # Set the low label attributes.
196
- @low_string = @low.to_s
197
- @lowx = 1
198
- @lowy = @title_lines + 1
199
-
200
- # Set the high label attributes.
201
- @high_string = @high.to_s
202
- @highx = @box_width - @high_string.size - 1
203
- @highy = @title_lines + 1
204
-
205
- # Set the stats label attributes.
206
- string = if @view_type == :PERCENT
207
- then "%3.1f%%" % [1.0 * @percent * 100]
208
- elsif @view_type == :FRACTION
209
- "%d/%d" % [@value, @high]
210
- else @value.to_s
211
- end
212
- @cur_string = string
213
- @curx = (@field_width - @cur_string.size) / 2 + 1
214
- @cury = @title_lines + 1
215
- elsif @stats_pos == RNDK::CENTER
216
- # Set the low label attributes.
217
- @low_string = @low.to_s
218
- @lowx = 1
219
- @lowy = (@field_height / 2) + @title_lines + 1
220
-
221
- # Set the high label attributes.
222
- @high_string = @high.to_s
223
- @highx = @box_width - @high_string.size - 1
224
- @highy = @field_height / 2 + @title_lines + 1
225
-
226
- # Set the stats label attributes.
227
- string = if @view_type == :PERCENT
228
- then "%3.1f%%" % [1.0 * @percent * 100]
229
- elsif @view_type == :FRACTION
230
- "%d/%d" % [@value, @high]
231
- else @value.to_s
232
- end
233
- @cur_string = string
234
- @curx = (@field_width - @cur_string.size) / 2 + 1
235
- @cury = @field_height / 2 + @title_lines + 1
236
- elsif @stats_pos == RNDK::BOTTOM || @stats_pos == RNDK::LEFT
237
- # Set the low label attributes.
238
- @low_string = @low.to_s
239
- @lowx = 1
240
- @lowy = @box_height -2 * @border_size
241
-
242
- # Set the high label attributes.
243
- @high_string = @high.to_s
244
- @highx = @box_width - @high_string.size - 1
245
- @highy = @box_height - 2 * @border_size
246
-
247
- # Set the stats label attributes.
248
- string = if @view_type == :PERCENT
249
- then "%3.1f%%" % [1.0 * @percent * 100]
250
- elsif @view_type == :FRACTION
251
- "%d/%d" % [@value, @high]
252
- else @value.to_s
253
- end
254
- @cur_string = string
255
- @curx = (@field_width - @cur_string.size) / 2 + 1
256
- @cury = @box_height - 2 * @border_size
257
- end
258
- end
259
- end
260
- end
261
-
262
- def getValue
263
- return @value
264
- end
265
-
266
- def getLowValue
267
- return @low
268
- end
269
-
270
- def getHighValue
271
- return @high
272
- end
273
-
274
- # Set the histogram display type
275
- def setDisplayType(view_type)
276
- @view_type = view_type
277
- end
278
-
279
- def getViewType
280
- return @view_type
281
- end
282
-
283
- # Set the position of the statistics information.
284
- def setStatsPos(stats_pos)
285
- @stats_pos = stats_pos
286
- end
287
-
288
- def getStatsPos
289
- return @stats_pos
290
- end
291
-
292
- # Set the attribute of the statistics.
293
- def setStatsAttr(stats_attr)
294
- @stats_attr = stats_attr
295
- end
296
-
297
- def getStatsAttr
298
- return @stats_attr
299
- end
300
-
301
- # Set the character to use when drawing the widget.
302
- def setFillerChar(character)
303
- @filler = character
304
- end
305
-
306
- def getFillerChar
307
- return @filler
308
- end
309
-
310
- # Set the background attribute of the widget.
311
- def set_bg_attrib(attrib)
312
- Ncurses.wbkgd(@win, attrib)
313
- end
314
-
315
- # Move the histogram field to the given location.
316
- # Inherited
317
- # def move(xplace, yplace, relative, refresh_flag)
318
- # end
319
-
320
- # Draw the widget.
321
- def draw(box)
322
- battr = 0
323
- bchar = 0
324
- fattr = @filler & Ncurses::A_ATTRIBUTES
325
- hist_x = @title_lines + 1
326
- hist_y = @bar_size
327
-
328
- Ncurses.werase(@win)
329
-
330
- # Box the widget if asked.
331
- if box
332
- Draw.drawObjBox(@win, self)
333
- end
334
-
335
- # Do we have a shadow to draw?
336
- if !(@shadow.nil?)
337
- Draw.drawShadow(@shadow_win)
338
- end
339
-
340
- self.drawTitle(@win)
341
-
342
- # If the user asked for labels, draw them in.
343
- if @view_type != :NONE
344
- # Draw in the low label.
345
- if @low_string.size > 0
346
- Draw.writeCharAttrib(@win, @lowx, @lowy, @low_string,
347
- @stats_attr, @orient, 0, @low_string.size)
348
- end
349
-
350
- # Draw in the current value label.
351
- if @cur_string.size > 0
352
- Draw.writeCharAttrib(@win, @curx, @cury, @cur_string,
353
- @stats_attr, @orient, 0, @cur_string.size)
354
- end
355
-
356
- # Draw in the high label.
357
- if @high_string.size > 0
358
- Draw.writeCharAttrib(@win, @highx, @highy, @high_string,
359
- @stats_attr, @orient, 0, @high_string.size)
360
- end
361
- end
362
-
363
- if @orient == RNDK::VERTICAL
364
- hist_x = @box_height - @bar_size - 1
365
- hist_y = @field_width
366
- end
367
-
368
- # Draw the histogram bar.
369
- (hist_x...@box_height - 1).to_a.each do |x|
370
- (1..hist_y).each do |y|
371
- battr = Ncurses.mvwinch(@win, x, y)
372
-
373
- if battr == ' '.ord
374
- Ncurses.mvwaddch(@win, x, y, @filler)
375
- else
376
- Ncurses.mvwaddch(@win, x, y, battr | fattr)
377
- end
378
- end
379
- end
380
-
381
- # Refresh the window
382
- Ncurses.wrefresh @win
383
- end
384
-
385
- # Destroy the widget.
386
- def destroy
387
- self.cleanTitle
388
-
389
- # Clean up the windows.
390
- RNDK.window_delete(@shadow_win)
391
- RNDK.window_delete(@win)
392
-
393
- # Clean the key bindings.
394
- self.clean_bindings(:HISTOGRAM)
395
-
396
- # Unregister this object.
397
- RNDK::Screen.unregister(:HISTOGRAM, self)
398
- end
399
-
400
- # Erase the widget from the screen.
401
- def erase
402
- if self.valid_widget?
403
- RNDK.window_erase(@win)
404
- RNDK.window_erase(@shadow_win)
405
- end
406
- end
407
-
408
- def object_type
409
- :HISTOGRAM
410
- end
411
- end
412
- end
@@ -1,244 +0,0 @@
1
- require 'rndk'
2
-
3
- module RNDK
4
- class MARQUEE < 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.set_box(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.set_box(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.window_delete(@shadow_win)
162
- RNDK.window_delete(@win)
163
-
164
- # Clean the key bindings.
165
- self.clean_bindings(: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.valid_widget?
174
- RNDK.window_erase(@win)
175
- RNDK.window_erase(@shadow_win)
176
- end
177
- end
178
-
179
- # This sets the widgets box attribute.
180
- def set_box(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 set_bg_attrib(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