cdk 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cdk.rb +7 -866
  3. data/lib/cdk/cdk_objs.rb +46 -423
  4. data/lib/cdk/components.rb +28 -0
  5. data/lib/cdk/{alphalist.rb → components/alphalist.rb} +9 -6
  6. data/lib/cdk/components/button.rb +405 -0
  7. data/lib/cdk/{buttonbox.rb → components/buttonbox.rb} +11 -11
  8. data/lib/cdk/{calendar.rb → components/calendar.rb} +13 -13
  9. data/lib/cdk/components/dialog.rb +343 -0
  10. data/lib/cdk/{dscale.rb → components/dscale.rb} +0 -0
  11. data/lib/cdk/{entry.rb → components/entry.rb} +18 -18
  12. data/lib/cdk/{fscale.rb → components/fscale.rb} +1 -1
  13. data/lib/cdk/{fselect.rb → components/fselect.rb} +16 -13
  14. data/lib/cdk/{fslider.rb → components/fslider.rb} +1 -1
  15. data/lib/cdk/components/graph.rb +386 -0
  16. data/lib/cdk/{histogram.rb → components/histogram.rb} +3 -3
  17. data/lib/cdk/{itemlist.rb → components/itemlist.rb} +14 -14
  18. data/lib/cdk/{label.rb → components/label.rb} +7 -7
  19. data/lib/cdk/{marquee.rb → components/marquee.rb} +7 -7
  20. data/lib/cdk/{matrix.rb → components/matrix.rb} +27 -27
  21. data/lib/cdk/{mentry.rb → components/mentry.rb} +18 -18
  22. data/lib/cdk/{menu.rb → components/menu.rb} +18 -18
  23. data/lib/cdk/{radio.rb → components/radio.rb} +12 -12
  24. data/lib/cdk/{scale.rb → components/scale.rb} +13 -13
  25. data/lib/cdk/{scroll.rb → components/scroll.rb} +23 -386
  26. data/lib/cdk/{scroller.rb → components/scroller.rb} +1 -1
  27. data/lib/cdk/{selection.rb → components/selection.rb} +14 -14
  28. data/lib/cdk/{slider.rb → components/slider.rb} +15 -15
  29. data/lib/cdk/{swindow.rb → components/swindow.rb} +14 -14
  30. data/lib/cdk/{template.rb → components/template.rb} +18 -18
  31. data/lib/cdk/{uscale.rb → components/uscale.rb} +0 -0
  32. data/lib/cdk/{uslider.rb → components/uslider.rb} +0 -0
  33. data/lib/cdk/{viewer.rb → components/viewer.rb} +88 -18
  34. data/lib/cdk/constants.rb +54 -0
  35. data/lib/cdk/display.rb +30 -35
  36. data/lib/cdk/draw.rb +4 -6
  37. data/lib/cdk/helpers/file.rb +43 -0
  38. data/lib/cdk/helpers/types.rb +13 -0
  39. data/lib/cdk/helpers/window.rb +64 -0
  40. data/lib/cdk/mixins/alignments.rb +55 -0
  41. data/lib/cdk/mixins/bindings.rb +73 -0
  42. data/lib/cdk/mixins/borders.rb +62 -0
  43. data/lib/cdk/mixins/common_controls.rb +14 -0
  44. data/lib/cdk/mixins/converters.rb +358 -0
  45. data/lib/cdk/mixins/exit_conditions.rb +31 -0
  46. data/lib/cdk/mixins/focusable.rb +17 -0
  47. data/lib/cdk/mixins/formattable.rb +15 -0
  48. data/lib/cdk/mixins/has_screen.rb +23 -0
  49. data/lib/cdk/mixins/has_title.rb +64 -0
  50. data/lib/cdk/mixins/justifications.rb +26 -0
  51. data/lib/cdk/mixins/list_support.rb +31 -0
  52. data/lib/cdk/mixins/movement.rb +140 -0
  53. data/lib/cdk/mixins/window_hooks.rb +18 -0
  54. data/lib/cdk/mixins/window_input.rb +61 -0
  55. data/lib/cdk/screen.rb +27 -3
  56. metadata +51 -29
  57. data/lib/cdk/dialog.rb +0 -727
@@ -1,4 +1,4 @@
1
- require_relative 'cdk_objs'
1
+ require_relative '../cdk_objs'
2
2
 
3
3
  module CDK
4
4
  class ENTRY < CDK::CDKOBJS
@@ -32,7 +32,7 @@ module CDK
32
32
  # Translate the label string to a chtype array
33
33
  if !(label.nil?) && label.size > 0
34
34
  label_len = [@label_len]
35
- @label = CDK.char2Chtype(label, label_len, [])
35
+ @label = char2Chtype(label, label_len, [])
36
36
  @label_len = label_len[0]
37
37
  box_width += @label_len
38
38
  end
@@ -52,7 +52,7 @@ module CDK
52
52
  # Rejustify the x and y positions if we need to.
53
53
  xtmp = [xpos]
54
54
  ytmp = [ypos]
55
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
55
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
56
56
  xpos = xtmp[0]
57
57
  ypos = ytmp[0]
58
58
 
@@ -82,7 +82,7 @@ module CDK
82
82
  xpos + horizontal_adjust + @border_size)
83
83
  end
84
84
 
85
- # cleanChar (entry->info, max + 3, '\0');
85
+ #entry->info += '\0' * (max + 3)
86
86
  @info = ''
87
87
  @info_width = max + 3
88
88
 
@@ -198,7 +198,7 @@ module CDK
198
198
  def inject(input)
199
199
  pp_return = 1
200
200
  ret = 1
201
- complete = false
201
+ @complete = false
202
202
 
203
203
  # Set the exit type
204
204
  self.setExitType(0)
@@ -215,7 +215,7 @@ module CDK
215
215
  if pp_return != 0
216
216
  # Check a predefined binding
217
217
  if self.checkBind(:ENTRY, input)
218
- complete = true
218
+ @complete = true
219
219
  else
220
220
  curr_pos = @screen_col + @left_char
221
221
 
@@ -295,7 +295,7 @@ module CDK
295
295
  end
296
296
  when CDK::KEY_ESC
297
297
  self.setExitType(input)
298
- complete = true
298
+ @complete = true
299
299
  when CDK::ERASE
300
300
  if @info.size != 0
301
301
  self.clean
@@ -326,13 +326,13 @@ module CDK
326
326
  if @info.size >= @min
327
327
  self.setExitType(input)
328
328
  ret = @info
329
- complete = true
329
+ @complete = true
330
330
  else
331
331
  CDK.Beep
332
332
  end
333
333
  when Ncurses::ERR
334
334
  self.setExitType(input)
335
- complete = true
335
+ @complete = true
336
336
  when CDK::REFRESH
337
337
  @screen.erase
338
338
  @screen.refresh
@@ -341,12 +341,12 @@ module CDK
341
341
  end
342
342
  end
343
343
 
344
- if !complete && !(@post_process_func.nil?)
344
+ if !@complete && !(@post_process_func.nil?)
345
345
  @post_process_func.call(:ENTRY, self, @post_process_data, input)
346
346
  end
347
347
  end
348
348
 
349
- unless complete
349
+ unless @complete
350
350
  self.setExitType(0)
351
351
  end
352
352
 
@@ -376,7 +376,7 @@ module CDK
376
376
  @left_char = 0
377
377
 
378
378
  # Refresh the entry field.
379
- @field_win.wrefresh
379
+ wrefresh(@field_win)
380
380
  end
381
381
 
382
382
  # This draws the entry field.
@@ -393,13 +393,13 @@ module CDK
393
393
 
394
394
  self.drawTitle(@win)
395
395
 
396
- @win.wrefresh
396
+ wrefresh
397
397
 
398
398
  # Draw in the label to the widget.
399
399
  unless @label_win.nil?
400
400
  Draw.writeChtype(@label_win, 0, 0, @label, CDK::HORIZONTAL, 0,
401
401
  @label_len)
402
- @label_win.wrefresh
402
+ wrefresh(@label_win)
403
403
  end
404
404
 
405
405
  self.drawField
@@ -424,7 +424,7 @@ module CDK
424
424
  @field_win.wmove(0, @screen_col)
425
425
  end
426
426
 
427
- @field_win.wrefresh
427
+ wrefresh(@field_win)
428
428
  end
429
429
 
430
430
  # This erases an entry widget from the screen.
@@ -505,7 +505,7 @@ module CDK
505
505
  end
506
506
 
507
507
  # This sets the character to use when a hidden type is used.
508
- def setHiddenChar(hidden_characer)
508
+ def setHiddenChar(hidden_character)
509
509
  @hidden = hidden_character
510
510
  end
511
511
 
@@ -537,12 +537,12 @@ module CDK
537
537
 
538
538
  def focus
539
539
  @field_win.wmove(0, @screen_col)
540
- @field_win.wrefresh
540
+ wrefresh(@field_win)
541
541
  end
542
542
 
543
543
  def unfocus
544
544
  self.draw(box)
545
- @field_win.wrefresh
545
+ wrefresh(@field_win)
546
546
  end
547
547
 
548
548
  def position
@@ -22,7 +22,7 @@ module CDK
22
22
  CDK::HORIZONTAL, 0, temp.size)
23
23
 
24
24
  self.moveToEditPosition(@field_edit)
25
- @field_win.wrefresh
25
+ wrefresh(@field_win)
26
26
  end
27
27
 
28
28
  def setDigits(digits)
@@ -1,7 +1,10 @@
1
- require_relative 'cdk_objs'
1
+ require_relative '../cdk_objs'
2
+ require_relative '../mixins/list_support'
2
3
 
3
4
  module CDK
4
5
  class FSELECT < CDK::CDKOBJS
6
+ include ListSupport
7
+
5
8
  attr_reader :scroll_field, :entry_field
6
9
  attr_reader :dir_attribute, :file_attribute, :link_attribute, :highlight
7
10
  attr_reader :sock_attribute, :field_attribute, :filler_character
@@ -31,7 +34,7 @@ module CDK
31
34
  # Rejustify the x and y positions if we need to.
32
35
  xtmp = [xplace]
33
36
  ytmp = [yplace]
34
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
37
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
35
38
  xpos = xtmp[0]
36
39
  ypos = ytmp[0]
37
40
 
@@ -76,7 +79,7 @@ module CDK
76
79
 
77
80
  # Create the entry field in the selector
78
81
  label_len = []
79
- CDK.char2Chtype(label, label_len, [])
82
+ char2Chtype(label, label_len, [])
80
83
  label_len = label_len[0]
81
84
 
82
85
  temp_width = if CDK::FSELECT.isFullWidth(width)
@@ -207,7 +210,7 @@ module CDK
207
210
  end
208
211
 
209
212
  # Look for a unique filename match.
210
- index = CDK.searchList(list, fselect.file_counter, filename)
213
+ index = search_list(list, fselect.file_counter, filename)
211
214
 
212
215
  # If the index is less than zero, return we didn't find a match.
213
216
  if index < 0
@@ -285,7 +288,7 @@ module CDK
285
288
  buttons = ['No', 'Yes']
286
289
 
287
290
  # Get the filename which is to be deleted.
288
- filename = CDK.chtype2Char(fscroll.item[fscroll.current_item])
291
+ filename = chtype2Char(fscroll.item[fscroll.current_item])
289
292
  filename = filename[0...-1]
290
293
 
291
294
  # Create the dialog message.
@@ -334,8 +337,8 @@ module CDK
334
337
  fselect.injectMyScroller(key)
335
338
 
336
339
  # Get the currently highlighted filename.
337
- current = CDK.chtype2Char(scrollp.item[scrollp.current_item])
338
- #current = CDK.chtype2String(scrollp.item[scrollp.current_item])
340
+ current = chtype2Char(scrollp.item[scrollp.current_item])
341
+ #current = chtype2String(scrollp.item[scrollp.current_item])
339
342
  current = current[0...-1]
340
343
 
341
344
  temp = CDK::FSELECT.make_pathname(fselect.pwd, current)
@@ -486,7 +489,7 @@ module CDK
486
489
  # This injects a single character into the file selector.
487
490
  def inject(input)
488
491
  ret = -1
489
- complete = false
492
+ @complete = false
490
493
 
491
494
  # Let the user play.
492
495
  filename = @entry_field.inject(input)
@@ -512,7 +515,7 @@ module CDK
512
515
 
513
516
  # Return the complete pathname.
514
517
  ret = @pathname
515
- complete = true
518
+ @complete = true
516
519
  else
517
520
  # Set the file selector information.
518
521
  self.set(filename, @field_attribute, @filler_character, @highlight,
@@ -523,7 +526,7 @@ module CDK
523
526
  self.drawMyScroller
524
527
  end
525
528
 
526
- if !complete
529
+ if !@complete
527
530
  self.setExitType(0)
528
531
  end
529
532
 
@@ -869,9 +872,9 @@ module CDK
869
872
  # Return the plain string that corresponds to an item in dir_contents
870
873
  def contentToPath(content)
871
874
  # XXX direct translation of original but might be redundant
872
- temp_chtype = CDK.char2Chtype(content, [], [])
873
- temp_char = CDK.chtype2Char(temp_chtype)
874
- temp_char = temp_char[0..-1]
875
+ temp_chtype = char2Chtype(content, [], [])
876
+ temp_char = chtype2Char(temp_chtype)
877
+ temp_char = temp_char[0..-1]
875
878
 
876
879
  # Create the pathname.
877
880
  result = CDK::FSELECT.make_pathname(@pwd, temp_char)
@@ -32,7 +32,7 @@ module CDK
32
32
  Ncurses::A_NORMAL, CDK::HORIZONTAL, 0, temp.size)
33
33
 
34
34
  self.moveToEditPosition(@field_edit)
35
- @field_win.wrefresh
35
+ wrefresh(@field_win)
36
36
  end
37
37
 
38
38
  def formattedSize(value)
@@ -0,0 +1,386 @@
1
+ require_relative '../cdk_objs'
2
+
3
+ module CDK
4
+ class GRAPH < CDK::CDKOBJS
5
+ def initialize(cdkscreen, xplace, yplace, height, width,
6
+ title, xtitle, ytitle)
7
+ super()
8
+ parent_width = cdkscreen.window.getmaxx
9
+ parent_height = cdkscreen.window.getmaxy
10
+
11
+ self.setBox(false)
12
+
13
+ box_height = CDK.setWidgetDimension(parent_height, height, 3)
14
+ box_width = CDK.setWidgetDimension(parent_width, width, 0)
15
+ box_width = self.setTitle(title, box_width)
16
+ box_height += @title_lines
17
+ box_width = [parent_width, box_width].min
18
+ box_height = [parent_height, box_height].min
19
+
20
+ # Rejustify the x and y positions if we need to
21
+ xtmp = [xplace]
22
+ ytmp = [yplace]
23
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
24
+ xpos = xtmp[0]
25
+ ypos = ytmp[0]
26
+
27
+ # Create the widget pointer
28
+ @screen = cdkscreen
29
+ @parent = cdkscreen.window
30
+ @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos)
31
+ @box_height = box_height
32
+ @box_width = box_width
33
+ @minx = 0
34
+ @maxx = 0
35
+ @xscale = 0
36
+ @yscale = 0
37
+ @count = 0
38
+ @display_type = :LINE
39
+
40
+ if @win.nil?
41
+ self.destroy
42
+ return nil
43
+ end
44
+ @win.keypad(true)
45
+
46
+ # Translate the X axis title string to a chtype array
47
+ if !(xtitle.nil?) && xtitle.size > 0
48
+ xtitle_len = []
49
+ xtitle_pos = []
50
+ @xtitle = char2Chtype(xtitle, xtitle_len, xtitle_pos)
51
+ @xtitle_len = xtitle_len[0]
52
+ @xtitle_pos = justify_string(@box_height, @xtitle_len, xtitle_pos[0])
53
+
54
+ else
55
+ xtitle_len = []
56
+ xtitle_pos = []
57
+ @xtitle = char2Chtype("<C></5>X Axis", xtitle_len, xtitle_pos)
58
+ @xtitle_len = title_len[0]
59
+ @xtitle_pos = justify_string(@box_height, @xtitle_len, xtitle_pos[0])
60
+ end
61
+
62
+ # Translate the Y Axis title string to a chtype array
63
+ if !(ytitle.nil?) && ytitle.size > 0
64
+ ytitle_len = []
65
+ ytitle_pos = []
66
+ @ytitle = char2Chtype(ytitle, ytitle_len, ytitle_pos)
67
+ @ytitle_len = ytitle_len[0]
68
+ @ytitle_pos = justify_string(@box_width, @ytitle_len, ytitle_pos[0])
69
+ else
70
+ ytitle_len = []
71
+ ytitle_pos = []
72
+ @ytitle = char2Chtype("<C></5>Y Axis", ytitle_len, ytitle_pos)
73
+ @ytitle_len = ytitle_len[0]
74
+ @ytitle_pos = justify_string(@box_width, @ytitle_len, ytitle_pos[0])
75
+ end
76
+
77
+ @graph_char = 0
78
+ @values = []
79
+
80
+ cdkscreen.register(:GRAPH, self)
81
+ end
82
+
83
+ # This was added for the builder.
84
+ def activate(actions)
85
+ self.draw(@box)
86
+ end
87
+
88
+ # Set multiple attributes of the widget
89
+ def set(values, count, graph_char, start_at_zero, display_type)
90
+ ret = self.setValues(values, count, start_at_zero)
91
+ self.setCharacters(graph_char)
92
+ self.setDisplayType(display_type)
93
+ return ret
94
+ end
95
+
96
+ # Set the scale factors for the graph after wee have loaded new values.
97
+ def setScales
98
+ @xscale = (@maxx - @minx) / [1, @box_height - @title_lines - 5].max
99
+ if @xscale <= 0
100
+ @xscale = 1
101
+ end
102
+
103
+ @yscale = (@box_width - 4) / [1, @count].max
104
+ if @yscale <= 0
105
+ @yscale = 1
106
+ end
107
+ end
108
+
109
+ # Set the values of the graph.
110
+ def setValues(values, count, start_at_zero)
111
+ min = 2**30
112
+ max = -2**30
113
+
114
+ # Make sure everything is happy.
115
+ if count < 0
116
+ return false
117
+ end
118
+
119
+ if !(@values.nil?) && @values.size > 0
120
+ @values = []
121
+ @count = 0
122
+ end
123
+
124
+ # Copy the X values
125
+ values.each do |value|
126
+ min = [value, @minx].min
127
+ max = [value, @maxx].max
128
+
129
+ # Copy the value.
130
+ @values << value
131
+ end
132
+
133
+ # Keep the count and min/max values
134
+ @count = count
135
+ @minx = min
136
+ @maxx = max
137
+
138
+ # Check the start at zero status.
139
+ if start_at_zero
140
+ @minx = 0
141
+ end
142
+
143
+ self.setScales
144
+
145
+ return true
146
+ end
147
+
148
+ def getValues(size)
149
+ size << @count
150
+ return @values
151
+ end
152
+
153
+ # Set the value of the graph at the given index.
154
+ def setValue(index, value, start_at_zero)
155
+ # Make sure the index is within range.
156
+ if index < 0 || index >= @count
157
+ return false
158
+ end
159
+
160
+ # Set the min, max, and value for the graph
161
+ @minx = [value, @minx].min
162
+ @maxx = [value, @maxx].max
163
+ @values[index] = value
164
+
165
+ # Check the start at zero status
166
+ if start_at_zero
167
+ @minx = 0
168
+ end
169
+
170
+ self.setScales
171
+
172
+ return true
173
+ end
174
+
175
+ def getValue(index)
176
+ if index >= 0 && index < @count then @values[index] else 0 end
177
+ end
178
+
179
+ # Set the characters of the graph widget.
180
+ def setCharacters(characters)
181
+ char_count = []
182
+ new_tokens = char2Chtype(characters, char_count, [])
183
+
184
+ if char_count[0] != @count
185
+ return false
186
+ end
187
+
188
+ @graph_char = new_tokens
189
+ return true
190
+ end
191
+
192
+ def getCharacters
193
+ return @graph_char
194
+ end
195
+
196
+ # Set the character of the graph widget of the given index.
197
+ def setCharacter(index, character)
198
+ # Make sure the index is within range
199
+ if index < 0 || index > @count
200
+ return false
201
+ end
202
+
203
+ # Convert the string given to us
204
+ char_count = []
205
+ new_tokens = char2Chtype(character, char_count, [])
206
+
207
+ # Check if the number of characters back is the same as the number
208
+ # of elements in the list.
209
+ if char_count[0] != @count
210
+ return false
211
+ end
212
+
213
+ # Everything OK so far. Set the value of the array.
214
+ @graph_char[index] = new_tokens[0]
215
+ return true
216
+ end
217
+
218
+ def getCharacter(index)
219
+ return graph_char[index]
220
+ end
221
+
222
+ # Set the display type of the graph.
223
+ def setDisplayType(type)
224
+ @display_type = type
225
+ end
226
+
227
+ def getDisplayType
228
+ @display_type
229
+ end
230
+
231
+ # Set the background attribute of the widget.
232
+ def setBKattr(attrib)
233
+ @win.wbkgd(attrib)
234
+ end
235
+
236
+ # Move the graph field to the given location.
237
+ def move(xplace, yplace, relative, refresh_flag)
238
+ current_x = @win.getbegx
239
+ current_y = @win.getbegy
240
+ xpos = xplace
241
+ ypos = yplace
242
+
243
+ # If this is a relative move, then we will adjust where we want
244
+ # to move to
245
+ if relative
246
+ xpos = @win.getbegx + xplace
247
+ ypos = @win.getbegy + yplace
248
+ end
249
+
250
+ # Adjust the window if we need to.
251
+ xtmp = [xpos]
252
+ tymp = [ypos]
253
+ CDK.alignxy(@screen.window, xtmp, ytmp, @box_width, @box_height)
254
+ xpos = xtmp[0]
255
+ ypos = ytmp[0]
256
+
257
+ # Get the difference
258
+ xdiff = current_x - xpos
259
+ ydiff = current_y - ypos
260
+
261
+ # Move the window to the new location.
262
+ CDK.moveCursesWindow(@win, -xdiff, -ydiff)
263
+ CDK.moveCursesWindow(@shadow_win, -xdiff, -ydiff)
264
+
265
+ # Touch the windows so they 'move'.
266
+ CDK::SCREEN.refreshCDKWindow(@screen.window)
267
+
268
+ # Reraw the windowk if they asked for it
269
+ if refresh_flag
270
+ self.draw(@box)
271
+ end
272
+ end
273
+
274
+ # Draw the grpah widget
275
+ def draw(box)
276
+ adj = 2 + (if @xtitle.nil? || @xtitle.size == 0 then 0 else 1 end)
277
+ spacing = 0
278
+ attrib = ' '.ord | Ncurses::A_REVERSE
279
+
280
+ if box
281
+ Draw.drawObjBox(@win, self)
282
+ end
283
+
284
+ # Draw in the vertical axis
285
+ Draw.drawLine(@win, 2, @title_lines + 1, 2, @box_height - 3,
286
+ Ncurses::ACS_VLINE)
287
+
288
+ # Draw in the horizontal axis
289
+ Draw.drawLine(@win, 3, @box_height - 3, @box_width, @box_height - 3,
290
+ Ncurses::ACS_HLINE)
291
+
292
+ self.drawTitle(@win)
293
+
294
+ # Draw in the X axis title.
295
+ if !(@xtitle.nil?) && @xtitle.size > 0
296
+ Draw.writeChtype(@win, 0, @xtitle_pos, @xtitle, CDK::VERTICAL,
297
+ 0, @xtitle_len)
298
+ attrib = @xtitle[0] & Ncurses::A_ATTRIBUTES
299
+ end
300
+
301
+ # Draw in the X axis high value
302
+ temp = "%d" % [@maxx]
303
+ Draw.writeCharAttrib(@win, 1, @title_lines + 1, temp, attrib,
304
+ CDK::VERTICAL, 0, temp.size)
305
+
306
+ # Draw in the X axis low value.
307
+ temp = "%d" % [@minx]
308
+ Draw.writeCharAttrib(@win, 1, @box_height - 2 - temp.size, temp, attrib,
309
+ CDK::VERTICAL, 0, temp.size)
310
+
311
+ # Draw in the Y axis title
312
+ if !(@ytitle.nil?) && @ytitle.size > 0
313
+ Draw.writeChtype(@win, @ytitle_pos, @box_height - 1, @ytitle,
314
+ CDK::HORIZONTAL, 0, @ytitle_len)
315
+ end
316
+
317
+ # Draw in the Y axis high value.
318
+ temp = "%d" % [@count]
319
+ Draw.writeCharAttrib(@win, @box_width - temp.size - adj,
320
+ @box_height - 2, temp, attrib, CDK::HORIZONTAL, 0, temp.size)
321
+
322
+ # Draw in the Y axis low value.
323
+ Draw.writeCharAttrib(@win, 3, @box_height - 2, "0", attrib,
324
+ CDK::HORIZONTAL, 0, "0".size)
325
+
326
+ # If the count is zero then there aren't any points.
327
+ if @count == 0
328
+ wrefresh(@win)
329
+ return
330
+ end
331
+
332
+ spacing = (@box_width - 3) / @count # FIXME magic number (TITLE_LM)
333
+
334
+ # Draw in the graph line/plot points.
335
+ (0...@count).each do |y|
336
+ colheight = (@values[y] / @xscale) - 1
337
+ # Add the marker on the Y axis.
338
+ @win.mvwaddch(@box_height - 3, (y + 1) * spacing + adj,
339
+ Ncurses::ACS_TTEE)
340
+
341
+ # If this is a plot graph, all we do is draw a dot.
342
+ if @display_type == :PLOT
343
+ xpos = @box_height - 4 - colheight
344
+ ypos = (y + 1) * spacing + adj
345
+ @win.mvwaddch(xpos, ypos, @graph_char[y])
346
+ else
347
+ (0..@yscale).each do |x|
348
+ xpos = @box_height - 3
349
+ ypos = (y + 1) * spacing - adj
350
+ Draw.drawLine(@win, ypos, xpos - colheight, ypos, xpos,
351
+ @graph_char[y])
352
+ end
353
+ end
354
+ end
355
+
356
+ # Draw in the axis corners.
357
+ @win.mvwaddch(@title_lines, 2, Ncurses::ACS_URCORNER)
358
+ @win.mvwaddch(@box_height - 3, 2, Ncurses::ACS_LLCORNER)
359
+ @win.mvwaddch(@box_height - 3, @box_width, Ncurses::ACS_URCORNER)
360
+
361
+ # Refresh and lets see it
362
+ wrefresh
363
+ end
364
+
365
+ def destroy
366
+ self.cleanTitle
367
+ self.cleanBindings(:GRAPH)
368
+ CDK::SCREEN.unregister(:GRAPH, self)
369
+ CDK.deleteCursesWindow(@win)
370
+ end
371
+
372
+ def erase
373
+ if self.validCDKObject
374
+ CDK.eraseCursesWindow(@win)
375
+ end
376
+ end
377
+
378
+ def object_type
379
+ :GRAPH
380
+ end
381
+
382
+ def position
383
+ super(@win)
384
+ end
385
+ end # class Graph
386
+ end # module CDK