• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

RotFlip.hpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 #ifndef GOSU_ROTFLIP_HPP
00005 #define GOSU_ROTFLIP_HPP
00006 
00007 namespace Gosu
00008 {
00011     enum RotFlipName
00012     {
00013         rfDefault,
00014         rfRotate90,
00015         rfRotate180,
00016         rfRotate270,
00017 
00018         rfFlipX,
00019         rfRotate90FlipX,
00020         rfRotate180FlipX,
00021         rfRotate270FlipX,
00022         
00023         rfFlipY          = rfRotate180FlipX,
00024         rfRotate90FlipY  = rfRotate270FlipX,
00025         rfRotate180FlipY = rfFlipX,
00026         rfRotate270FlipY = rfRotate90FlipX,
00027 
00028         rfFlipXRotate90  = rfRotate270FlipX,
00029         rfFlipXRotate180 = rfRotate180FlipX,
00030         rfFlipXRotate270 = rfRotate90FlipX,
00031 
00032         rfFlipYRotate90  = rfRotate90FlipX,
00033         rfFlipYRotate180 = rfFlipX,
00034         rfFlipYRotate270 = rfRotate270FlipX
00035     };
00036     
00043     class RotFlip
00044     {
00045         RotFlipName name_;
00046 
00047         typedef RotFlipName TransTable[8];
00048         static const TransTable flipXTable, flipYTable, rotate90Table,
00049             rotate180Table, rotate270Table;
00050 
00051         typedef unsigned CornerTable[8][4];
00052         static const CornerTable mapCornerTable, realCornerTable;
00053 
00054     public:
00055         RotFlip(RotFlipName name = rfDefault)
00056         : name_(name)
00057         {
00058         }
00059 
00060         RotFlipName name() const
00061         {
00062             return name_;
00063         }
00064 
00065         void flipX()
00066         {
00067             name_ = flipXTable[name_];
00068         }
00069 
00070         void flipY()
00071         {
00072             name_ = flipYTable[name_];
00073         }
00074 
00075         void rotate90()
00076         {
00077             name_ = rotate90Table[name_];
00078         }
00079 
00080         void rotate180()
00081         {
00082             name_ = rotate180Table[name_];
00083         }
00084 
00085         void rotate270()
00086         {
00087             name_ = rotate270Table[name_];
00088         }
00089 
00090         bool flipped() const
00091         {
00092             return name_ >= rfFlipX;
00093         }
00094 
00095         bool rotated() const
00096         {
00097             return name_ % 2 == 1;
00098         }
00099 
00100         unsigned mapCorner(unsigned n) const
00101         {
00102             return mapCornerTable[name_][n];
00103         }
00104 
00105         unsigned realCorner(unsigned n) const
00106         {
00107             return realCornerTable[name_][n];
00108         }
00109     };
00110 
00111     inline bool operator==(RotFlip a, RotFlip b)
00112     {
00113         return a.name() == b.name();
00114     }
00115 
00116     inline bool operator!=(RotFlip a, RotFlip b)
00117     {
00118         return a.name() != b.name();
00119     }
00120     
00122     void applyToPoint(RotFlip rotFlip, int& x, int& y, int max);
00123 }
00124 
00125 #endif

Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!