CCreatureAnimation.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef __CCREATUREANIMATION_H__
  2. #define __CCREATUREANIMATION_H__
  3. #include "../global.h"
  4. #include "CDefHandler.h"
  5. #include "GUIBase.h"
  6. #include "../client/CBitmapHandler.h"
  7. /*
  8. * CCreatureAnimation.h, part of VCMI engine
  9. *
  10. * Authors: listed in file AUTHORS in main folder
  11. *
  12. * License: GNU General Public License v2.0 or later
  13. * Full text of license available in license.txt file, in main folder
  14. *
  15. */
  16. struct BMPPalette;
  17. class CCreatureAnimation : public CIntObject
  18. {
  19. private:
  20. int totalEntries, DEFType, totalBlocks;
  21. int length;
  22. BMPPalette palette[256];
  23. struct SEntry
  24. {
  25. int offset;
  26. int group;
  27. } ;
  28. std::vector<SEntry> SEntries ;
  29. std::string defName, curDir;
  30. template< int bytCon > static int readNormalNr (int pos, unsigned char * str)
  31. {
  32. int ret=0;
  33. int amp=1;
  34. for (int i=0; i<bytCon; i++)
  35. {
  36. ret+=str[pos+i]*amp;
  37. amp<<=8; //amp*=256;
  38. }
  39. return ret;
  40. }
  41. template<int bpp>
  42. void putPixel(
  43. SDL_Surface * dest,
  44. const int & ftcpX,
  45. const int & ftcpY,
  46. const BMPPalette & color,
  47. const unsigned char & palc,
  48. const bool & yellowBorder,
  49. const bool & blueBorder,
  50. const unsigned char & animCount
  51. ) const;
  52. ////////////
  53. unsigned char * FDef; //animation raw data
  54. int curFrame, internalFrame; //number of currently displayed frame
  55. unsigned int frames; //number of frames
  56. public:
  57. std::map<int, std::vector<int> > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group
  58. int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
  59. int fullWidth, fullHeight; //read-only, please!
  60. CCreatureAnimation(std::string name); //c-tor
  61. ~CCreatureAnimation(); //d-tor
  62. void setType(int type); //sets type of animation and cleares framecount
  63. int getType() const; //returns type of animation
  64. template<int bpp>
  65. 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
  66. 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
  67. 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
  68. void incrementFrame();
  69. int getFrame() const;
  70. bool onFirstFrameInGroup();
  71. bool onLastFrameInGroup();
  72. bool once;
  73. void playOnce(int type); //plays once given stage of animation, then resets to 2
  74. int framesInGroup(int group) const; //retirns number of fromes in given group
  75. };
  76. #endif // __CCREATUREANIMATION_H__