2024-07-21 23:11:02 +02:00
|
|
|
/*
|
|
|
|
* ImageScaled.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "ImageScaled.h"
|
|
|
|
|
|
|
|
#include "SDLImage.h"
|
|
|
|
#include "SDL_Extensions.h"
|
|
|
|
|
2024-07-25 12:38:48 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../render/IScreenHandler.h"
|
|
|
|
#include "../render/Colors.h"
|
|
|
|
|
2024-07-21 23:11:02 +02:00
|
|
|
#include "../../lib/constants/EntityIdentifiers.h"
|
|
|
|
|
|
|
|
#include <SDL_surface.h>
|
|
|
|
|
2024-11-16 17:40:05 +02:00
|
|
|
ImageScaled::ImageScaled(const ImageLocator & inputLocator, const std::shared_ptr<const ISharedImage> & source, EImageBlitMode mode)
|
2024-07-25 12:38:48 +02:00
|
|
|
: source(source)
|
|
|
|
, locator(inputLocator)
|
|
|
|
, colorMultiplier(Colors::WHITE_TRUE)
|
|
|
|
, alphaValue(SDL_ALPHA_OPAQUE)
|
|
|
|
, blitMode(mode)
|
2024-07-21 23:11:02 +02:00
|
|
|
{
|
2024-11-17 19:54:55 +02:00
|
|
|
prepareImages();
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2024-11-16 17:40:05 +02:00
|
|
|
std::shared_ptr<const ISharedImage> ImageScaled::getSharedImage() const
|
2024-07-21 23:11:02 +02:00
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
return body;
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2024-07-25 20:22:27 +02:00
|
|
|
void ImageScaled::scaleInteger(int factor)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageScaled::scaleTo(const Point & size)
|
2024-07-21 23:11:02 +02:00
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
if (body)
|
2024-08-27 21:49:41 +02:00
|
|
|
body = body->scaleTo(size * GH.screenHandler().getScalingFactor(), nullptr);
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImageScaled::exportBitmap(const boost::filesystem::path &path) const
|
|
|
|
{
|
2024-09-12 18:11:03 +02:00
|
|
|
source->exportBitmap(path, nullptr);
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ImageScaled::isTransparent(const Point &coords) const
|
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
return source->isTransparent(coords);
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Point ImageScaled::dimensions() const
|
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
return source->dimensions();
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImageScaled::setAlpha(uint8_t value)
|
|
|
|
{
|
|
|
|
alphaValue = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageScaled::setBlitMode(EImageBlitMode mode)
|
|
|
|
{
|
|
|
|
blitMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageScaled::draw(SDL_Surface *where, const Point &pos, const Rect *src) const
|
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
if (shadow)
|
|
|
|
shadow->draw(where, nullptr, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
|
|
|
|
if (body)
|
|
|
|
body->draw(where, nullptr, pos, src, Colors::WHITE_TRUE, alphaValue, blitMode);
|
|
|
|
if (overlay)
|
|
|
|
overlay->draw(where, nullptr, pos, src, colorMultiplier, colorMultiplier.a * alphaValue / 255, blitMode);
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2024-07-25 12:38:48 +02:00
|
|
|
void ImageScaled::setOverlayColor(const ColorRGBA & color)
|
2024-07-21 23:11:02 +02:00
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
colorMultiplier = color;
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImageScaled::playerColored(PlayerColor player)
|
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
playerColor = player;
|
2024-11-17 19:54:55 +02:00
|
|
|
prepareImages();
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2024-07-25 12:38:48 +02:00
|
|
|
void ImageScaled::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
|
2024-07-21 23:11:02 +02:00
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
// TODO: implement
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2024-07-25 12:38:48 +02:00
|
|
|
void ImageScaled::adjustPalette(const ColorFilter &shifter, uint32_t colorsToSkipMask)
|
2024-07-21 23:11:02 +02:00
|
|
|
{
|
2024-07-25 12:38:48 +02:00
|
|
|
// TODO: implement
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2024-11-17 19:54:55 +02:00
|
|
|
void ImageScaled::prepareImages()
|
2024-07-25 12:38:48 +02:00
|
|
|
{
|
2024-11-17 19:54:55 +02:00
|
|
|
switch(blitMode)
|
2024-07-25 12:38:48 +02:00
|
|
|
{
|
2024-11-17 19:54:55 +02:00
|
|
|
case EImageBlitMode::OPAQUE:
|
|
|
|
case EImageBlitMode::COLORKEY:
|
|
|
|
case EImageBlitMode::SIMPLE:
|
|
|
|
locator.layer = blitMode;
|
|
|
|
locator.playerColored = playerColor;
|
|
|
|
body = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
|
|
|
|
case EImageBlitMode::ONLY_BODY:
|
|
|
|
locator.layer = EImageBlitMode::ONLY_BODY;
|
|
|
|
locator.playerColored = playerColor;
|
|
|
|
body = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EImageBlitMode::WITH_SHADOW:
|
|
|
|
case EImageBlitMode::ONLY_BODY_IGNORE_OVERLAY:
|
|
|
|
locator.layer = EImageBlitMode::ONLY_BODY_IGNORE_OVERLAY;
|
|
|
|
locator.playerColored = playerColor;
|
|
|
|
body = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EImageBlitMode::ONLY_SHADOW:
|
|
|
|
case EImageBlitMode::ONLY_OVERLAY:
|
|
|
|
body = nullptr;
|
|
|
|
break;
|
2024-07-25 12:38:48 +02:00
|
|
|
}
|
|
|
|
|
2024-11-17 19:54:55 +02:00
|
|
|
switch(blitMode)
|
2024-07-25 12:38:48 +02:00
|
|
|
{
|
2024-11-17 19:54:55 +02:00
|
|
|
case EImageBlitMode::WITH_SHADOW:
|
|
|
|
case EImageBlitMode::ONLY_SHADOW:
|
|
|
|
case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
|
|
|
|
locator.layer = EImageBlitMode::ONLY_SHADOW;
|
|
|
|
locator.playerColored = PlayerColor::CANNOT_DETERMINE;
|
|
|
|
shadow = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
shadow = nullptr;
|
|
|
|
break;
|
2024-07-25 12:38:48 +02:00
|
|
|
}
|
|
|
|
|
2024-11-17 19:54:55 +02:00
|
|
|
switch(blitMode)
|
2024-07-25 12:38:48 +02:00
|
|
|
{
|
2024-11-17 19:54:55 +02:00
|
|
|
case EImageBlitMode::ONLY_OVERLAY:
|
|
|
|
case EImageBlitMode::WITH_SHADOW_AND_OVERLAY:
|
|
|
|
locator.layer = EImageBlitMode::ONLY_OVERLAY;
|
|
|
|
locator.playerColored = PlayerColor::CANNOT_DETERMINE;
|
|
|
|
overlay = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
overlay = nullptr;
|
|
|
|
break;
|
2024-07-25 12:38:48 +02:00
|
|
|
}
|
2024-07-21 23:11:02 +02:00
|
|
|
}
|