home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWBWPat.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.5 KB  |  293 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBWPat.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #if defined(FW_PROFILER_CALLS) && defined(__MWERKS__)
  13. #pragma profile on
  14. #endif
  15.  
  16. #ifndef FWBWPAT_H
  17. #include "FWBWPat.h"
  18. #endif
  19.  
  20. #ifndef FWGRGLOB_H
  21. #include "FWGrGlob.h"
  22. #endif
  23.  
  24. // ----- Foundation Includes -----
  25.  
  26. #ifndef FWSTREAM_H
  27. #include "FWStream.h"
  28. #endif
  29.  
  30. //========================================================================================
  31. // RunTime Info
  32. //========================================================================================
  33.  
  34. #if FW_LIB_EXPORT_PRAGMAS
  35. #pragma lib_export on
  36. #endif
  37.  
  38. #ifdef FW_BUILD_MAC
  39. #pragma segment fwgraphx
  40. #endif
  41.  
  42. FW_DEFINE_CLASS_M1(FW_CBWPatternRep, FW_CPatternRep)
  43.  
  44. FW_REGISTER_ARCHIVABLE_CLASS(FW_LBWPatternRep, FW_CBWPatternRep, FW_CBWPatternRep::Read, FW_CPatternRep::Write)
  45.  
  46. //========================================================================================
  47. //    CLASS FW_CBWPatternRep
  48. //========================================================================================
  49.  
  50. //----------------------------------------------------------------------------------------
  51. //    FW_CBWPatternRep::FW_CBWPatternRep
  52. //----------------------------------------------------------------------------------------
  53.  
  54. FW_CBWPatternRep::FW_CBWPatternRep()
  55. {
  56.     unsigned char black[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  57.     MoveBitPattern(black, &fBitPattern);
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    FW_CBWPatternRep::FW_CBWPatternRep
  62. //----------------------------------------------------------------------------------------
  63.  
  64. FW_CBWPatternRep::FW_CBWPatternRep(const FW_BitPattern& bits)
  65. {
  66.     MoveBitPattern(&bits, &fBitPattern);
  67. }
  68.  
  69. //----------------------------------------------------------------------------------------
  70. //    FW_CBWPatternRep::FW_CBWPatternRep
  71. //----------------------------------------------------------------------------------------
  72.  
  73. FW_CBWPatternRep::FW_CBWPatternRep(FW_CReadableStream& stream)
  74. {
  75.     stream.Read(fBitPattern.fData, 8);    
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    FW_CBWPatternRep::~FW_CBWPatternRep
  80. //----------------------------------------------------------------------------------------
  81.  
  82. FW_CBWPatternRep::~FW_CBWPatternRep()
  83. {
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    FW_CBWPatternRep::Invert
  88. //----------------------------------------------------------------------------------------
  89.  
  90. void FW_CBWPatternRep::Invert()
  91. {
  92.     *((long*)&fBitPattern.fData[0]) ^= 0xFFFFFFFFL;
  93.     *((long*)&fBitPattern.fData[4]) ^= 0xFFFFFFFFL;
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    FW_CBWPatternRep::FlipVerticaly
  98. //----------------------------------------------------------------------------------------
  99.  
  100. void FW_CBWPatternRep::FlipVerticaly()
  101. {
  102.     for (short i = 0; i<4; i++)
  103.     {
  104.         unsigned char temp = fBitPattern.fData[i];
  105.         fBitPattern.fData[i] = fBitPattern.fData[7-i];
  106.         fBitPattern.fData[7-i] = temp;
  107.     }
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    FW_CBWPatternRep::FlipHorizontaly
  112. //----------------------------------------------------------------------------------------
  113. // This is not the best implementation
  114.  
  115. void FW_CBWPatternRep::FlipHorizontaly()
  116. {    
  117.     for (short j = 0; j<8; j++)
  118.     {
  119.         unsigned char leftMask = 0x80;
  120.         unsigned char rightMask = 0x01;
  121.         unsigned char theChar = fBitPattern.fData[j];
  122.         for (short i = 0; i<4; i++)
  123.         {
  124.             unsigned char left = theChar & leftMask;
  125.             unsigned char right = theChar & rightMask;
  126.             
  127.             if (left)
  128.                 theChar |= rightMask;    // Set
  129.             else
  130.                 theChar ^= right;        // Clear
  131.                 
  132.             if (right)
  133.                 theChar |= leftMask;    // Set
  134.             else
  135.                 theChar ^= left;        // Clear
  136.                 
  137.             leftMask >>= 1;
  138.             rightMask <<= 1;
  139.         }
  140.         fBitPattern.fData[j] = theChar;
  141.     }
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //    FW_CBWPatternRep::ShiftRight
  146. //----------------------------------------------------------------------------------------
  147.  
  148. void FW_CBWPatternRep::ShiftRight()
  149. {
  150.     for (short i = 0; i<8; i++)
  151.     {
  152.         unsigned char theChar = fBitPattern.fData[i];
  153.         theChar >>= 1;
  154.         if (fBitPattern.fData[i] & 0x01)
  155.             theChar |= 0x80;
  156.         fBitPattern.fData[i] = theChar;
  157.     }    
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    FW_CBWPatternRep::ShiftLeft
  162. //----------------------------------------------------------------------------------------
  163.  
  164. void FW_CBWPatternRep::ShiftLeft()
  165. {
  166.     for (short i = 0; i<8; i++)
  167.     {
  168.         unsigned char theChar = fBitPattern.fData[i];
  169.         theChar <<= 1;
  170.         if (fBitPattern.fData[i] & 0x80)
  171.             theChar |= 0x01;            
  172.         fBitPattern.fData[i] = theChar;
  173.     }    
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CBWPatternRep::ShiftUp
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void FW_CBWPatternRep::ShiftUp()
  181. {
  182.     unsigned char temp = fBitPattern.fData[0];
  183.     for (short i = 0; i<7; i++)
  184.         fBitPattern.fData[i] = fBitPattern.fData[i+1];
  185.     fBitPattern.fData[7] = temp;
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_CBWPatternRep::ShiftDown
  190. //----------------------------------------------------------------------------------------
  191.  
  192. void FW_CBWPatternRep::ShiftDown()
  193. {
  194.     unsigned char temp = fBitPattern.fData[7];
  195.     for (short i = 7; i>0; i--)
  196.         fBitPattern.fData[i] = fBitPattern.fData[i-1];
  197.     fBitPattern.fData[0] = temp;
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    FW_CBWPatternRep::IsEqual
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_Boolean FW_CBWPatternRep::IsEqual(const FW_CGraphicCountedPtrRep* other) const
  205. {
  206.     if (other == this)
  207.         return TRUE;
  208.         
  209.     FW_CBWPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CBWPatternRep, other);
  210.     
  211.     if (patternRep)
  212.     {
  213.         for (short i=0; i<7; i++)
  214.             if (fBitPattern.fData[i] != patternRep->fBitPattern.fData[i])
  215.                 return FALSE;
  216.         return TRUE;
  217.     }
  218.     
  219.     return FALSE;
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    FW_CBWPatternRep::IsBlack
  224. //----------------------------------------------------------------------------------------
  225.  
  226. FW_Boolean FW_CBWPatternRep::IsBlack() const
  227. {
  228.     return fBitPattern.fDataLongs[0] == 0xFFFFFFFFL && fBitPattern.fDataLongs[1] == 0xFFFFFFFFL;
  229. }
  230.  
  231. #ifdef FW_BUILD_WIN
  232. //----------------------------------------------------------------------------------------
  233. //    FW_CBWPatternRep::WinCreatePatternBrush
  234. //----------------------------------------------------------------------------------------
  235.  
  236. HBRUSH FW_CBWPatternRep::WinCreatePatternBrush() const
  237. {
  238.     unsigned char temp[16];    // 16 because rowbytes has to be even
  239.     for (short i=0; i<8; i++)
  240.         temp[2*i] = fBitPattern.fData[i] ^ 0xFF;
  241.         
  242.     HBRUSH hBrush = NULL;
  243.     
  244.     HBITMAP hbmp = ::CreateBitmap(8, 8, 1, 1, temp);
  245.     if(hbmp != NULL)
  246.     {
  247.         hBrush = ::CreatePatternBrush(hbmp);
  248.         ::DeleteObject(hbmp);
  249.     }
  250.     
  251.     return hBrush;
  252. }
  253. #endif
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    FW_CBWPatternRep::Copy
  257. //----------------------------------------------------------------------------------------
  258.  
  259. FW_PPattern FW_CBWPatternRep::Copy() const
  260. {
  261.     return FW_PPattern(fBitPattern);
  262. }
  263.  
  264. #ifdef FW_BUILD_MAC
  265. //----------------------------------------------------------------------------------------
  266. //    FW_CBWPatternRep::MacSetInCurPort
  267. //----------------------------------------------------------------------------------------
  268.  
  269. void FW_CBWPatternRep::MacSetInCurPort() const
  270. {
  271.     ::PenPat((const Pattern*)&fBitPattern);
  272. }
  273. #endif
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    FW_CBWPatternRep::Flatten
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void FW_CBWPatternRep::Flatten(FW_CWritableStream& archive) const
  280. {
  281.     archive.Write(fBitPattern.fData, 8);
  282. }
  283.  
  284. //----------------------------------------------------------------------------------------
  285. //    FW_CBWPatternRep::Read
  286. //----------------------------------------------------------------------------------------
  287.  
  288. void* FW_CBWPatternRep::Read(FW_CReadableStream& archive)
  289. {
  290.     return new FW_CBWPatternRep(archive);
  291. }
  292.  
  293.