home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / ImageOpr.bproj / RotateView.m < prev    next >
Encoding:
Text File  |  1996-02-09  |  2.0 KB  |  96 lines

  1. #import  "RotateView.h"
  2. #import  <math.h>
  3. #import  <dpsclient/wraps.h>
  4. #import  <appkit/NXImage.h>
  5. #import  <appkit/Control.h>
  6. #import  <appkit/TextField.h>
  7. #import  "../common.h"
  8. #import  "../ImageOpCtr.h"
  9. #import  "imageOperation.h"
  10.  
  11. @implementation RotateView
  12.  
  13. /* Overload */
  14. - initFrame:(const NXRect *)frameRect
  15. {
  16.     float    min;
  17.  
  18.     [super initFrame:frameRect];
  19.     min = frameRect->size.width;
  20.     if (min > frameRect->size.height) min = frameRect->size.height;
  21.     xc = frameRect->size.width / 2.0;
  22.     yc = frameRect->size.height / 2.0;
  23.     x0 = min * -0.35;
  24.     x1 = min * 0.35;
  25.     y0 = min * -0.25;
  26.     y1 = min * 0.25;
  27.     [self drawIt: nil];
  28.     return self;
  29. }
  30.  
  31. /* Overload */
  32. - drawSelf:(NXRect *)r :(int) count
  33. {
  34.     int i;
  35.  
  36.     PSsetgray(NX_LTGRAY);
  37.     PSrectfill(0.0, 0.0, bounds.size.width, bounds.size.height);
  38.     PSsetgray(NX_WHITE);
  39.     PSnewpath();
  40.     PSmoveto(xc + x[0], yc + y[0]);
  41.     for (i = 1; i < 4; i++)
  42.         PSlineto(xc + x[i], yc + y[i]);
  43.     PSfill();
  44.     PSsetgray(NX_DKGRAY);
  45.     PSnewpath();
  46.     PSmoveto(xc + x[0], yc + y[0]);
  47.     PSlineto(xc + x[1], yc + y[1]);
  48.     PSlineto(xc + (x[2] + x[3])/2.0, yc + (y[2] + y[3])/2.0);
  49.     PSfill();
  50.     return self;
  51. }
  52.  
  53. - drawIt: sender
  54. {
  55.     int angle;
  56.  
  57.     if (sender == nil) /* initialize */
  58.         angle = 0;
  59.     else
  60.         angle = [angleSlider intValue];
  61.     [angleText setIntValue: angle];
  62.     if (angle == 0) {
  63.         x[0] = x[3] = x0;
  64.         x[1] = x[2] = x1;
  65.         y[0] = y[1] = y0;
  66.         y[2] = y[3] = y1;
  67.     }else {
  68.         double si = sin((double)angle * 3.14159265 / 180.0);
  69.         double co = cos((double)angle * 3.14159265 / 180.0);
  70.         double xw, xs, yw;
  71.         x[0] = (xs = x0 * co) - (yw = y0 * si);
  72.         x[1] = (xw = x1 * co) - yw;
  73.         x[2] = xw - (yw = y1 * si);
  74.         x[3] = xs - yw;
  75.         y[0] = (xs = x0 * si) + (yw = y0 * co);
  76.         y[1] = (xw = x1 * si) + yw;
  77.         y[2] = xw + (yw = y1 * co);
  78.         y[3] = xs + yw;
  79.     }
  80.     return [self display];
  81. }
  82.  
  83. - writenAngle: sender
  84. {
  85.     int angle = [angleText intValue];
  86.  
  87.     while (angle < 0) angle += 360;
  88.     while (angle >= 360) angle -= 360;
  89.     [angleSlider setIntValue:((angle > 180) ? (angle - 360) : angle)];
  90.     [self drawIt: self];
  91.     [imageOp rotateAngle: self];
  92.     return self;
  93. }
  94.  
  95. @end
  96.