CCreatureAnimation.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. void putPixel(
  40. SDL_Surface * dest,
  41. const int & ftcp,
  42. const BMPPalette & color,
  43. const unsigned char & palc,
  44. const bool & yellowBorder,
  45. const bool & blueBorder,
  46. const unsigned char & animCount
  47. ) const;
  48. ////////////
  49. unsigned char * FDef; //animation raw data
  50. int curFrame, internalFrame; //number of currently displayed frame
  51. unsigned int frames; //number of frames
  52. public:
  53. std::map<int, std::vector<int> > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group
  54. int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
  55. int fullWidth, fullHeight; //read-only, please!
  56. CCreatureAnimation(std::string name); //c-tor
  57. ~CCreatureAnimation(); //d-tor
  58. void setType(int type); //sets type of animation and cleares framecount
  59. int getType() const; //returns type of animation
  60. 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
  61. 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
  62. void incrementFrame();
  63. int getFrame() const;
  64. bool onFirstFrameInGroup();
  65. bool onLastFrameInGroup();
  66. bool once;
  67. void playOnce(int type); //plays once given stage of animation, then resets to 2
  68. int framesInGroup(int group) const; //retirns number of fromes in given group
  69. };
  70. #endif // __CCREATUREANIMATION_H__