2023-02-01 16:12:01 +02:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* SDLImage.h, part of VCMI engine
|
2023-02-01 16:12:01 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/IImage.h"
|
|
|
|
#include "../../lib/Point.h"
|
2023-02-01 16:12:01 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
class JsonNode;
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class CDefFile;
|
2023-02-01 20:42:06 +02:00
|
|
|
|
|
|
|
struct SDL_Surface;
|
|
|
|
struct SDL_Palette;
|
2023-02-01 16:12:01 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper around SDL_Surface
|
|
|
|
*/
|
|
|
|
class SDLImage : public IImage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
const static int DEFAULT_PALETTE_COLORS = 256;
|
|
|
|
|
|
|
|
//Surface without empty borders
|
|
|
|
SDL_Surface * surf;
|
|
|
|
//size of left and top borders
|
|
|
|
Point margins;
|
|
|
|
//total size including borders
|
|
|
|
Point fullSize;
|
|
|
|
|
2023-02-20 18:37:33 +02:00
|
|
|
EImageBlitMode blitMode;
|
|
|
|
|
2023-02-01 16:12:01 +02:00
|
|
|
public:
|
|
|
|
//Load image from def file
|
|
|
|
SDLImage(CDefFile *data, size_t frame, size_t group=0);
|
|
|
|
//Load from bitmap file
|
2023-09-04 12:39:42 +02:00
|
|
|
SDLImage(const ImagePath & filename, EImageBlitMode blitMode);
|
2023-02-01 16:12:01 +02:00
|
|
|
|
2023-02-20 18:37:33 +02:00
|
|
|
SDLImage(const JsonNode & conf, EImageBlitMode blitMode);
|
2023-02-01 16:12:01 +02:00
|
|
|
//Create using existing surface, extraRef will increase refcount on SDL_Surface
|
2023-02-20 18:37:33 +02:00
|
|
|
SDLImage(SDL_Surface * from, EImageBlitMode blitMode);
|
2023-02-01 16:12:01 +02:00
|
|
|
~SDLImage();
|
|
|
|
|
|
|
|
// Keep the original palette, in order to do color switching operation
|
|
|
|
void savePalette();
|
|
|
|
|
|
|
|
void draw(SDL_Surface * where, int posX=0, int posY=0, const Rect *src=nullptr) const override;
|
|
|
|
void draw(SDL_Surface * where, const Rect * dest, const Rect * src) const override;
|
|
|
|
std::shared_ptr<IImage> scaleFast(const Point & size) const override;
|
|
|
|
void exportBitmap(const boost::filesystem::path & path) const override;
|
|
|
|
void playerColored(PlayerColor player) override;
|
|
|
|
void setFlagColor(PlayerColor player) override;
|
|
|
|
bool isTransparent(const Point & coords) const override;
|
|
|
|
Point dimensions() const override;
|
|
|
|
|
|
|
|
void horizontalFlip() override;
|
|
|
|
void verticalFlip() override;
|
2023-05-25 21:36:13 +02:00
|
|
|
void doubleFlip() override;
|
2023-02-01 16:12:01 +02:00
|
|
|
|
2023-02-19 22:05:19 +02:00
|
|
|
void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) override;
|
2023-03-25 18:55:08 +02:00
|
|
|
void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) override;
|
2023-02-01 16:12:01 +02:00
|
|
|
void resetPalette(int colorID) override;
|
|
|
|
void resetPalette() override;
|
|
|
|
|
|
|
|
void setAlpha(uint8_t value) override;
|
2023-02-20 18:37:33 +02:00
|
|
|
void setBlitMode(EImageBlitMode mode) override;
|
2023-02-01 16:12:01 +02:00
|
|
|
|
2023-03-25 18:55:08 +02:00
|
|
|
void setSpecialPallete(const SpecialPalette & SpecialPalette, uint32_t colorsToSkipMask) override;
|
2023-02-01 16:12:01 +02:00
|
|
|
|
|
|
|
friend class SDLImageLoader;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_Palette * originalPalette;
|
|
|
|
};
|