CAnimation.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "../../lib/GameConstants.h"
  12. #include "../../lib/filesystem/ResourcePath.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class JsonNode;
  15. VCMI_LIB_NAMESPACE_END
  16. class CDefFile;
  17. class IImage;
  18. class RenderHandler;
  19. /// Class for handling animation
  20. class CAnimation
  21. {
  22. private:
  23. //source[group][position] - file with this frame, if string is empty - image located in def file
  24. std::map<size_t, std::vector <JsonNode> > source;
  25. //bitmap[group][position], store objects with loaded bitmaps
  26. std::map<size_t, std::map<size_t, std::shared_ptr<IImage> > > images;
  27. //animation file name
  28. AnimationPath name;
  29. bool preloaded;
  30. //loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
  31. bool loadFrame(size_t frame, size_t group);
  32. //unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
  33. bool unloadFrame(size_t frame, size_t group);
  34. //to get rid of copy-pasting error message :]
  35. void printError(size_t frame, size_t group, std::string type) const;
  36. public:
  37. CAnimation(const AnimationPath & Name, std::map<size_t, std::vector <JsonNode> > layout);
  38. CAnimation();
  39. ~CAnimation();
  40. //duplicates frame at [sourceGroup, sourceFrame] as last frame in targetGroup
  41. //and loads it if animation is preloaded
  42. void duplicateImage(const size_t sourceGroup, const size_t sourceFrame, const size_t targetGroup);
  43. //add custom surface to the selected position.
  44. void setCustom(std::string filename, size_t frame, size_t group=0);
  45. std::shared_ptr<IImage> getImage(size_t frame, size_t group=0, bool verbose=true) const;
  46. void exportBitmaps(const boost::filesystem::path & path) const;
  47. //all available frames
  48. void load ();
  49. void unload();
  50. void preload();
  51. //all frames from group
  52. void loadGroup (size_t group);
  53. void unloadGroup(size_t group);
  54. //single image
  55. void load (size_t frame, size_t group=0);
  56. void unload(size_t frame, size_t group=0);
  57. //total count of frames in group (including not loaded)
  58. size_t size(size_t group=0) const;
  59. void horizontalFlip();
  60. void verticalFlip();
  61. void playerColored(PlayerColor player);
  62. void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
  63. };