home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 4.8 KB | 180 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPat.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWPAT_H
- #include "FWPat.h"
- #endif
-
- //==============================================================================
- // •• CLASS FW_CPattern
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::FW_CPattern
- //------------------------------------------------------------------------------
-
- FW_CPattern::FW_CPattern()
- {
- MovePattern(FW_kBlackPat, fPattern);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::FW_CPattern
- //------------------------------------------------------------------------------
-
- FW_CPattern::FW_CPattern(const char* pattern)
- {
- MovePattern(pattern, fPattern);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::FW_CPattern
- //------------------------------------------------------------------------------
-
- FW_CPattern::FW_CPattern(const FW_CPattern& otherPattern)
- {
- MovePattern(otherPattern.fPattern, fPattern);
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::operator=
- //------------------------------------------------------------------------------
-
- FW_CPattern& FW_CPattern::operator=(const FW_CPattern& otherPattern)
- {
- MovePattern(otherPattern.fPattern, fPattern);
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::operator=
- //------------------------------------------------------------------------------
-
- FW_CPattern& FW_CPattern::operator=(const char* otherPattern)
- {
- MovePattern(otherPattern, fPattern);
- return *this;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::Invert
- //------------------------------------------------------------------------------
-
- void FW_CPattern::Invert()
- {
- *((long*)&fPattern[0]) ^= 0xFFFFFF;
- *((long*)&fPattern[4]) ^= 0xFFFFFF;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::FlipVerticaly
- //------------------------------------------------------------------------------
-
- void FW_CPattern::FlipVerticaly()
- {
- for (short i = 0; i<4; i++)
- {
- char temp = fPattern[i];
- fPattern[i] = fPattern[7-i];
- fPattern[7-i] = temp;
- }
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::FlipHorizontaly
- //------------------------------------------------------------------------------
- // This is not the best implementation
-
- void FW_CPattern::FlipHorizontaly()
- {
- for (short j = 0; j<8; j++)
- {
- unsigned char leftMask = 0x80;
- unsigned char rightMask = 0x01;
- char theChar = fPattern[j];
- for (short i = 0; i<4; i++)
- {
- char left = theChar & leftMask;
- char right = theChar & rightMask;
-
- if (left)
- theChar |= rightMask; // Set
- else
- theChar ^= right; // Clear
-
- if (right)
- theChar |= leftMask; // Set
- else
- theChar ^= left; // Clear
-
- leftMask >>= 1;
- rightMask <<= 1;
- }
- fPattern[j] = theChar;
- }
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::ShiftRight
- //------------------------------------------------------------------------------
-
- void FW_CPattern::ShiftRight()
- {
- for (short i = 0; i<8; i++)
- {
- unsigned char theChar = fPattern[i];
- theChar >>= 1;
- if (fPattern[i] & 0x01)
- theChar |= 0x80;
- fPattern[i] = theChar;
- }
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::ShiftLeft
- //------------------------------------------------------------------------------
-
- void FW_CPattern::ShiftLeft()
- {
- for (short i = 0; i<8; i++)
- {
- unsigned char theChar = fPattern[i];
- theChar <<= 1;
- if (fPattern[i] & 0x80)
- theChar |= 0x01;
- fPattern[i] = theChar;
- }
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::ShiftUp
- //------------------------------------------------------------------------------
-
- void FW_CPattern::ShiftUp()
- {
- char temp = fPattern[0];
- for (short i = 0; i<7; i++)
- fPattern[i] = fPattern[i+1];
- fPattern[7] = temp;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CPattern::ShiftDown
- //------------------------------------------------------------------------------
-
- void FW_CPattern::ShiftDown()
- {
- char temp = fPattern[7];
- for (short i = 7; i>0; i--)
- fPattern[i] = fPattern[i-1];
- fPattern[0] = temp;
- }
-