Main Page   Class Hierarchy   Compound List   File List   Compound Members  

spriteresource.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under 2 licenses:
00008 
00009         - The GPL, with no additional restrictions.
00010         - The LGPL, provided you display the Kyra splash screen, described below.
00011 
00012 
00013 --- GPL License --
00014         This program is free software; you can redistribute it and/or
00015         modify it under the terms of the GNU General Public License
00016         as published by the Free Software Foundation; either version 2
00017         of the License, or (at your option) any later version.
00018 
00019         This program is distributed in the hope that it will be useful,
00020         but WITHOUT ANY WARRANTY; without even the implied warranty of
00021         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022         GNU General Public License for more details.
00023 
00024         You should have received a copy of the GNU General Public License
00025         along with this program; if not, write to the Free Software
00026         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028         The full text of the license can be found in license.txt
00029 
00030 
00031 --- LGPL License --
00032   **Provided you kindly display the Kyra splash screen (details below), 
00033         you     may use the LGPL license:**
00034 
00035     This library is free software; you can redistribute it and/or
00036     modify it under the terms of the GNU Lesser General Public
00037     License as published by the Free Software Foundation; either
00038     version 2.1 of the License, or (at your option) any later version.
00039 
00040     This library is distributed in the hope that it will be useful,
00041     but WITHOUT ANY WARRANTY; without even the implied warranty of
00042     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043     Lesser General Public License for more details.
00044 
00045     You should have received a copy of the GNU Lesser General Public
00046     License along with this library; if not, write to the Free Software
00047     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00048 
00049         The full text of the license can be found in lgpl.txt
00050 
00051 
00052 --- Kyra Splash Screen.
00053 
00054         It would be appreciate if you display the Kyra splash screen when using
00055         either license, however it is only required for the LGPL. All the
00056         resources for the splash are compiled into the library, and it can be
00057         accessed through the following API:
00058 
00059                 KrEngine::StartSplash
00060                 KrEngine::UpdateSplash
00061                 KrEngine::EndSplash
00062 
00063         Full documentation is provided with the KrEngine class. The splash screen
00064         should be displayed for 2 seconds.
00065 
00066         Thank you.
00067 */
00068 
00069 #ifndef KYRA_SPRITERESOURCE_INCLUDED
00070 #define KYRA_SPRITERESOURCE_INCLUDED
00071 
00072 #include "../util/glstring.h"
00073 #include "../util/glmap.h"
00074 #include "kyraresource.h"
00075 // #include "tags.h"
00076 #include "../engine/krmath.h"
00077 #include "action.h"
00078 
00079 
00088 class KrSpriteResource : public KrResource
00089 {
00090   public:
00091         // Create by reading from a .dat file
00092         KrSpriteResource( U32 size, SDL_RWops* data );
00093 
00094         /*  Create the resource from the program. (Used by the sprite
00095                 editor for animating and aligning sprites.) 
00096                 After construction, SetAction is called.
00097         */
00098         KrSpriteResource( const std::string& spriteName );
00099         
00100         virtual ~KrSpriteResource();
00101 
00102         // Pass in an action to the resource. Used by the sprite editor.
00103         // Will allocate the action, if necessary.
00104         void AddAction( KrAction* action );
00105 
00106         virtual U32 Type()                                                              { return KYRATAG_SPRITE; }
00107         virtual const std::string&      TypeName()                      { return spriteName; }
00108         virtual KrSpriteResource* ToSpriteResource()    { return this; }
00109 
00111         int               NumActions()                                  { return actionArr.Count(); }
00113         KrAction* GetAction( const std::string& actionName );
00115         KrAction* GetAction( U32 actionId );
00116         
00122         KrCanvasResource* CreateCanvasResource( const std::string& actionName,
00123                                                                                                 int frame, int* hotx, int* hoty );
00124 
00126         KrCanvasResource* CreateCanvasResource( U32 actionId,
00127                                                                                                 int frame, int* hotx, int* hoty );
00128 
00129         // -- internal -- //
00130         KrAction* GetActionByIndex( int i )             { return actionArr[i]; }
00131         const KrAction& ActionByIndex( int i )  { return *actionArr[i]; }
00132 
00133         /*  Draw a sprite resource.
00134                 @param  surface         Target surface.
00135                 @param  paintInfo       Information about the target surface for drawing (optimizing).
00136                 @param  action          The name of the action to draw.
00137                 @param  frame           A frame # to draw.
00138                 @param  x                       X location in pixels.
00139                 @param  y                       Y location in pixels.
00140                 @param  cForm           Color transformation applied to the drawing.
00141                 @param  clip            A clipping rectangle, which can be null.
00142         */
00143         void Draw( KrPaintInfo* paintInfo, 
00144                            const std::string& action,
00145                            int frame,
00146                            const KrMatrix2& matrix,
00147                            const KrColorTransform& cForm,
00148                            const KrRect& clip,
00149                            int quality,
00150                            int openGLZ );
00151 
00152         /*  Do a HitTest (see KrImageTree::HitTest) in transformed 
00153                 coordinates. So the tree object that made this call
00154                 has already transformed the x and y into local pixel coords.
00155         */
00156         bool HitTestTransformed( int x, int y, int hitFlags )   {       GLASSERT( 0 ); return false; }  // never called directly. Use the action.
00157 
00158         virtual void CacheScale( GlFixed xScale, GlFixed yScale );
00159         virtual bool IsScaleCached( GlFixed xScale, GlFixed yScale );
00160         virtual void FreeScaleCache();
00161         virtual KrCollisionMap* GetCollisionMap( KrImage* state, int window );
00162 
00163         virtual void Save( KrEncoder* );
00164 
00165   protected:
00166         GlDynArray< KrAction* > actionArr;                      // the actions are stored here
00167 
00168   private:
00169 
00170         const static std::string spriteName;
00171 
00172         GlMap< std::string, KrAction*, GlStringHash >*  actionMap;              // the map is fast access to the action
00173         GlMap< U32, KrAction*, GlNumberHash<U32> >*             actionIdMap;    // the map is fast access to the action
00174 };
00175 
00176 
00177 #endif

Generated on Mon Sep 15 12:01:11 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001