CCreatureAnimation.h 3.1 KB

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