mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Merge pull request #3088 from Laserlicht/non_squared
Minimap keep aspect ratio (Letterboxing)
This commit is contained in:
commit
a70ad7202f
@ -91,10 +91,19 @@ CMinimap::CMinimap(const Rect & position)
|
||||
level(0)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
pos.w = position.w;
|
||||
pos.h = position.h;
|
||||
|
||||
aiShield = std::make_shared<CPicture>(ImagePath::builtin("AIShield"));
|
||||
double maxSideLenghtSrc = std::max(LOCPLINT->cb->getMapSize().x, LOCPLINT->cb->getMapSize().y);
|
||||
double maxSideLenghtDst = std::max(position.w, position.h);
|
||||
double resize = maxSideLenghtSrc / maxSideLenghtDst;
|
||||
Point newMinimapSize = Point(LOCPLINT->cb->getMapSize().x/ resize, LOCPLINT->cb->getMapSize().y / resize);
|
||||
Point offset = Point((std::max(newMinimapSize.x, newMinimapSize.y) - newMinimapSize.x) / 2, (std::max(newMinimapSize.x, newMinimapSize.y) - newMinimapSize.y) / 2);
|
||||
|
||||
pos.x += offset.x;
|
||||
pos.y += offset.y;
|
||||
pos.w = newMinimapSize.x;
|
||||
pos.h = newMinimapSize.y;
|
||||
|
||||
aiShield = std::make_shared<CPicture>(ImagePath::builtin("AIShield"), -offset);
|
||||
aiShield->disable();
|
||||
}
|
||||
|
||||
@ -167,7 +176,7 @@ void CMinimap::mouseDragged(const Point & cursorPosition, const Point & lastUpda
|
||||
|
||||
void CMinimap::showAll(Canvas & to)
|
||||
{
|
||||
CSDL_Ext::CClipRectGuard guard(to.getInternalSurface(), pos);
|
||||
CSDL_Ext::CClipRectGuard guard(to.getInternalSurface(), aiShield->pos);
|
||||
CIntObject::showAll(to);
|
||||
|
||||
if(minimap)
|
||||
@ -238,4 +247,3 @@ void CMinimap::updateTiles(const std::unordered_set<int3> & positions)
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,7 @@ InfoCard::InfoCard()
|
||||
pos.y += 6;
|
||||
|
||||
labelSaveDate = std::make_shared<CLabel>(310, 38, FONT_SMALL, ETextAlignment::BOTTOMRIGHT, Colors::WHITE);
|
||||
labelMapSize = std::make_shared<CLabel>(333, 56, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE);
|
||||
mapName = std::make_shared<CLabel>(26, 39, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW);
|
||||
Rect descriptionRect(26, 149, 320, 115);
|
||||
mapDescription = std::make_shared<CTextBox>("", descriptionRect, 1);
|
||||
@ -193,6 +194,7 @@ InfoCard::InfoCard()
|
||||
void InfoCard::disableLabelRedraws()
|
||||
{
|
||||
labelSaveDate->setAutoRedraw(false);
|
||||
labelMapSize->setAutoRedraw(false);
|
||||
mapName->setAutoRedraw(false);
|
||||
mapDescription->label->setAutoRedraw(false);
|
||||
labelVictoryConditionText->setAutoRedraw(false);
|
||||
@ -208,6 +210,7 @@ void InfoCard::changeSelection()
|
||||
return;
|
||||
|
||||
labelSaveDate->setText(mapInfo->date);
|
||||
labelMapSize->setText(std::to_string(mapInfo->mapHeader->width) + "x" + std::to_string(mapInfo->mapHeader->height));
|
||||
mapName->setText(mapInfo->getNameTranslated());
|
||||
mapDescription->setText(mapInfo->getDescriptionTranslated());
|
||||
|
||||
|
@ -80,6 +80,7 @@ class InfoCard : public CIntObject
|
||||
std::shared_ptr<CAnimImage> iconsMapSizes;
|
||||
|
||||
std::shared_ptr<CLabel> labelSaveDate;
|
||||
std::shared_ptr<CLabel> labelMapSize;
|
||||
std::shared_ptr<CLabel> labelScenarioName;
|
||||
std::shared_ptr<CLabel> labelScenarioDescription;
|
||||
std::shared_ptr<CLabel> labelVictoryCondition;
|
||||
|
@ -186,3 +186,8 @@ SDL_Surface * Canvas::getInternalSurface()
|
||||
{
|
||||
return surface;
|
||||
}
|
||||
|
||||
Rect Canvas::getRenderArea() const
|
||||
{
|
||||
return renderArea;
|
||||
}
|
||||
|
@ -101,4 +101,7 @@ public:
|
||||
|
||||
/// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished.
|
||||
SDL_Surface * getInternalSurface();
|
||||
|
||||
/// get the render area
|
||||
Rect getRenderArea() const;
|
||||
};
|
||||
|
@ -135,8 +135,14 @@ std::shared_ptr<CPicture> CMapOverviewWidget::buildDrawMinimap(const JsonNode &
|
||||
if(id >= minimaps.size())
|
||||
return nullptr;
|
||||
|
||||
Rect minimapRect = minimaps[id].getRenderArea();
|
||||
double maxSideLenghtSrc = std::max(minimapRect.w, minimapRect.h);
|
||||
double maxSideLenghtDst = std::max(rect.w, rect.h);
|
||||
double resize = maxSideLenghtSrc / maxSideLenghtDst;
|
||||
Point newMinimapSize = Point(minimapRect.w / resize, minimapRect.h / resize);
|
||||
|
||||
Canvas canvasScaled = Canvas(Point(rect.w, rect.h));
|
||||
canvasScaled.drawScaled(minimaps[id], Point(0, 0), Point(rect.w, rect.h));
|
||||
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());
|
||||
|
||||
return std::make_shared<CPicture>(img, Point(rect.x, rect.y));
|
||||
|
Loading…
Reference in New Issue
Block a user