mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-28 00:42:19 -07:00
Comments.
Took 29 minutes
This commit is contained in:
parent
d50a2d533b
commit
34ee64b2a1
3 changed files with 16 additions and 10 deletions
|
|
@ -187,8 +187,8 @@ void PlayerGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||||
|
|
||||||
QRectF combinedArea(combinedLeft, combinedTop, combinedRight - combinedLeft, combinedBottom - combinedTop);
|
QRectF combinedArea(combinedLeft, combinedTop, combinedRight - combinedLeft, combinedBottom - combinedTop);
|
||||||
|
|
||||||
const QRectF srcRect = computeArtSourceRect(playmatPixmap.size(), playmatParams);
|
const QRectF srcRect = PlaymatUtils::computeArtSourceRect(playmatPixmap.size(), playmatParams);
|
||||||
const QRectF dstRect = coverFitRect(combinedArea, srcRect.size());
|
const QRectF dstRect = PlaymatUtils::coverFitRect(combinedArea, srcRect.size());
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setClipRect(combinedArea);
|
painter->setClipRect(combinedArea);
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ void PlaymatPreviewWidget::paintEvent(QPaintEvent *)
|
||||||
// Stack is ~20% width on the left, table is ~80% on the right
|
// Stack is ~20% width on the left, table is ~80% on the right
|
||||||
const QRectF playArea = cardRect.adjusted(6, 4, -4, -4);
|
const QRectF playArea = cardRect.adjusted(6, 4, -4, -4);
|
||||||
|
|
||||||
const QRectF srcRect = computeArtSourceRect(sourcePixmap.size(), params);
|
const QRectF srcRect = PlaymatUtils::computeArtSourceRect(sourcePixmap.size(), params);
|
||||||
const QRectF dstRect = coverFitRect(playArea, srcRect.size());
|
const QRectF dstRect = PlaymatUtils::coverFitRect(playArea, srcRect.size());
|
||||||
|
|
||||||
painter.setClipRect(playArea.toRect());
|
painter.setClipRect(playArea.toRect());
|
||||||
painter.drawPixmap(dstRect, sourcePixmap, srcRect);
|
painter.drawPixmap(dstRect, sourcePixmap, srcRect);
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,11 @@
|
||||||
#include <QSizeF>
|
#include <QSizeF>
|
||||||
#include <libcockatrice/deck_list/deck_list.h>
|
#include <libcockatrice/deck_list/deck_list.h>
|
||||||
|
|
||||||
inline qreal playmatMaxZoom()
|
namespace PlaymatUtils
|
||||||
{
|
{
|
||||||
return 4.0;
|
|
||||||
}
|
/** @brief Upper bound for zooming into the playmat art. */
|
||||||
|
constexpr qreal MAX_ZOOM = 4.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Width of the outer viewing window: full card width trimmed by the
|
* @brief Width of the outer viewing window: full card width trimmed by the
|
||||||
|
|
@ -38,7 +39,11 @@ inline qreal playmatClampedZoom(const QSize &fullCardSize, const PlaymatParams &
|
||||||
const qreal minDim = qMin<qreal>(fullCardSize.width(), fullCardSize.height());
|
const qreal minDim = qMin<qreal>(fullCardSize.width(), fullCardSize.height());
|
||||||
const qreal visibleW = playmatVisibleWidth(fullCardSize, params);
|
const qreal visibleW = playmatVisibleWidth(fullCardSize, params);
|
||||||
const qreal zoomOutFloor = (minDim > 0.0 && visibleW > 0.0) ? visibleW / minDim : 1.0;
|
const qreal zoomOutFloor = (minDim > 0.0 && visibleW > 0.0) ? visibleW / minDim : 1.0;
|
||||||
return qBound(qMin(zoomOutFloor, playmatMaxZoom()), params.zoom, playmatMaxZoom());
|
// The floor deliberately bypasses MAX_ZOOM: when the art is much wider
|
||||||
|
// than tall, keeping the square window inside it requires more than 4x
|
||||||
|
// zoom-out, and honoring that larger floor keeps side within
|
||||||
|
// min(card width, height). Zooming IN is still capped at MAX_ZOOM.
|
||||||
|
return qMin(MAX_ZOOM, qMax(params.zoom, zoomOutFloor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -80,8 +85,7 @@ inline QRectF computeArtSourceRect(const QSize &fullCardSize, const PlaymatParam
|
||||||
// verticalOffset places the TOP edge of the sampling window itself within
|
// verticalOffset places the TOP edge of the sampling window itself within
|
||||||
// its travel, so the full [0, 1] parameter range is live at every zoom and
|
// its travel, so the full [0, 1] parameter range is live at every zoom and
|
||||||
// the window can always reach the very top (0.0) and bottom (1.0) of the
|
// the window can always reach the very top (0.0) and bottom (1.0) of the
|
||||||
// art. At zoom 1 this is byte identical to the released formula, because
|
// art.
|
||||||
// the sampling window then equals the outer trimmed span.
|
|
||||||
const qreal offset = qBound(0.0, params.verticalOffset, 1.0);
|
const qreal offset = qBound(0.0, params.verticalOffset, 1.0);
|
||||||
const qreal y = offset * qMax(0.0, srcH - side);
|
const qreal y = offset * qMax(0.0, srcH - side);
|
||||||
|
|
||||||
|
|
@ -131,4 +135,6 @@ inline QRectF aspectFitRect(const QRectF &dstArea, qreal aspect)
|
||||||
return QRectF(dstArea.left() + (dstArea.width() - w) / 2.0, dstArea.top() + (dstArea.height() - h) / 2.0, w, h);
|
return QRectF(dstArea.left() + (dstArea.width() - w) / 2.0, dstArea.top() + (dstArea.height() - h) / 2.0, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace PlaymatUtils
|
||||||
|
|
||||||
#endif // COCKATRICE_PLAYMAT_UTILS_H
|
#endif // COCKATRICE_PLAYMAT_UTILS_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue