CCreatureAnimation.h 2.9 KB

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