| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /*
- * 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"
- #include "../../lib/constants/EntityIdentifiers.h"
- #include <SDL_surface.h>
- ImageScaled::ImageScaled(const ImageLocator & inputLocator, const std::shared_ptr<ISharedImage> & source, EImageBlitMode mode)
- : source(source)
- , locator(inputLocator)
- , colorMultiplier(Colors::WHITE_TRUE)
- , alphaValue(SDL_ALPHA_OPAQUE)
- , blitMode(mode)
- {
- locator.scalingFactor = GH.screenHandler().getScalingFactor();
- setBodyEnabled(true);
- }
- std::shared_ptr<ISharedImage> ImageScaled::getSharedImage() const
- {
- return body;
- }
- void ImageScaled::scaleFast(const Point &size)
- {
- if (body)
- body = body->scaleFast(size, nullptr); // FIXME: adjust for scaling
- }
- void ImageScaled::exportBitmap(const boost::filesystem::path &path) const
- {
- source->exportBitmap(path);
- }
- bool ImageScaled::isTransparent(const Point &coords) const
- {
- return source->isTransparent(coords);
- }
- Point ImageScaled::dimensions() const
- {
- return source->dimensions();
- }
- 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);
- }
- void ImageScaled::setOverlayColor(const ColorRGBA & color)
- {
- colorMultiplier = color;
- }
- void ImageScaled::playerColored(PlayerColor player)
- {
- playerColor = player;
- if (body)
- setBodyEnabled(true); // regenerate
- }
- void ImageScaled::shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove)
- {
- // TODO: implement
- }
- void ImageScaled::adjustPalette(const ColorFilter &shifter, uint32_t colorsToSkipMask)
- {
- // TODO: implement
- }
- void ImageScaled::setShadowEnabled(bool on)
- {
- if (on)
- {
- locator.layerBody = false;
- locator.layerShadow = true;
- locator.layerOverlay = false;
- locator.playerColored = PlayerColor::CANNOT_DETERMINE;
- shadow = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
- }
- else
- shadow = nullptr;
- }
- void ImageScaled::setBodyEnabled(bool on)
- {
- if (on)
- {
- locator.layerBody = true;
- locator.layerShadow = false;
- locator.layerOverlay = false;
- locator.playerColored = playerColor;
- body = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
- }
- else
- body = nullptr;
- }
- void ImageScaled::setOverlayEnabled(bool on)
- {
- if (on)
- {
- locator.layerBody = false;
- locator.layerShadow = false;
- locator.layerOverlay = true;
- locator.playerColored = PlayerColor::CANNOT_DETERMINE;
- overlay = GH.renderHandler().loadImage(locator, blitMode)->getSharedImage();
- }
- else
- overlay = nullptr;
- }
|