home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio-DSP / NU / Source / FGWindow.m < prev    next >
Encoding:
Text File  |  1992-12-20  |  3.4 KB  |  131 lines

  1. #import "FGWindow.h"
  2. #import <appkit/NXImage.h>
  3. #import <appkit/NXBitmapImageRep.h>
  4. #import <dpsclient/wraps.h>
  5. #import <dpsclient/psops.h>
  6. #import "Nutation.h"
  7. #import <math.h>
  8. #define NXSetWindowLevel _NXSetWindowLevel
  9.  
  10. // this window buffers the foreground (i.e. the targetGlyph) image
  11. // of a GlyphView.  This image is kept in an offscreen window
  12. // called "anImage", which is initially painted transparent.
  13. // All drawing is directed at this offscreen window, and all
  14. // compositing comes from it. If the ivar highlighted is YES,
  15. // then the composite will be followed by a highlight.
  16.  
  17. @implementation FGWindow: BGWindow
  18. { id anImage ;
  19.   BOOL highlighted ;
  20. }
  21.  
  22. - erase: (NXRect *) aRect ;
  23. { // erase (to transparent white) aRect within my image
  24.   [anImage lockFocus] ;
  25.   PScompositerect(aRect->origin.x,aRect->origin.y,
  26.    aRect->size.width, aRect->size.height, NX_CLEAR) ;
  27.   [anImage unlockFocus] ;
  28.   return self ;
  29. }
  30.  
  31. - erase ;
  32. { // erase my image
  33.   NXRect aRect = frame ;
  34.   aRect.origin.x = aRect.origin.y = 0.0 ;
  35.   return [self erase: &aRect] ;
  36. }
  37.  
  38. - composite: (int) op fromRect: (const NXRect *) aRect
  39.     toPoint: (const NXPoint *) aPnt ;
  40. { // actually composite from anImage
  41.   NXRect bRect ;
  42.   NXPoint bPnt ;
  43.   bPnt.x = rint(aPnt->x) ;
  44.   bPnt.y = rint(aPnt->y) ;
  45.   bRect.size = aRect->size ;
  46.   bRect.origin.x = rint(aRect->origin.x) ;
  47.   bRect.origin.y = rint(aRect->origin.y) ;
  48.   [anImage composite:op fromRect: &bRect toPoint: &bPnt] ;
  49.   if(highlighted)
  50.     PScompositerect(bPnt.x,bPnt.y,bRect.size.width,
  51.       bRect.size.height, NX_HIGHLIGHT) ;
  52.   return self ;
  53. }
  54.  
  55. - composite: (int) op toPoint: (const NXPoint *) aPnt ;
  56. { // actually composite from anImage
  57.   NXRect aRect = frame ;
  58.   aRect.origin.x = aRect.origin.y = 0.0 ;
  59.   return [self composite:op fromRect: &aRect toPoint: aPnt] ;
  60. }
  61.  
  62. - composite: (int) op  ;
  63. { // actually composite from anImage
  64.   NXPoint zeroPoint = {0.0,0.0} ;
  65.   return [self composite:op toPoint: &zeroPoint] ;
  66. }
  67.  
  68. - frame: (NXRect *) aFrame ;
  69. { // this is the "designated" initializer method
  70.   // Frist, make the window which will be seen on-screen
  71.   [super frame: aFrame] ;
  72.   // make an offscreen window to buffer the image
  73.   anImage = [[BGWindow alloc]
  74.     initContent: aFrame
  75.      style: NX_PLAINSTYLE
  76.      backing: NX_RETAINED
  77.      buttonMask: 0
  78.      defer: NO] ;
  79.   // paint anImage transparent
  80.   [self erase] ;
  81.   // for debugging, move offscreen window where it can be seen
  82.   [anImage moveTo: 300.0 :0] ;
  83.   // default is to be highlighted
  84.   [self setHighlighted: YES] ;
  85.   return self ;
  86. }
  87.  
  88. - free ;
  89. { [anImage free] ;
  90.   return [super free] ;
  91. }
  92.  
  93. - image ;
  94. { return anImage ;
  95. }
  96.  
  97. - (BOOL) lockFocus ;
  98. { // we actually lock focus on anImage
  99.   return [anImage lockFocus] ;
  100. }
  101.  
  102. - setHighlighted: (BOOL) YESorNO ;
  103. { highlighted = YESorNO ;
  104.   return self ;
  105. }
  106.  
  107. - sizeWindow:(NXCoord)width :(NXCoord)height ;
  108. { [anImage sizeWindow: width :height] ;
  109.   [anImage erase] ;
  110.   return [super sizeWindow: width :height] ;
  111. }
  112.  
  113. - unlockFocus ;
  114. { NXRect aRect = frame ;
  115.   // we actually unlock focus on anImage
  116.   [anImage unlockFocus] ;
  117.   // presumably, we have just some drawing, so
  118.   // composite anImage over ourselves and
  119.   // highlight if necessary
  120.   [contentView lockFocus] ;
  121.   aRect.origin.x = aRect.origin.y = 0.0 ;
  122.   NXEraseRect(&aRect) ; // paintmyself opaque white
  123.   [anImage composite: NX_SOVER toPoint: &aRect.origin] ;
  124.   if(highlighted)
  125.     PScompositerect(0.0,0.0,frame.size.width,
  126.      frame.size.height, NX_HIGHLIGHT) ;
  127.   [contentView unlockFocus] ;
  128.   return self ;
  129. }
  130.  
  131. @end