canvasresource.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_CANVASRESOURCE_INCLUDED
00034 #define KYRA_CANVASRESOURCE_INCLUDED
00035 
00036 
00037 #ifdef _MSC_VER
00038 // Disable the no-exception handling warning.
00039 #pragma warning( disable : 4530 )
00040 #pragma warning( disable : 4786 )
00041 #endif
00042 
00043 #include <vector>
00044 
00045 #include "kyraresource.h"
00046 #include "../engine/krmath.h"
00047 #include "../util/glcirclelist.h"
00048 #include "pixelblock.h"
00049 
00050 class KrCanvas;
00051 
00055 class KrCanvasResource : public KrResource
00056 {
00057   public:
00076         KrCanvasResource( const std::string& name,
00077                                           int width, 
00078                                           int height, 
00079                                           int alphaSupport );
00080 
00081         virtual ~KrCanvasResource();
00082 
00083         virtual U32 Type()                                              { return KYRATAG_CANVAS; }
00084         virtual const std::string&      TypeName()      { return canvasName; }
00085         virtual KrCanvasResource* ToCanvasResource(){ return this; }
00086 
00087         int     Width()                                         { return pixelBlock.Width(); }  
00088         int             Height()                                        { return pixelBlock.Height(); } 
00089         KrRGBA* Pixels()                                        { return pixelBlock.Pixels(); } 
00090         int             Alpha()                                         { return pixelBlock.Alpha(); }  
00091 
00092         /*  Draw a canvas resource.
00093                 @param  paintInfo       Information about the target surface for drawing (optimizing).
00094                 @param  x                       X location in pixels.
00095                 @param  y                       Y location in pixels.
00096                 @param  cForm           Color transformation applied to the drawing.
00097                 @param  clip            A clipping rectangle, which can be null.
00098         */
00099         void Draw( KrPaintInfo* paintInfo,
00100                            const KrMatrix2& matrix,
00101                            const KrColorTransform& cForm,
00102                            const grinliz::Rectangle2I& clipping,
00103                            int quality );
00104 
00109         void Refresh();
00110 
00111         /*  Do a HitTest (see KrImageTree::HitTest) in transformed 
00112                 coordinates. So the tree object that made this call
00113                 has already transformed the x and y into local pixel coords.
00114         */
00115         bool HitTestTransformed( int x, int y, int hitFlags );
00116 
00117         void CalculateBounds( const KrMatrix2& xForm, grinliz::Rectangle2I* bounds ) const;
00118 
00119         // Canvases don't cache.
00120         virtual void CacheScale( GlFixed xScale, GlFixed yScale )               {}
00121         virtual bool IsScaleCached( GlFixed xScale, GlFixed yScale )    { return false; }
00122         virtual void FreeScaleCache()                                                                   {}
00123 
00124         // But they do collision map.
00125         virtual KrCollisionMap* GetCollisionMap( KrImage* state, int window );
00126 
00127         // For use by the Canvas objects:
00128         void AddCanvas( KrCanvas* canvas );
00129         void RemoveCanvas( KrCanvas* canvas );
00130 
00131   private:
00132         static const std::string canvasName;
00133         static int canvasId;
00134 
00135         KrPixelBlock            pixelBlock;
00136         int                                     numClients;
00137         GlCircleList<KrCanvas*>         clients;
00138         std::vector<KrCollisionMap*>    collisionMaps;
00139 };
00140 
00141 
00142 #endif

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