1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/renderSDL/ImageScaled.cpp

166 lines
4.0 KiB
C++
Raw Normal View History

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"
#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>
ImageScaled::ImageScaled(const ImageLocator & inputLocator, const std::shared_ptr<const ISharedImage> & source, EImageBlitMode mode)
: source(source)
, locator(inputLocator)
, colorMultiplier(Colors::WHITE_TRUE)
, alphaValue(SDL_ALPHA_OPAQUE)
, blitMode(mode)
2024-07-21 23:11:02 +02:00
{
prepareImages();
2024-07-21 23:11:02 +02:00
}
std::shared_ptr<const ISharedImage> ImageScaled::getSharedImage() const
2024-07-21 23:11:02 +02:00
{
return body;
2024-07-21 23:11:02 +02:00
}
void ImageScaled::scaleInteger(int factor)
{
assert(0);
}
void ImageScaled::scaleTo(const Point & size)
2024-07-21 23:11:02 +02:00
{
if (body)
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
{
source->exportBitmap(path, nullptr);
2024-07-21 23:11:02 +02:00
}
bool ImageScaled::isTransparent(const Point &coords) const
{
return source->isTransparent(coords);
2024-07-21 23:11:02 +02:00
}
Point ImageScaled::dimensions() const
{
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
{
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
}
void ImageScaled::setOverlayColor(const ColorRGBA & color)
2024-07-21 23:11:02 +02:00
{
colorMultiplier = color;
2024-07-21 23:11:02 +02:00
}
void ImageScaled::playerColored(PlayerColor player)
{
playerColor = player;
prepareImages();
2024-07-21 23:11:02 +02:00
}
void ImageScaled::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
2024-07-21 23:11:02 +02:00
{
// TODO: implement
2024-07-21 23:11:02 +02:00
}
void ImageScaled::adjustPalette(const ColorFilter &shifter, uint32_t colorsToSkipMask)
2024-07-21 23:11:02 +02:00
{
// TODO: implement
2024-07-21 23:11:02 +02:00
}
void ImageScaled::prepareImages()
{
switch(blitMode)
{
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;
}
switch(blitMode)
{
case EImageBlitMode::SIMPLE:
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;
}
switch(blitMode)
{
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-21 23:11:02 +02:00
}