RenderHandler.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 ScalableImageShared;
  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<SharedImageLocator, std::shared_ptr<ScalableImageShared>> imageFiles;
  24. std::map<EFonts, std::shared_ptr<const IFont>> fonts;
  25. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  26. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path, int scalingFactor, EImageBlitMode mode);
  27. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config, EImageBlitMode mode);
  28. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  29. void addImageListEntries(const EntityService * service);
  30. void storeCachedImage(const ImageLocator & locator, std::shared_ptr<ScalableImageShared> image);
  31. std::shared_ptr<ScalableImageShared> loadImageImpl(const ImageLocator & config);
  32. std::shared_ptr<SDLImageShared> loadImageFromFileUncached(const ImageLocator & locator);
  33. ImageLocator getLocatorForAnimationFrame(const AnimationPath & path, int frame, int group, int scaling, EImageBlitMode mode);
  34. int getScalingFactor() const;
  35. public:
  36. // IRenderHandler implementation
  37. void onLibraryLoadingFinished(const Services * services) override;
  38. std::shared_ptr<IImage> loadImage(const ImageLocator & locator) override;
  39. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  40. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group, EImageBlitMode mode) override;
  41. std::shared_ptr<SDLImageShared> loadScaledImage(const ImageLocator & locator) override;
  42. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path, EImageBlitMode mode) override;
  43. std::shared_ptr<CanvasImage> createImage(const Point & size, CanvasScalingPolicy scalingPolicy) override;
  44. /// Returns font with specified identifer
  45. std::shared_ptr<const IFont> loadFont(EFonts font) override;
  46. };