RenderHandler.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 SDLImageShared;
  17. class ISharedImage;
  18. class RenderHandler : public IRenderHandler
  19. {
  20. using AnimationLayoutMap = std::map<size_t, std::vector<ImageLocator>>;
  21. std::map<AnimationPath, std::shared_ptr<CDefFile>> animationFiles;
  22. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  23. std::map<ImageLocator, std::shared_ptr<ISharedImage>> imageFiles;
  24. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  25. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
  26. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
  27. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  28. void addImageListEntries(const EntityService * service);
  29. void storeCachedImage(const ImageLocator & locator, std::shared_ptr<ISharedImage> image);
  30. std::shared_ptr<ISharedImage> loadImageImpl(const ImageLocator & config);
  31. std::shared_ptr<ISharedImage> loadImageFromFileUncached(const ImageLocator & locator);
  32. std::shared_ptr<ISharedImage> loadImageFromFile(const ImageLocator & locator);
  33. std::shared_ptr<ISharedImage> transformImage(const ImageLocator & locator, std::shared_ptr<ISharedImage> image);
  34. std::shared_ptr<ISharedImage> scaleImage(const ImageLocator & locator, std::shared_ptr<ISharedImage> image);
  35. ImageLocator getLocatorForAnimationFrame(const AnimationPath & path, int frame, int group);
  36. int getScalingFactor() const;
  37. public:
  38. // IRenderHandler implementation
  39. void onLibraryLoadingFinished(const Services * services) override;
  40. std::shared_ptr<IImage> loadImage(const ImageLocator & locator, EImageBlitMode mode) override;
  41. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  42. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group, EImageBlitMode mode) override;
  43. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path, EImageBlitMode mode) override;
  44. std::shared_ptr<IImage> createImage(SDL_Surface * source) override;
  45. };