mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Banner] Keep horizontal user banner crops inside the artwork (#7742)
This commit is contained in:
parent
d944273335
commit
e558c0dffa
7 changed files with 139 additions and 32 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "libcockatrice/card/card_info.h"
|
||||
|
||||
#include <QRect>
|
||||
#include <QSize>
|
||||
#include <QTransform>
|
||||
#include <libcockatrice/card/printing/exact_card.h>
|
||||
#include <qnamespace.h>
|
||||
|
|
@ -18,4 +20,23 @@ QPixmap rotateSidewaysLayoutArt(const QPixmap &art, const ExactCard &card)
|
|||
transform.rotate(90);
|
||||
return art.transformed(transform, Qt::SmoothTransformation);
|
||||
}
|
||||
} // namespace CardArtUtils
|
||||
|
||||
QPixmap cropCardArt(const QPixmap &art, const ExactCard &card)
|
||||
{
|
||||
if (art.isNull()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const QPixmap source = rotateSidewaysLayoutArt(art, card);
|
||||
const bool landscape = card.getInfo().getUiAttributes().landscapeOrientation;
|
||||
const QSize size = source.size();
|
||||
const int marginX = size.width() * 0.07;
|
||||
// Landscape name boxes extend below 5% of the upright image. Remove the
|
||||
// whole box here, rather than relying on the banner's narrow viewport to
|
||||
// hide it: the same saved offset is also used by the taller profile popup.
|
||||
const int topMargin = size.height() * (landscape ? 0.15 : 0.11);
|
||||
const int bottomMargin = size.height() * 0.45;
|
||||
const QRect crop(marginX, topMargin, size.width() - 2 * marginX, size.height() - topMargin - bottomMargin);
|
||||
return source.copy(crop.intersected(source.rect()));
|
||||
}
|
||||
} // namespace CardArtUtils
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue