SDLImage.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifdef IN
  13. #undef IN
  14. #endif
  15. #ifdef OUT
  16. #undef OUT
  17. #endif
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. class JsonNode;
  20. class Rect;
  21. class Point;
  22. VCMI_LIB_NAMESPACE_END
  23. struct SDL_Surface;
  24. struct SDL_Color;
  25. class CDefFile;
  26. class ColorFilter;
  27. /*
  28. * Wrapper around SDL_Surface
  29. */
  30. class SDLImage : public IImage
  31. {
  32. public:
  33. const static int DEFAULT_PALETTE_COLORS = 256;
  34. //Surface without empty borders
  35. SDL_Surface * surf;
  36. //size of left and top borders
  37. Point margins;
  38. //total size including borders
  39. Point fullSize;
  40. public:
  41. //Load image from def file
  42. SDLImage(CDefFile *data, size_t frame, size_t group=0);
  43. //Load from bitmap file
  44. SDLImage(std::string filename);
  45. SDLImage(const JsonNode & conf);
  46. //Create using existing surface, extraRef will increase refcount on SDL_Surface
  47. SDLImage(SDL_Surface * from, bool extraRef);
  48. ~SDLImage();
  49. // Keep the original palette, in order to do color switching operation
  50. void savePalette();
  51. void draw(SDL_Surface * where, int posX=0, int posY=0, const Rect *src=nullptr) const override;
  52. void draw(SDL_Surface * where, const Rect * dest, const Rect * src) const override;
  53. std::shared_ptr<IImage> scaleFast(const Point & size) const override;
  54. void exportBitmap(const boost::filesystem::path & path) const override;
  55. void playerColored(PlayerColor player) override;
  56. void setFlagColor(PlayerColor player) override;
  57. bool isTransparent(const Point & coords) const override;
  58. Point dimensions() const override;
  59. void horizontalFlip() override;
  60. void verticalFlip() override;
  61. void shiftPalette(int from, int howMany) override;
  62. void adjustPalette(const ColorFilter & shifter, size_t colorsToSkip) override;
  63. void resetPalette(int colorID) override;
  64. void resetPalette() override;
  65. void setAlpha(uint8_t value) override;
  66. void setSpecialPallete(const SpecialPalette & SpecialPalette) override;
  67. friend class SDLImageLoader;
  68. private:
  69. SDL_Palette * originalPalette;
  70. };