spriteresource.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 #ifndef KYRA_SPRITERESOURCE_INCLUDED
00033 #define KYRA_SPRITERESOURCE_INCLUDED
00034 
00035 #ifdef _MSC_VER
00036 // Disable the no-exception handling warning.
00037 #pragma warning( disable : 4530 )
00038 #pragma warning( disable : 4786 )
00039 #endif
00040 
00041 #include "kyraresource.h"
00042 // #include "tags.h"
00043 #include "../engine/krmath.h"
00044 #include "action.h"
00045 #include <map>
00046 
00055 class KrSpriteResource : public KrResource
00056 {
00057   public:
00058         // Create by reading from a .dat file
00059         KrSpriteResource( U32 size, SDL_RWops* data );
00060 
00061         /*  Create the resource from the program. (Used by the sprite
00062                 editor for animating and aligning sprites.) 
00063                 After construction, SetAction is called.
00064         */
00065         KrSpriteResource( const std::string& spriteName );
00066         
00067         virtual ~KrSpriteResource();
00068 
00069         // Pass in an action to the resource. Used by the sprite editor.
00070         // Will allocate the action, if necessary.
00071         void AddAction( KrAction* action );
00072 
00073         virtual U32 Type()                                                              { return KYRATAG_SPRITE; }
00074         virtual const std::string&      TypeName()                      { return spriteName; }
00075         virtual KrSpriteResource* ToSpriteResource()    { return this; }
00076 
00078         int               NumActions()                                  { return actionArr.size(); }
00080         KrAction* GetAction( const std::string& actionName );
00082         KrAction* GetAction( U32 actionId );
00083         
00089         KrCanvasResource* CreateCanvasResource( const std::string& actionName,
00090                                                                                                 int frame, int* hotx, int* hoty );
00091 
00093         KrCanvasResource* CreateCanvasResource( U32 actionId,
00094                                                                                                 int frame, int* hotx, int* hoty );
00095 
00096         // -- internal -- //
00097         KrAction* GetActionByIndex( int i )             { return actionArr[i]; }
00098         const KrAction& ActionByIndex( int i )  { return *actionArr[i]; }
00099 
00100         /*  Draw a sprite resource.
00101                 @param  surface         Target surface.
00102                 @param  paintInfo       Information about the target surface for drawing (optimizing).
00103                 @param  action          The name of the action to draw.
00104                 @param  frame           A frame # to draw.
00105                 @param  x                       X location in pixels.
00106                 @param  y                       Y location in pixels.
00107                 @param  cForm           Color transformation applied to the drawing.
00108                 @param  clip            A clipping rectangle, which can be null.
00109         */
00110         void Draw( KrPaintInfo* paintInfo, 
00111                            const std::string& action,
00112                            int frame,
00113                            const KrMatrix2& matrix,
00114                            const KrColorTransform& cForm,
00115                            const grinliz::Rectangle2I& clip,
00116                            int quality );
00117 
00118         /*  Do a HitTest (see KrImageTree::HitTest) in transformed 
00119                 coordinates. So the tree object that made this call
00120                 has already transformed the x and y into local pixel coords.
00121         */
00122         bool HitTestTransformed( int x, int y, int hitFlags )   {       GLASSERT( 0 ); return false; }  // never called directly. Use the action.
00123 
00124         virtual void CacheScale( GlFixed xScale, GlFixed yScale );
00125         virtual bool IsScaleCached( GlFixed xScale, GlFixed yScale );
00126         virtual void FreeScaleCache();
00127         virtual KrCollisionMap* GetCollisionMap( KrImage* state, int window );
00128 
00129         virtual void Save( KrEncoder* );
00130 
00131   protected:
00132         std::vector< KrAction* >        actionArr;                      // the actions are stored here
00133 
00134   private:
00135 
00136         const static std::string spriteName;
00137 
00138         std::map< std::string, KrAction* >  actionMap;          // the map is fast access to the action
00139         std::map< U32, KrAction* >                      actionIdMap;    // the map is fast access to the action
00140 };
00141 
00142 
00143 #endif

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