home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / Tutorial / Cookbook / 31.NumberLine / NumberLineView.m < prev    next >
Encoding:
Text File  |  1993-01-19  |  1.6 KB  |  85 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import <stdio.h>
  5. #import "NumberLineView.h"
  6. #import <appkit/Control.h>
  7. #import <dpsclient/wraps.h>
  8.  
  9. #define LEFT_MARGIN 10.0
  10. #define RIGHT_MARGIN 30.0
  11.  
  12. @implementation NumberLineView
  13.  
  14. +newFrame:(const NXRect *)tF {
  15.     self = [super newFrame:tF];
  16.     max = min = 50.0;
  17.     return self;
  18. }
  19.  
  20. - setMinText:anObject
  21. {
  22.     minText = anObject;
  23.     return self;
  24. }
  25.  
  26. - setMaxText:anObject
  27. {
  28.     maxText = anObject;
  29.     return self;
  30. }
  31.  
  32. - newMinValue:sender
  33. {
  34.     min = [sender floatValue];
  35.     [minText setFloatValue:min];
  36.     [self display];
  37.     return self;
  38. }
  39.  
  40. - newMaxValue:sender
  41. {
  42.     max = [sender floatValue];
  43.     [maxText setFloatValue:max];
  44.     [self display];
  45.     return self;
  46. }
  47.  
  48. - drawSelf:(NXRect*)r :(int)c
  49. {
  50.     char str[10];
  51.     int i;
  52.     float width,vert,scale;
  53.     width = bounds.size.width-RIGHT_MARGIN-LEFT_MARGIN;
  54.     vert = bounds.size.height/2.0;
  55.     scale = (bounds.size.width-RIGHT_MARGIN-LEFT_MARGIN)/100.0;
  56.     PSsetgray(NX_WHITE);
  57.     NXRectFill(r);
  58.     PSsetgray(NX_LTGRAY);
  59.     PSsetlinewidth(1.0);
  60.     PSnewpath();
  61.         PSmoveto(LEFT_MARGIN, vert);
  62.         PSrlineto(width, 0.0);
  63.     PSstroke();
  64.     PSsetgray(NX_DKGRAY);
  65.     PSsetlinewidth(5.0);
  66.     PSnewpath();
  67.         PSmoveto(LEFT_MARGIN+(0.0)*scale, vert);
  68.         PSlineto(LEFT_MARGIN+min*scale, vert);
  69.     PSstroke();
  70.     PSnewpath();
  71.         PSmoveto(LEFT_MARGIN+max*scale, vert);
  72.         PSlineto(LEFT_MARGIN+(100.0)*scale, vert);
  73.     PSstroke();
  74.     PSsetgray(NX_BLACK);
  75.     PSselectfont("Helvetica", 16.0);
  76.     for (i=0; i<=10; i++) {
  77.         sprintf(str, "%d", i*10);
  78.         PSmoveto(10.0*scale*i+LEFT_MARGIN, 5.0);
  79.         PSshow(str);
  80.     }
  81.     return self;
  82. }
  83.  
  84. @end
  85.