12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /*
- * 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 <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();
- auto newSurface = CSDL_Ext::scaleSurface(surface, scaledSize.x, scaledSize.y, algorithm);
- SDL_FreeSurface(surface);
- surface = newSurface;
- }
- 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};
- }
|