home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / OutOfContextMenus / Source / CInvertBehavior.cp < prev    next >
Encoding:
Text File  |  1999-06-23  |  2.6 KB  |  104 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CInvertBehavior.cp                 ©1999 Eric Traut
  3. // ===========================================================================
  4.  
  5. #include "CInvertBehavior.h"
  6. #include "CShadowWindow.h"
  7.  
  8.  
  9. // ---------------------------------------------------------------------------
  10. //        • CInvertBehavior
  11. // ---------------------------------------------------------------------------
  12.  
  13. CInvertBehavior::CInvertBehavior(
  14.     CShadowWindow &        inShadowWindow)
  15.     :    COffscreenBehavior(inShadowWindow, true)
  16. {
  17. }
  18.  
  19.  
  20. // ---------------------------------------------------------------------------
  21. //        • SyncWithShadowWindow
  22. // ---------------------------------------------------------------------------
  23.  
  24. Boolean
  25. CInvertBehavior::SyncWithShadowWindow(void)
  26. {
  27.     Boolean            didSync;
  28.     
  29.     didSync = COffscreenBehavior::SyncWithShadowWindow();
  30.     
  31.     if (didSync)
  32.     {
  33.         // Recalculate our blur rect
  34.         CWindowRecord *        macWindow = mShadowWindow.GetMacWindow();
  35.         mInvertRect = macWindow->port.portRect;
  36.         
  37.         mInvertRect.right -= 15;
  38.         mInvertRect.bottom -= 15;
  39.         mInvertRect.top += 21;
  40.     }
  41.     
  42.     return didSync;
  43. }
  44.  
  45.         
  46. // ---------------------------------------------------------------------------
  47. //        • RenderToGWorld
  48. // ---------------------------------------------------------------------------
  49.  
  50. Boolean
  51. CInvertBehavior::RenderToGWorld(
  52.     StGWorldLocker &        inBackingLocker,
  53.     StGWorldLocker &        inRenderingLocker)
  54. {
  55.     UInt16        row;
  56.     UInt16        column;
  57.     UInt16        maxRow;
  58.     UInt16        maxColumn;
  59.     UInt16        srcRowWords;
  60.     UInt16        destRowWords;
  61.     UInt16 *    srcRowPtr;
  62.     UInt16 *    destRowPtr;
  63.     PixMapPtr    tempPixMap;
  64.     
  65.     tempPixMap = *inBackingLocker.GetPixMap();
  66.     srcRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
  67.     srcRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
  68.  
  69.     tempPixMap = *inRenderingLocker.GetPixMap();
  70.     destRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
  71.     destRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
  72.  
  73.     maxRow = tempPixMap->bounds.bottom - tempPixMap->bounds.top;
  74.     maxColumn = tempPixMap->bounds.right - tempPixMap->bounds.left;
  75.  
  76.     // Simply invert everything in the specified rectangle
  77.     for (row = 0; row < maxRow; row++)
  78.     {
  79.         for (column = 0; column < maxColumn; column++)
  80.         {
  81.             UInt32        accumRed = 0;
  82.             UInt32        accumGreen = 0;
  83.             UInt32        accumBlue = 0;
  84.             
  85.             if (column >= mInvertRect.left && column < mInvertRect.right &&
  86.                 row >= mInvertRect.top && row < mInvertRect.bottom)
  87.             {
  88.                 destRowPtr[column] = ~srcRowPtr[column];
  89.             }
  90.             else
  91.             {
  92.                 destRowPtr[column] = srcRowPtr[column];
  93.             }
  94.         }
  95.         
  96.         srcRowPtr += srcRowWords;
  97.         destRowPtr += destRowWords;
  98.     }
  99.     
  100.     return true;
  101. }
  102.  
  103.  
  104.