mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
All assets generation (large spellbook, terrain animations, etc) are now done in memory and used as it, without saving to disk. This should slightly improve load times since there is no encode png / decode png, and should help with avoiding strange bug when vcmi fails to load recently saved assets. If needed, such assets can be force-dumped on disk using already existing console command
70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
/*
|
|
* CanvasImage.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 "CanvasImage.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
|
#include "../render/IScreenHandler.h"
|
|
#include "../renderSDL/SDL_Extensions.h"
|
|
#include "../renderSDL/SDLImageScaler.h"
|
|
#include "../renderSDL/SDLImage.h"
|
|
|
|
#include <SDL_image.h>
|
|
#include <SDL_surface.h>
|
|
|
|
CanvasImage::CanvasImage(const Point & size, CanvasScalingPolicy scalingPolicy)
|
|
: surface(CSDL_Ext::newSurface(scalingPolicy == CanvasScalingPolicy::IGNORE ? size : (size * GH.screenHandler().getScalingFactor())))
|
|
, scalingPolicy(scalingPolicy)
|
|
{
|
|
}
|
|
|
|
void CanvasImage::draw(SDL_Surface * where, const Point & pos, const Rect * src, int scalingFactor) const
|
|
{
|
|
if(src)
|
|
CSDL_Ext::blitSurface(surface, *src, where, pos);
|
|
else
|
|
CSDL_Ext::blitSurface(surface, where, pos);
|
|
}
|
|
|
|
void CanvasImage::scaleTo(const Point & size, EScalingAlgorithm algorithm)
|
|
{
|
|
Point scaledSize = size * GH.screenHandler().getScalingFactor();
|
|
|
|
SDLImageScaler scaler(surface);
|
|
scaler.scaleSurface(scaledSize, algorithm);
|
|
SDL_FreeSurface(surface);
|
|
surface = scaler.acquireResultSurface();
|
|
}
|
|
|
|
void CanvasImage::exportBitmap(const boost::filesystem::path & path) const
|
|
{
|
|
IMG_SavePNG(surface, path.string().c_str());
|
|
}
|
|
|
|
Canvas CanvasImage::getCanvas()
|
|
{
|
|
return Canvas::createFromSurface(surface, scalingPolicy);
|
|
}
|
|
|
|
Rect CanvasImage::contentRect() const
|
|
{
|
|
return Rect(Point(0, 0), dimensions());
|
|
}
|
|
|
|
Point CanvasImage::dimensions() const
|
|
{
|
|
return {surface->w, surface->h};
|
|
}
|
|
|
|
std::shared_ptr<ISharedImage> CanvasImage::toSharedImage()
|
|
{
|
|
return std::make_shared<SDLImageShared>(surface);
|
|
}
|