- Main Page
- Classes
- Files
- Directories
- Related Pages

# action.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_ACTION_INCLUDED
    00033 #define KYRA_ACTION_INCLUDED
    00034
    00035 #ifdef _MSC_VER
    00036 #pragma warning( disable : 4530 )
    00037 #pragma warning( disable : 4786 )
    00038 #endif
    00039
    00040 #include <string>
    00041 #include <vector>
    00042
    00043 #include "SDL.h"
    00044 #include "rle.h"
    00045
    00046 class KrCanvasResource;
    00047 class KrEncoder;
    00048 class KrCollisionMap;
    00049
    00050
    00055 class KrAction
    00056 {
    00057   public:
    00058         /*  Create an empty KrAction. Used with the AddFrame method
    00059                 to create an action.
    00060         */
    00061         KrAction( const std::string& name );
    00062
    00064         KrAction( SDL_RWops* data );
    00065
    00066         ~KrAction();
    00067
    00069         const std::string& Name() const         { return name; }
    00071         U32                                Id() const           { return id; }
    00072
    00073         /*  Draw the action to the surface.
    00074                 Normally called by the Sprite.
    00075                 @param paintInfo        Target surface information
    00076                 @param frame            The frame number to draw.
    00077                 @param x                        x value to draw -- measured at hotspot.
    00078                 @param y                        y value to draw -- measured at hotspot.
    00079                 @param cForm            The color transformation to use.
    00080                 @param clip                     A clipping rectangle. (Can be NULL)
    00081         */
    00082         void Draw( KrPaintInfo* paintInfo,
    00083                            int frame,
    00084                            const KrMatrix2& matrix,
    00085                            const KrColorTransform& cForm,
    00086                            const grinliz::Rectangle2I& clip );
    00087
    00089         int   NumFrames() const                         { return numFrames; }
    00090
    00092         const KrRle& Frame( int i ) const       { GLASSERT( i >= 0 );
    00093                                                                                   GLASSERT( i < numFrames );
    00094                                                                                   return frame[ i ]; }
    00095
    00096         /*  Get a non-conts pointer to the frame. A special case call.
    00097         */
    00098         KrRle* GetFrame( int i ) const          { GLASSERT( i >= 0 );
    00099                                                                                   GLASSERT( i < numFrames );
    00100                                                                                   return &frame[ i ]; }
    00101
    00102         bool HitTestTransformed( int frame, int x, int y, int hitFlags );
    00103
    00104         // internal
    00105         void CacheScale( GlFixed xScale, GlFixed yScale );
    00106         bool IsScaleCached( GlFixed xScale, GlFixed yScale );
    00107         void FreeScaleCache();
    00108         KrCollisionMap* GetCollisionMap( GlFixed xScale, GlFixed yScale, int frame );
    00109
    00110         void AddFrame()         { GrowFrameArray( numFrames + 1 ); }
    00111
    00115         KrCanvasResource* CreateCanvasResource( int frame, int* hotx, int* hoty );
    00116
    00117         void CalculateBounds( int frame, const KrMatrix2& xForm, grinliz::Rectangle2I* bounds );
    00118
    00119         void Save( KrEncoder* encoder );
    00120
    00121   private:
    00122         struct CachedBlock
    00123         {
    00124                 GlFixed xScale,
    00125                                 yScale;
    00126                 KrRle** frame;
    00127
    00128                 bool operator==( const CachedBlock& )   { GLASSERT( 0 ); return false; }                // be nice to buggy compilers.
    00129         };
    00130         void GrowFrameArray( int newSize );
    00131
    00132         std::vector< CachedBlock > cache;
    00133
    00134         std::string             name;
    00135         U32                             id;
    00136         KrRle*                  frame;                  // Can't use dynamic array since it doesn't have proper copy
    00137         int                             numFrames;
    00138 };
    00139
    00140
    00141 #endif