mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fixed minimap generation when upscaled mode is used
This commit is contained in:
parent
b527c0d09e
commit
748a3a1b64
@ -453,7 +453,7 @@ void AdventureMapInterface::onPlayerTurnStarted(PlayerColor playerID)
|
||||
widget->getInfoBar()->showDate();
|
||||
|
||||
onHeroChanged(nullptr);
|
||||
Canvas canvas = Canvas::createFromSurface(screen);
|
||||
Canvas canvas = Canvas::createFromSurface(screen, CanvasScalingPolicy::AUTO);
|
||||
showAll(canvas);
|
||||
mapAudio->onPlayerTurnStarted();
|
||||
|
||||
|
@ -73,7 +73,7 @@ void CMinimapInstance::redrawMinimap()
|
||||
|
||||
CMinimapInstance::CMinimapInstance(CMinimap *Parent, int Level):
|
||||
parent(Parent),
|
||||
minimap(new Canvas(Point(LOCPLINT->cb->getMapSize().x, LOCPLINT->cb->getMapSize().y))),
|
||||
minimap(new Canvas(Point(LOCPLINT->cb->getMapSize().x, LOCPLINT->cb->getMapSize().y), CanvasScalingPolicy::IGNORE)),
|
||||
level(Level)
|
||||
{
|
||||
pos.w = parent->pos.w;
|
||||
|
@ -142,7 +142,7 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
|
||||
pos.w = background->width();
|
||||
pos.h = background->height();
|
||||
|
||||
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
|
||||
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()), CanvasScalingPolicy::AUTO);
|
||||
|
||||
updateAccessibleHexes();
|
||||
addUsedEvents(LCLICK | SHOW_POPUP | MOVE | TIME | GESTURE);
|
||||
|
@ -233,12 +233,12 @@ void CIntObject::redraw()
|
||||
}
|
||||
else
|
||||
{
|
||||
Canvas buffer = Canvas::createFromSurface(screenBuf);
|
||||
Canvas buffer = Canvas::createFromSurface(screenBuf, CanvasScalingPolicy::AUTO);
|
||||
|
||||
showAll(buffer);
|
||||
if(screenBuf != screen)
|
||||
{
|
||||
Canvas screenBuffer = Canvas::createFromSurface(screen);
|
||||
Canvas screenBuffer = Canvas::createFromSurface(screen, CanvasScalingPolicy::AUTO);
|
||||
|
||||
showAll(screenBuffer);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ void WindowHandler::totalRedrawImpl()
|
||||
{
|
||||
logGlobal->debug("totalRedraw requested!");
|
||||
|
||||
Canvas target = Canvas::createFromSurface(screen2);
|
||||
Canvas target = Canvas::createFromSurface(screen2, CanvasScalingPolicy::AUTO);
|
||||
|
||||
for(auto & elem : windowsStack)
|
||||
elem->showAll(target);
|
||||
@ -134,7 +134,7 @@ void WindowHandler::simpleRedrawImpl()
|
||||
if(windowsStack.size() > 1)
|
||||
CSDL_Ext::blitAt(screen2, 0, 0, screen); //blit background
|
||||
|
||||
Canvas target = Canvas::createFromSurface(screen);
|
||||
Canvas target = Canvas::createFromSurface(screen, CanvasScalingPolicy::AUTO);
|
||||
|
||||
if(!windowsStack.empty())
|
||||
windowsStack.back()->show(target); //blit active interface/window
|
||||
|
@ -36,9 +36,9 @@ MapViewCache::MapViewCache(const std::shared_ptr<MapViewModel> & model)
|
||||
, overlayWasVisible(false)
|
||||
, mapRenderer(new MapRenderer())
|
||||
, iconsStorage(GH.renderHandler().loadAnimation(AnimationPath::builtin("VwSymbol"), EImageBlitMode::COLORKEY))
|
||||
, intermediate(new Canvas(Point(32, 32)))
|
||||
, terrain(new Canvas(model->getCacheDimensionsPixels()))
|
||||
, terrainTransition(new Canvas(model->getPixelsVisibleDimensions()))
|
||||
, intermediate(new Canvas(Point(32, 32), CanvasScalingPolicy::AUTO))
|
||||
, terrain(new Canvas(model->getCacheDimensionsPixels(), CanvasScalingPolicy::AUTO))
|
||||
, terrainTransition(new Canvas(model->getPixelsVisibleDimensions(), CanvasScalingPolicy::AUTO))
|
||||
{
|
||||
Point visibleSize = model->getTilesVisibleDimensions();
|
||||
terrainChecksum.resize(boost::extents[visibleSize.x][visibleSize.y]);
|
||||
|
@ -19,7 +19,8 @@
|
||||
#include <SDL_surface.h>
|
||||
#include <SDL_pixels.h>
|
||||
|
||||
Canvas::Canvas(SDL_Surface * surface):
|
||||
Canvas::Canvas(SDL_Surface * surface, CanvasScalingPolicy scalingPolicy):
|
||||
scalingPolicy(scalingPolicy),
|
||||
surface(surface),
|
||||
renderArea(0,0, surface->w, surface->h)
|
||||
{
|
||||
@ -27,6 +28,7 @@ Canvas::Canvas(SDL_Surface * surface):
|
||||
}
|
||||
|
||||
Canvas::Canvas(const Canvas & other):
|
||||
scalingPolicy(other.scalingPolicy),
|
||||
surface(other.surface),
|
||||
renderArea(other.renderArea)
|
||||
{
|
||||
@ -34,6 +36,7 @@ Canvas::Canvas(const Canvas & other):
|
||||
}
|
||||
|
||||
Canvas::Canvas(Canvas && other):
|
||||
scalingPolicy(other.scalingPolicy),
|
||||
surface(other.surface),
|
||||
renderArea(other.renderArea)
|
||||
{
|
||||
@ -46,7 +49,8 @@ Canvas::Canvas(const Canvas & other, const Rect & newClipRect):
|
||||
renderArea = other.renderArea.intersect(newClipRect + other.renderArea.topLeft());
|
||||
}
|
||||
|
||||
Canvas::Canvas(const Point & size):
|
||||
Canvas::Canvas(const Point & size, CanvasScalingPolicy scalingPolicy):
|
||||
scalingPolicy(scalingPolicy),
|
||||
renderArea(Point(0,0), size * getScalingFactor()),
|
||||
surface(CSDL_Ext::newSurface(size * getScalingFactor()))
|
||||
{
|
||||
@ -56,6 +60,8 @@ Canvas::Canvas(const Point & size):
|
||||
|
||||
int Canvas::getScalingFactor() const
|
||||
{
|
||||
if (scalingPolicy == CanvasScalingPolicy::IGNORE)
|
||||
return 1;
|
||||
return 2; // TODO: get from screen handler
|
||||
}
|
||||
|
||||
@ -69,9 +75,9 @@ Point Canvas::transformSize(const Point & input)
|
||||
return input * getScalingFactor();
|
||||
}
|
||||
|
||||
Canvas Canvas::createFromSurface(SDL_Surface * surface)
|
||||
Canvas Canvas::createFromSurface(SDL_Surface * surface, CanvasScalingPolicy scalingPolicy)
|
||||
{
|
||||
return Canvas(surface);
|
||||
return Canvas(surface, scalingPolicy);
|
||||
}
|
||||
|
||||
void Canvas::applyTransparency(bool on)
|
||||
|
@ -17,9 +17,19 @@ struct SDL_Surface;
|
||||
class IImage;
|
||||
enum EFonts : int;
|
||||
|
||||
enum class CanvasScalingPolicy
|
||||
{
|
||||
AUTO, // automatically scale canvas operations by global scaling factor
|
||||
IGNORE // disable any scaling processing. Scaling factor will be set to 1
|
||||
|
||||
};
|
||||
|
||||
/// Class that represents surface for drawing on
|
||||
class Canvas
|
||||
{
|
||||
/// Upscaler awareness. Must be first member for initialization
|
||||
CanvasScalingPolicy scalingPolicy;
|
||||
|
||||
/// Target surface
|
||||
SDL_Surface * surface;
|
||||
|
||||
@ -27,7 +37,7 @@ class Canvas
|
||||
Rect renderArea;
|
||||
|
||||
/// constructs canvas using existing surface. Caller maintains ownership on the surface
|
||||
explicit Canvas(SDL_Surface * surface);
|
||||
explicit Canvas(SDL_Surface * surface, CanvasScalingPolicy scalingPolicy);
|
||||
|
||||
/// copy constructor
|
||||
Canvas(const Canvas & other);
|
||||
@ -46,11 +56,11 @@ public:
|
||||
Canvas(const Canvas & other, const Rect & clipRect);
|
||||
|
||||
/// constructs canvas of specified size
|
||||
explicit Canvas(const Point & size);
|
||||
explicit Canvas(const Point & size, CanvasScalingPolicy scalingPolicy);
|
||||
|
||||
/// constructs canvas using existing surface. Caller maintains ownership on the surface
|
||||
/// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished.
|
||||
static Canvas createFromSurface(SDL_Surface * surface);
|
||||
static Canvas createFromSurface(SDL_Surface * surface, CanvasScalingPolicy scalingPolicy);
|
||||
|
||||
~Canvas();
|
||||
|
||||
|
@ -60,7 +60,7 @@ CMapOverview::CMapOverview(const std::string & mapName, const std::string & file
|
||||
|
||||
Canvas CMapOverviewWidget::createMinimapForLayer(std::unique_ptr<CMap> & map, int layer) const
|
||||
{
|
||||
Canvas canvas = Canvas(Point(map->width, map->height));
|
||||
Canvas canvas = Canvas(Point(map->width, map->height), CanvasScalingPolicy::IGNORE);
|
||||
|
||||
for (int y = 0; y < map->height; ++y)
|
||||
for (int x = 0; x < map->width; ++x)
|
||||
@ -139,7 +139,7 @@ std::shared_ptr<CPicture> CMapOverviewWidget::buildDrawMinimap(const JsonNode &
|
||||
double resize = maxSideLengthSrc / maxSideLengthDst;
|
||||
Point newMinimapSize = Point(minimapRect.w / resize, minimapRect.h / resize);
|
||||
|
||||
Canvas canvasScaled = Canvas(Point(rect.w, rect.h));
|
||||
Canvas canvasScaled = Canvas(Point(rect.w, rect.h), CanvasScalingPolicy::AUTO);
|
||||
canvasScaled.drawScaled(minimaps[id], Point((rect.w - newMinimapSize.x) / 2, (rect.h - newMinimapSize.y) / 2), newMinimapSize);
|
||||
std::shared_ptr<IImage> img = GH.renderHandler().createImage(canvasScaled.getInternalSurface());
|
||||
|
||||
|
@ -224,32 +224,32 @@ CSpellWindow::~CSpellWindow()
|
||||
std::shared_ptr<IImage> CSpellWindow::createBigSpellBook()
|
||||
{
|
||||
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(ImagePath::builtin("SpelBack"), EImageBlitMode::OPAQUE);
|
||||
Canvas canvas = Canvas(Point(800, 600));
|
||||
Canvas canvas = Canvas(Point(800, 600), CanvasScalingPolicy::AUTO);
|
||||
// edges
|
||||
canvas.draw(img, Point(0, 0), Rect(15, 38, 90, 45));
|
||||
canvas.draw(img, Point(0, 460), Rect(15, 400, 90, 141));
|
||||
canvas.draw(img, Point(705, 0), Rect(509, 38, 95, 45));
|
||||
canvas.draw(img, Point(705, 460), Rect(509, 400, 95, 141));
|
||||
// left / right
|
||||
Canvas tmp1 = Canvas(Point(90, 355 - 45));
|
||||
Canvas tmp1 = Canvas(Point(90, 355 - 45), CanvasScalingPolicy::AUTO);
|
||||
tmp1.draw(img, Point(0, 0), Rect(15, 38 + 45, 90, 355 - 45));
|
||||
canvas.drawScaled(tmp1, Point(0, 45), Point(90, 415));
|
||||
Canvas tmp2 = Canvas(Point(95, 355 - 45));
|
||||
Canvas tmp2 = Canvas(Point(95, 355 - 45), CanvasScalingPolicy::AUTO);
|
||||
tmp2.draw(img, Point(0, 0), Rect(509, 38 + 45, 95, 355 - 45));
|
||||
canvas.drawScaled(tmp2, Point(705, 45), Point(95, 415));
|
||||
// top / bottom
|
||||
Canvas tmp3 = Canvas(Point(409, 45));
|
||||
Canvas tmp3 = Canvas(Point(409, 45), CanvasScalingPolicy::AUTO);
|
||||
tmp3.draw(img, Point(0, 0), Rect(100, 38, 409, 45));
|
||||
canvas.drawScaled(tmp3, Point(90, 0), Point(615, 45));
|
||||
Canvas tmp4 = Canvas(Point(409, 141));
|
||||
Canvas tmp4 = Canvas(Point(409, 141), CanvasScalingPolicy::AUTO);
|
||||
tmp4.draw(img, Point(0, 0), Rect(100, 400, 409, 141));
|
||||
canvas.drawScaled(tmp4, Point(90, 460), Point(615, 141));
|
||||
// middle
|
||||
Canvas tmp5 = Canvas(Point(409, 141));
|
||||
Canvas tmp5 = Canvas(Point(409, 141), CanvasScalingPolicy::AUTO);
|
||||
tmp5.draw(img, Point(0, 0), Rect(100, 38 + 45, 509 - 15, 400 - 38));
|
||||
canvas.drawScaled(tmp5, Point(90, 45), Point(615, 415));
|
||||
// carpet
|
||||
Canvas tmp6 = Canvas(Point(590, 59));
|
||||
Canvas tmp6 = Canvas(Point(590, 59), CanvasScalingPolicy::AUTO);
|
||||
tmp6.draw(img, Point(0, 0), Rect(15, 484, 590, 59));
|
||||
canvas.drawScaled(tmp6, Point(0, 545), Point(800, 59));
|
||||
// remove bookmarks
|
||||
|
Loading…
Reference in New Issue
Block a user