home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Educational / Dual / Source / AbstractView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.2 KB  |  123 lines

  1. // AbstractView.m
  2.  
  3. #import "AbstractView.h"
  4. #import "Controller.h"
  5. #import <stdio.h>
  6.  
  7. @implementation AbstractView
  8.  
  9. - initFrame:(const NXRect *)frameRect
  10. {
  11.     [super initFrame:frameRect];
  12.     xMin = -100;
  13.     xMax = 100;
  14.     yMin = -100;
  15.     yMax = 100;
  16.     [self display];
  17.     return self;
  18. }
  19.  
  20. - newLimits:sender
  21. {
  22.     xMin = [xMinField floatValue];
  23.     xMax = [xMaxField floatValue];
  24.     yMin = [yMinField floatValue];
  25.     yMax = [yMaxField floatValue];
  26.     [self display];
  27.     return self;
  28. }
  29.     
  30. #define X(x) ((x - xMin) * sx)
  31. #define Y(y) ((y - yMin) * sy)
  32.  
  33. - drawSelf:(const NXRect *)rects :(int)rectCount
  34. {
  35.     float sx = bounds.size.width / (xMax - xMin);
  36.     float sy = bounds.size.height / (yMax - yMin);
  37.     id font = [Font newFont:"Helvetica" size:12.0 matrix:NX_IDENTITYMATRIX];
  38.         
  39.     // erase view
  40.     NXEraseRect(&rects[0]);
  41.     
  42.     // draw axes
  43.     PSsetgray(NX_BLACK);
  44.     PSmoveto(X(xMin), Y(0.0));
  45.     PSlineto(X(xMax), Y(0.0));
  46.     PSstroke();
  47.     PSmoveto(X(0.0), Y(yMin));
  48.     PSlineto(X(0.0), Y(yMax));
  49.     PSstroke();
  50.     
  51.     // set font for later
  52.     [font set];
  53.     
  54.     return self;
  55. }
  56.  
  57. - (BOOL)acceptsFirstResponder
  58. {
  59.     return YES;
  60. }
  61.  
  62. - copy:sender
  63. {
  64.     NXStream *stream;
  65.     NXAtom typelist[1] = { NXPostScriptPboardType };
  66.     int length, maxLength;
  67.     char *data;
  68.     id pboard = [Pasteboard new];    
  69.  
  70.     // put EPS on the pasteboard
  71. NX_DURING
  72.     [pboard declareTypes:typelist num:1 owner:self];
  73.     stream = NXOpenMemory(NULL, 0, NX_READWRITE);
  74.     [self copyPSCodeInside:&bounds to:stream];
  75.     NXGetMemoryBuffer(stream, &data, &length, &maxLength);
  76.     [pboard writeType:NXPostScriptPboardType data:data length:length];
  77.     NXCloseMemory(stream, NX_FREEBUFFER);
  78. NX_HANDLER
  79.     NXRunAlertPanel("Error", "Can't copy EPS to the pasteboard.", NULL, NULL, NULL);
  80. NX_ENDHANDLER
  81.     return self;
  82. }
  83.  
  84. #define ZOOM_FACTOR 1.2
  85.  
  86. - zoomIn:sender
  87. {
  88.     xMin /= ZOOM_FACTOR;
  89.     yMin /= ZOOM_FACTOR;
  90.     xMax /= ZOOM_FACTOR;
  91.     yMax /= ZOOM_FACTOR;
  92.     [self displayLimits];
  93.     [self display];
  94.     return self;
  95. }
  96.  
  97. - zoomOut:sender
  98. {
  99.     xMin *= ZOOM_FACTOR;
  100.     yMin *= ZOOM_FACTOR;
  101.     xMax *= ZOOM_FACTOR;
  102.     yMax *= ZOOM_FACTOR;
  103.     [self displayLimits];
  104.     [self display];
  105.     return self;
  106. }
  107.  
  108. - (void)displayLimits
  109. {
  110.     [xMinField setFloatValue: xMin];
  111.     [xMaxField setFloatValue: xMax];
  112.     [yMinField setFloatValue: yMin];
  113.     [yMaxField setFloatValue: yMax];
  114. }
  115.  
  116. - awakeFromNib
  117. {
  118.     [self displayLimits];
  119.     return self;
  120. }
  121.  
  122. @end
  123.