CAnimation.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * CAnimation.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "IImage.h"
  12. #include "ImageLocator.h"
  13. #include "../../lib/GameConstants.h"
  14. #include "../../lib/filesystem/ResourcePath.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class JsonNode;
  17. VCMI_LIB_NAMESPACE_END
  18. class CDefFile;
  19. class RenderHandler;
  20. /// Class for handling animation
  21. class CAnimation
  22. {
  23. private:
  24. //source[group][position] - location of this frame
  25. std::map<size_t, std::vector <ImageLocator> > source;
  26. //bitmap[group][position], store objects with loaded bitmaps
  27. std::map<size_t, std::map<size_t, std::shared_ptr<IImage> > > images;
  28. //animation file name
  29. AnimationPath name;
  30. EImageBlitMode mode;
  31. // current player color, if any
  32. PlayerColor player = PlayerColor::CANNOT_DETERMINE;
  33. //loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
  34. bool loadFrame(size_t frame, size_t group, bool verbose = true);
  35. //unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
  36. bool unloadFrame(size_t frame, size_t group);
  37. //to get rid of copy-pasting error message :]
  38. void printError(size_t frame, size_t group, std::string type) const;
  39. std::shared_ptr<IImage> getImageImpl(size_t frame, size_t group=0, bool verbose=true);
  40. public:
  41. CAnimation(const AnimationPath & Name, std::map<size_t, std::vector <ImageLocator> > layout, EImageBlitMode mode);
  42. ~CAnimation();
  43. //duplicates frame at [sourceGroup, sourceFrame] as last frame in targetGroup
  44. //and loads it if animation is preloaded
  45. void duplicateImage(const size_t sourceGroup, const size_t sourceFrame, const size_t targetGroup);
  46. std::shared_ptr<IImage> getImage(size_t frame, size_t group=0, bool verbose=true);
  47. void exportBitmaps(const boost::filesystem::path & path) const;
  48. //total count of frames in group (including not loaded)
  49. size_t size(size_t group=0) const;
  50. void horizontalFlip(size_t frame, size_t group=0);
  51. void verticalFlip(size_t frame, size_t group=0);
  52. void horizontalFlip();
  53. void verticalFlip();
  54. void playerColored(PlayerColor player);
  55. void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
  56. ImageLocator getImageLocator(size_t frame, size_t group) const;
  57. };