From 34ee64b2a1f7b8a6ba55561c8df6380fcabb90ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 23 Aug 2026 12:14:07 +0200 Subject: [PATCH] Comments. Took 29 minutes --- .../player/player_graphics_item.cpp | 4 ++-- .../widgets/playmat/playmat_preview_widget.cpp | 4 ++-- .../interface/widgets/playmat/playmat_utils.h | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cockatrice/src/game_graphics/player/player_graphics_item.cpp b/cockatrice/src/game_graphics/player/player_graphics_item.cpp index 026e00588..8bf2703e1 100644 --- a/cockatrice/src/game_graphics/player/player_graphics_item.cpp +++ b/cockatrice/src/game_graphics/player/player_graphics_item.cpp @@ -187,8 +187,8 @@ void PlayerGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem QRectF combinedArea(combinedLeft, combinedTop, combinedRight - combinedLeft, combinedBottom - combinedTop); - const QRectF srcRect = computeArtSourceRect(playmatPixmap.size(), playmatParams); - const QRectF dstRect = coverFitRect(combinedArea, srcRect.size()); + const QRectF srcRect = PlaymatUtils::computeArtSourceRect(playmatPixmap.size(), playmatParams); + const QRectF dstRect = PlaymatUtils::coverFitRect(combinedArea, srcRect.size()); painter->save(); painter->setClipRect(combinedArea); diff --git a/cockatrice/src/interface/widgets/playmat/playmat_preview_widget.cpp b/cockatrice/src/interface/widgets/playmat/playmat_preview_widget.cpp index dc3afc2cd..52f21f714 100644 --- a/cockatrice/src/interface/widgets/playmat/playmat_preview_widget.cpp +++ b/cockatrice/src/interface/widgets/playmat/playmat_preview_widget.cpp @@ -61,8 +61,8 @@ void PlaymatPreviewWidget::paintEvent(QPaintEvent *) // Stack is ~20% width on the left, table is ~80% on the right const QRectF playArea = cardRect.adjusted(6, 4, -4, -4); - const QRectF srcRect = computeArtSourceRect(sourcePixmap.size(), params); - const QRectF dstRect = coverFitRect(playArea, srcRect.size()); + const QRectF srcRect = PlaymatUtils::computeArtSourceRect(sourcePixmap.size(), params); + const QRectF dstRect = PlaymatUtils::coverFitRect(playArea, srcRect.size()); painter.setClipRect(playArea.toRect()); painter.drawPixmap(dstRect, sourcePixmap, srcRect); diff --git a/cockatrice/src/interface/widgets/playmat/playmat_utils.h b/cockatrice/src/interface/widgets/playmat/playmat_utils.h index 0f1420498..0691a9637 100644 --- a/cockatrice/src/interface/widgets/playmat/playmat_utils.h +++ b/cockatrice/src/interface/widgets/playmat/playmat_utils.h @@ -6,10 +6,11 @@ #include #include -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 @@ -38,7 +39,11 @@ inline qreal playmatClampedZoom(const QSize &fullCardSize, const PlaymatParams & const qreal minDim = qMin(fullCardSize.width(), fullCardSize.height()); const qreal visibleW = playmatVisibleWidth(fullCardSize, params); 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 // 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 - // art. At zoom 1 this is byte identical to the released formula, because - // the sampling window then equals the outer trimmed span. + // art. const qreal offset = qBound(0.0, params.verticalOffset, 1.0); 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); } +} // namespace PlaymatUtils + #endif // COCKATRICE_PLAYMAT_UTILS_H