home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWPat.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  4.8 KB  |  180 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPat.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWPAT_H
  13. #include "FWPat.h"
  14. #endif
  15.  
  16. //==============================================================================
  17. //    •• CLASS FW_CPattern
  18. //==============================================================================
  19.  
  20. //------------------------------------------------------------------------------
  21. //    • FW_CPattern::FW_CPattern
  22. //------------------------------------------------------------------------------
  23.  
  24. FW_CPattern::FW_CPattern()
  25. {
  26.     MovePattern(FW_kBlackPat, fPattern);
  27. }
  28.  
  29. //------------------------------------------------------------------------------
  30. //    • FW_CPattern::FW_CPattern
  31. //------------------------------------------------------------------------------
  32.  
  33. FW_CPattern::FW_CPattern(const char* pattern)
  34. {
  35.     MovePattern(pattern, fPattern);
  36. }
  37.  
  38. //------------------------------------------------------------------------------
  39. //    • FW_CPattern::FW_CPattern
  40. //------------------------------------------------------------------------------
  41.  
  42. FW_CPattern::FW_CPattern(const FW_CPattern& otherPattern)
  43. {
  44.     MovePattern(otherPattern.fPattern, fPattern);
  45. }
  46.  
  47. //------------------------------------------------------------------------------
  48. //    • FW_CPattern::operator=
  49. //------------------------------------------------------------------------------
  50.  
  51. FW_CPattern& FW_CPattern::operator=(const FW_CPattern& otherPattern)
  52. {
  53.     MovePattern(otherPattern.fPattern, fPattern);
  54.     return *this;
  55. }
  56.  
  57. //------------------------------------------------------------------------------
  58. //    • FW_CPattern::operator=
  59. //------------------------------------------------------------------------------
  60.  
  61. FW_CPattern& FW_CPattern::operator=(const char* otherPattern)
  62. {
  63.     MovePattern(otherPattern, fPattern);
  64.     return *this;
  65. }
  66.  
  67. //------------------------------------------------------------------------------
  68. //    • FW_CPattern::Invert
  69. //------------------------------------------------------------------------------
  70.  
  71. void FW_CPattern::Invert()
  72. {
  73.     *((long*)&fPattern[0]) ^= 0xFFFFFF;
  74.     *((long*)&fPattern[4]) ^= 0xFFFFFF;
  75. }
  76.  
  77. //------------------------------------------------------------------------------
  78. //    • FW_CPattern::FlipVerticaly
  79. //------------------------------------------------------------------------------
  80.  
  81. void FW_CPattern::FlipVerticaly()
  82. {
  83.     for (short i = 0; i<4; i++)
  84.     {
  85.         char temp = fPattern[i];
  86.         fPattern[i] = fPattern[7-i];
  87.         fPattern[7-i] = temp;
  88.     }
  89. }
  90.  
  91. //------------------------------------------------------------------------------
  92. //    • FW_CPattern::FlipHorizontaly
  93. //------------------------------------------------------------------------------
  94. // This is not the best implementation
  95.  
  96. void FW_CPattern::FlipHorizontaly()
  97. {    
  98.     for (short j = 0; j<8; j++)
  99.     {
  100.         unsigned char leftMask = 0x80;
  101.         unsigned char rightMask = 0x01;
  102.         char theChar = fPattern[j];
  103.         for (short i = 0; i<4; i++)
  104.         {
  105.             char left = theChar & leftMask;
  106.             char right = theChar & rightMask;
  107.             
  108.             if (left)
  109.                 theChar |= rightMask;    // Set
  110.             else
  111.                 theChar ^= right;        // Clear
  112.                 
  113.             if (right)
  114.                 theChar |= leftMask;    // Set
  115.             else
  116.                 theChar ^= left;        // Clear
  117.                 
  118.             leftMask >>= 1;
  119.             rightMask <<= 1;
  120.         }
  121.         fPattern[j] = theChar;
  122.     }
  123. }
  124.  
  125. //------------------------------------------------------------------------------
  126. //    • FW_CPattern::ShiftRight
  127. //------------------------------------------------------------------------------
  128.  
  129. void FW_CPattern::ShiftRight()
  130. {
  131.     for (short i = 0; i<8; i++)
  132.     {
  133.         unsigned char theChar = fPattern[i];
  134.         theChar >>= 1;
  135.         if (fPattern[i] & 0x01)
  136.             theChar |= 0x80;
  137.         fPattern[i] = theChar;
  138.     }    
  139. }
  140.  
  141. //------------------------------------------------------------------------------
  142. //    • FW_CPattern::ShiftLeft
  143. //------------------------------------------------------------------------------
  144.  
  145. void FW_CPattern::ShiftLeft()
  146. {
  147.     for (short i = 0; i<8; i++)
  148.     {
  149.         unsigned char theChar = fPattern[i];
  150.         theChar <<= 1;
  151.         if (fPattern[i] & 0x80)
  152.             theChar |= 0x01;            
  153.         fPattern[i] = theChar;
  154.     }    
  155. }
  156.  
  157. //------------------------------------------------------------------------------
  158. //    • FW_CPattern::ShiftUp
  159. //------------------------------------------------------------------------------
  160.  
  161. void FW_CPattern::ShiftUp()
  162. {
  163.     char temp = fPattern[0];
  164.     for (short i = 0; i<7; i++)
  165.         fPattern[i] = fPattern[i+1];
  166.     fPattern[7] = temp;
  167. }
  168.  
  169. //------------------------------------------------------------------------------
  170. //    • FW_CPattern::ShiftDown
  171. //------------------------------------------------------------------------------
  172.  
  173. void FW_CPattern::ShiftDown()
  174. {
  175.     char temp = fPattern[7];
  176.     for (short i = 7; i>0; i--)
  177.         fPattern[i] = fPattern[i-1];
  178.     fPattern[0] = temp;
  179. }
  180.