RenderHandler.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * RenderHandler.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 "../render/IRenderHandler.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class EntityService;
  14. VCMI_LIB_NAMESPACE_END
  15. class CDefFile;
  16. class IConstImage;
  17. class RenderHandler : public IRenderHandler
  18. {
  19. using AnimationLayoutMap = std::map<size_t, std::vector<JsonNode>>;
  20. struct ImageLocator
  21. {
  22. ImagePath image;
  23. AnimationPath animation;
  24. int frame = -1;
  25. int group = -1;
  26. bool verticalFlip = false;
  27. bool horizontalFlip = false;
  28. ImageLocator(const JsonNode & config);
  29. ImageLocator(const ImagePath & path);
  30. ImageLocator(const AnimationPath & path, int frame, int group);
  31. bool operator < (const ImageLocator & other) const;
  32. };
  33. std::map<AnimationPath, std::shared_ptr<CDefFile>> animationFiles;
  34. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  35. std::map<ImageLocator, std::shared_ptr<IConstImage>> imageFiles;
  36. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  37. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
  38. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
  39. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  40. void addImageListEntries(const EntityService * service);
  41. std::shared_ptr<IConstImage> loadImageFromSingleFile(const ImagePath & path);
  42. std::shared_ptr<IConstImage> loadImageFromAnimationFileUncached(const AnimationPath & path, int frame, int group);
  43. std::shared_ptr<IConstImage> loadImageFromAnimationFile(const AnimationPath & path, int frame, int group);
  44. std::shared_ptr<IConstImage> loadImageImpl(const ImageLocator & config);
  45. public:
  46. // IRenderHandler implementation
  47. void onLibraryLoadingFinished(const Services * services) override;
  48. std::shared_ptr<IImage> loadImage(const JsonNode & config) override;
  49. std::shared_ptr<IImage> loadImage(const ImagePath & path) override;
  50. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  51. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group) override;
  52. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path) override;
  53. std::shared_ptr<IImage> createImage(SDL_Surface * source) override;
  54. std::shared_ptr<CAnimation> createAnimation() override;
  55. };