home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 (1993) / nebula.bin / SourceCode / MiniExamples / PerformanceTuning / VisibleView-02 / SubViewFramer.m < prev    next >
Encoding:
Text File  |  1991-10-18  |  2.6 KB  |  96 lines

  1. //
  2. //    A View that Frames its Subview -- pretty ungeneral
  3. //      Randy Nelson, NeXT Developer Training
  4. //    Created 5-1-90
  5. //    Modified for 2.0 9-3-90
  6. //
  7. //    You may freely copy, distribute and reuse the code in this example.
  8. //    NeXT disclaims any warranty of any kind, expressed or implied, as to
  9. //    its fitness for any particular use.
  10. //
  11.  
  12. #import "SubViewFramer.h"
  13. #import <dpsclient/wraps.h>
  14. #import <appkit/graphics.h>
  15. #import "VisibleOne.h"
  16.  
  17. #define FACTOR 2
  18.  
  19. @implementation SubViewFramer
  20.  
  21. //sets clipping off
  22. - initFrame:(const NXRect *)r
  23. {
  24.     [super initFrame:r];
  25.     [self setClipping:NO];
  26.     return self;
  27. }
  28.  
  29. //called by the visible view to frame it—transparently if requested
  30. - frameMe:sender
  31. {
  32.     NXRect subViewsFrame, myFrame;
  33.     NXSize myFrameFactored;
  34.     float subViewsFrameAngle;
  35.     
  36.     [self lockFocus];
  37.     PSsetgray(0.5);
  38.     
  39.     //gets the subview's frame and rotation
  40.     [sender getFrame:&subViewsFrame];
  41.     subViewsFrameAngle = [sender frameAngle];
  42.     
  43.     //necessary to rotate around the same point the subview used if rotated
  44.     if(subViewsFrameAngle != 0){
  45.     PStranslate(subViewsFrame.origin.x, subViewsFrame.origin.y);
  46.     PSrotate(subViewsFrameAngle);
  47.     PStranslate(-subViewsFrame.origin.x, -subViewsFrame.origin.y);
  48.     }
  49.     
  50.     //sets the alpha if sender wants a transparent superview
  51.     if ([sender wantsTransparency]){
  52.     PSsetalpha(NX_DKGRAY);
  53.     }
  54.     
  55.     //the superview needs to completely cover the window
  56.     //even when rotated
  57.     [self getFrame:&myFrame];
  58.     myFrameFactored.width = (myFrame.size.width * FACTOR);
  59.     myFrameFactored.height =  (myFrame.size.height * FACTOR);
  60.     
  61.     //left side
  62.     PScompositerect(-(myFrameFactored.width), -(myFrameFactored.height),
  63.             ((myFrameFactored.width) + subViewsFrame.origin.x),
  64.             (myFrameFactored.height * 2), NX_SOVER);
  65.  
  66.     //top middle
  67.     PScompositerect(subViewsFrame.origin.x,
  68.                 (subViewsFrame.origin.y + subViewsFrame.size.height),
  69.             subViewsFrame.size.width,
  70.             ((myFrameFactored.height)
  71.             - (subViewsFrame.origin.y + subViewsFrame.size.height)),
  72.             NX_SOVER);
  73.  
  74.     //right side
  75.     PScompositerect((subViewsFrame.origin.x + subViewsFrame.size.width), 
  76.             -(myFrameFactored.height),
  77.             ((myFrameFactored.width)
  78.             - (subViewsFrame.origin.x + subViewsFrame.size.width)),
  79.             (myFrameFactored.height * 2), NX_SOVER);
  80.  
  81.     //bottom middle
  82.     PScompositerect(subViewsFrame.origin.x, -(myFrameFactored.height),
  83.     subViewsFrame.size.width,
  84.     ((myFrameFactored.height) + subViewsFrame.origin.y), NX_SOVER);
  85.  
  86.     //enclose the subview's frame
  87.     PSsetgray(NX_BLACK);
  88.     PSsetalpha(1.0);
  89.     NXFrameRect(&subViewsFrame);    
  90.  
  91.     [self unlockFocus];
  92.     return self;
  93. }
  94.  
  95. @end
  96.