tileresource.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under the LGPL. 
00008         
00009         I kindly request you display a splash screen (provided in the HTML documentation)
00010         to promote Kyra and acknowledge the software and everyone who has contributed to it, 
00011         but it is not required by the license.
00012 
00013 --- LGPL License --
00014 
00015     This library is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU Lesser General Public
00017     License as published by the Free Software Foundation; either
00018     version 2.1 of the License, or (at your option) any later version.
00019 
00020     This library is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023     Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public
00026     License along with this library; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029         The full text of the license can be found in lgpl.txt
00030 */
00031 
00032 
00033 #ifndef KYRA_TILERESOURCE_INCLUDED
00034 #define KYRA_TILERESOURCE_INCLUDED
00035 
00036 #ifdef _MSC_VER
00037 // Disable the no-exception handling warning.
00038 #pragma warning( disable : 4530 )
00039 #pragma warning( disable : 4786 )
00040 #endif
00041 
00042 #include <vector>
00043 #include "kyraresource.h"
00044 #include "../engine/krmath.h"
00045 #include "pixelblock.h"
00046 
00050 class KrTileResource : public KrResource
00051 {
00052   public:
00053         // Create by reading from a .dat file
00054         KrTileResource( U32 size, SDL_RWops* data );
00055 
00056         KrTileResource( const std::string& name,
00057                                         KrPaintInfo* surface,
00058                                         int x, int y, int size );
00059 
00060         virtual ~KrTileResource();
00061 
00062         virtual U32 Type()                                              { return KYRATAG_TILE; }
00063         virtual const std::string&      TypeName()      { return tileName; }
00064         virtual KrTileResource* ToTileResource(){ return this; }
00065 
00067         int     Size() const                                    { return pixelBlock[0]->Width(); }
00069         bool    Alpha()                                                 { return pixelBlock[0]->Alpha(); }
00070 
00071         // -- internal -- //
00072         void Draw( KrPaintInfo* paintInfo,
00073                            const KrMatrix2& matrix,
00074                            int rotation, 
00075                            const KrColorTransform& cForm,
00076                            const grinliz::Rectangle2I& clipping,
00077                            int quality );
00078 
00079         /*  Do a HitTest (see KrImageTree::HitTest) in transformed 
00080                 coordinates. So the tree object that made this call
00081                 has already transformed the x and y into local pixel coords.
00082         */
00083         bool HitTestTransformed( int rotation, int x, int y, int hitFlags );
00084 
00085         void CalculateBounds( const KrMatrix2&, grinliz::Rectangle2I* bounds ) const;
00086         
00087         virtual void CacheScale( GlFixed xScale, GlFixed yScale );
00088         virtual bool IsScaleCached( GlFixed xScale, GlFixed yScale );
00089         virtual void FreeScaleCache();
00090 
00091         virtual void Save( KrEncoder* );
00092 
00093         KrRGBA* GetPixels(const int nRotation, int& nPitchX, int& nPitchY);
00094 
00095   private:
00096         struct CachedBlock
00097         {
00098                 GlFixed xScale,
00099                                 yScale;
00100                 KrPixelBlock* pixelBlock;
00101 
00102                 bool operator==( const CachedBlock& rhs )       { GLASSERT( 0 ); return false; }        // be nice to buggy compilers.
00103         };
00104         std::vector< CachedBlock > cache;
00105         
00106         void CalcSourceAndPitch( KrPixelBlock* pblock, int rotation, KrRGBA** source, int* sPitchX, int* sPitchY );
00107 
00108         static const std::string tileName;
00109         KrPixelBlock*   pixelBlock[4];  
00110 };
00111 
00112 
00113 #endif

Generated on Thu Jul 20 20:45:32 2006 for Kyra by  doxygen 1.4.7