2009-04-16 14:14:13 +03:00
# ifndef __CCREATUREANIMATION_H__
# define __CCREATUREANIMATION_H__
# include "../global.h"
2010-12-20 23:22:53 +02:00
# include "CDefHandler.h"
2009-05-20 12:02:50 +03:00
# include "GUIBase.h"
2010-08-17 17:58:13 +03:00
# include "../client/CBitmapHandler.h"
2009-04-16 14:14:13 +03:00
2009-04-15 17:03:31 +03:00
/*
* CCreatureAnimation . h , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
2009-04-16 14:14:13 +03:00
*/
2010-08-17 17:58:13 +03:00
struct BMPPalette ;
2009-04-16 14:14:13 +03:00
class CCreatureAnimation : public CIntObject
{
private :
int totalEntries , DEFType , totalBlocks ;
int length ;
BMPPalette palette [ 256 ] ;
struct SEntry
{
int offset ;
int group ;
} ;
std : : vector < SEntry > SEntries ;
std : : string defName , curDir ;
2010-02-12 17:04:01 +02:00
template < int bytCon > static int readNormalNr ( int pos , unsigned char * str )
{
int ret = 0 ;
int amp = 1 ;
for ( int i = 0 ; i < bytCon ; i + + )
{
ret + = str [ pos + i ] * amp ;
amp < < = 8 ; //amp*=256;
}
return ret ;
}
2010-08-12 08:22:48 +03:00
template < int bpp >
2009-04-16 14:14:13 +03:00
void putPixel (
SDL_Surface * dest ,
const int & ftcp ,
const BMPPalette & color ,
const unsigned char & palc ,
const bool & yellowBorder ,
const bool & blueBorder ,
const unsigned char & animCount
) const ;
////////////
unsigned char * FDef ; //animation raw data
int curFrame , internalFrame ; //number of currently displayed frame
unsigned int frames ; //number of frames
public :
std : : map < int , std : : vector < int > > frameGroups ; //groups of frames; [groupID] -> vector of frame IDs in group
int type ; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
int fullWidth , fullHeight ; //read-only, please!
CCreatureAnimation ( std : : string name ) ; //c-tor
~ CCreatureAnimation ( ) ; //d-tor
void setType ( int type ) ; //sets type of animation and cleares framecount
int getType ( ) const ; //returns type of animation
2010-08-12 08:22:48 +03:00
template < int bpp >
int nextFrameT ( SDL_Surface * dest , int x , int y , bool attacker , unsigned char animCount , bool incrementFrame = true , bool yellowBorder = false , bool blueBorder = false , SDL_Rect * destRect = NULL ) ; //0 - success, any other - error //print next
2009-04-16 14:14:13 +03:00
int nextFrame ( SDL_Surface * dest , int x , int y , bool attacker , unsigned char animCount , bool incrementFrame = true , bool yellowBorder = false , bool blueBorder = false , SDL_Rect * destRect = NULL ) ; //0 - success, any other - error //print next
int nextFrameMiddle ( SDL_Surface * dest , int x , int y , bool attacker , unsigned char animCount , bool IncrementFrame = true , bool yellowBorder = false , bool blueBorder = false , SDL_Rect * destRect = NULL ) ; //0 - success, any other - error //print next
void incrementFrame ( ) ;
int getFrame ( ) const ;
2009-10-13 05:01:29 +03:00
bool onFirstFrameInGroup ( ) ;
2009-04-16 14:14:13 +03:00
bool onLastFrameInGroup ( ) ;
bool once ;
void playOnce ( int type ) ; //plays once given stage of animation, then resets to 2
int framesInGroup ( int group ) const ; //retirns number of fromes in given group
} ;
# endif // __CCREATUREANIMATION_H__