1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

use QImage::flipped instead of deprecated QImage::mirrored

This commit is contained in:
Andrey Filipenkov
2025-09-15 13:52:54 +03:00
parent 9a95f249fa
commit 28f4a3310c

View File

@@ -21,13 +21,34 @@
#include "../lib/mapObjects/MiscObjects.h"
#include "../lib/GameConstants.h"
namespace
{
const int tileSize = 32;
static bool objectBlitOrderSorter(const ObjectRect & a, const ObjectRect & b)
bool objectBlitOrderSorter(const ObjectRect & a, const ObjectRect & b)
{
return MapHandler::compareObjectBlitOrder(a.obj, b.obj);
}
QImage flippedImage(const std::shared_ptr<QImage> & image, ui8 rotationFlags)
{
const ui8 rotation = rotationFlags % 4;
const bool hflip = rotation & 0b01;
const bool vflip = rotation & 0b10;
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
Qt::Orientations orientations;
if(hflip)
orientations |= Qt::Horizontal;
if(vflip)
orientations |= Qt::Vertical;
return image->flipped(orientations);
#else
return image->mirrored(hflip, vflip);
#endif
}
}
int MapHandler::index(int x, int y, int z) const
{
return z * (map->width * map->height) + y * map->width + x;
@@ -90,54 +111,46 @@ void MapHandler::initTerrainGraphics()
void MapHandler::drawTerrainTile(QPainter & painter, int x, int y, int z)
{
auto & tinfo = map->getTile(int3(x, y, z));
ui8 rotation = tinfo.extTileFlags % 4;
const auto & tinfo = map->getTile(int3(x, y, z));
auto terrainName = tinfo.getTerrain()->getJsonKey();
if(terrainImages.at(terrainName).size() <= tinfo.terView)
return;
bool hflip = (rotation == 1 || rotation == 3);
bool vflip = (rotation == 2 || rotation == 3);
painter.drawImage(x * tileSize, y * tileSize, terrainImages.at(terrainName)[tinfo.terView]->mirrored(hflip, vflip));
painter.drawImage(x * tileSize, y * tileSize, flippedImage(terrainImages.at(terrainName)[tinfo.terView], tinfo.extTileFlags));
}
void MapHandler::drawRoad(QPainter & painter, int x, int y, int z)
{
auto & tinfo = map->getTile(int3(x, y, z));
const auto & tinfo = map->getTile(int3(x, y, z));
auto * tinfoUpper = map->isInTheMap(int3(x, y - 1, z)) ? &map->getTile(int3(x, y - 1, z)) : nullptr;
if(tinfoUpper && tinfoUpper->roadType)
{
auto roadName = tinfoUpper->getRoad()->getJsonKey();
QRect source(0, tileSize / 2, tileSize, tileSize / 2);
ui8 rotation = (tinfoUpper->extTileFlags >> 4) % 4;
bool hflip = (rotation == 1 || rotation == 3);
bool vflip = (rotation == 2 || rotation == 3);
if(roadImages.at(roadName).size() > tinfoUpper->roadDir)
{
painter.drawImage(QPoint(x * tileSize, y * tileSize), roadImages.at(roadName)[tinfoUpper->roadDir]->mirrored(hflip, vflip), source);
const QRect source{0, tileSize / 2, tileSize, tileSize / 2};
const ui8 rotationFlags = tinfoUpper->extTileFlags >> 4;
painter.drawImage(QPoint(x * tileSize, y * tileSize), flippedImage(roadImages.at(roadName)[tinfoUpper->roadDir], rotationFlags), source);
}
}
if(tinfo.roadType) //print road from this tile
{
auto roadName = tinfo.getRoad()->getJsonKey();
QRect source(0, 0, tileSize, tileSize / 2);
ui8 rotation = (tinfo.extTileFlags >> 4) % 4;
bool hflip = (rotation == 1 || rotation == 3);
bool vflip = (rotation == 2 || rotation == 3);
if(roadImages.at(roadName).size() > tinfo.roadDir)
{
painter.drawImage(QPoint(x * tileSize, y * tileSize + tileSize / 2), roadImages.at(roadName)[tinfo.roadDir]->mirrored(hflip, vflip), source);
const QRect source{0, 0, tileSize, tileSize / 2};
const ui8 rotationFlags = tinfo.extTileFlags >> 4;
painter.drawImage(QPoint(x * tileSize, y * tileSize + tileSize / 2), flippedImage(roadImages.at(roadName)[tinfo.roadDir], rotationFlags), source);
}
}
}
void MapHandler::drawRiver(QPainter & painter, int x, int y, int z)
{
auto & tinfo = map->getTile(int3(x, y, z));
const auto & tinfo = map->getTile(int3(x, y, z));
if(!tinfo.hasRiver())
return;
@@ -148,11 +161,8 @@ void MapHandler::drawRiver(QPainter & painter, int x, int y, int z)
if(riverImages.at(riverName).size() <= tinfo.riverDir)
return;
ui8 rotation = (tinfo.extTileFlags >> 2) % 4;
bool hflip = (rotation == 1 || rotation == 3);
bool vflip = (rotation == 2 || rotation == 3);
painter.drawImage(x * tileSize, y * tileSize, riverImages.at(riverName)[tinfo.riverDir]->mirrored(hflip, vflip));
const ui8 rotationFlags = tinfo.extTileFlags >> 2;
painter.drawImage(x * tileSize, y * tileSize, flippedImage(riverImages.at(riverName)[tinfo.riverDir], rotationFlags));
}
void setPlayerColor(QImage * sur, PlayerColor player)
@@ -295,8 +305,8 @@ bool MapHandler::compareObjectBlitOrder(const CGObjectInstance * a, const CGObje
}
ObjectRect::ObjectRect(const CGObjectInstance * obj_, QRect rect_)
: obj(obj_),
rect(rect_)
: obj(obj_)
, rect(rect_)
{
}