mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-11 04:23:29 -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
|
||||
|
|
|
|||
|
|
@ -20,6 +20,13 @@ namespace CardArtUtils
|
|||
* @return @p art rotated 90° clockwise for sideways-layout cards, else @p art.
|
||||
*/
|
||||
QPixmap rotateSidewaysLayoutArt(const QPixmap &art, const ExactCard &card);
|
||||
|
||||
/**
|
||||
* Return the upright artwork used by banner previews, user rows and profile
|
||||
* popups. The crop excludes conventional name and rules boxes before callers apply
|
||||
* their saved pan and zoom, so a taller popup cannot expose the card frame.
|
||||
*/
|
||||
QPixmap cropCardArt(const QPixmap &art, const ExactCard &card);
|
||||
} // namespace CardArtUtils
|
||||
|
||||
#endif // CARD_ART_UTILS_H
|
||||
#endif // CARD_ART_UTILS_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue