mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Refactor] Move table row mapping from TableZone into TableZoneLogic (#7413)
* [Refactor] Move table row mapping from TableZone into TableZoneLogic * [Game] Use TableZoneLogic::ROW_COUNT directly per review * [Format] Match clang-format line breaking in table_zone --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
d30d275296
commit
52c5bd2ea3
5 changed files with 47 additions and 43 deletions
|
|
@ -62,7 +62,8 @@ TableZone::TableZone(TableZoneLogic *_logic, bool _mirrored, QGraphicsItem *pare
|
|||
|
||||
updateBg();
|
||||
|
||||
height = MARGIN_TOP + MARGIN_BOTTOM + TABLEROWS * CardDimensions::HEIGHT + (TABLEROWS - 1) * PADDING_Y;
|
||||
height = MARGIN_TOP + MARGIN_BOTTOM + TableZoneLogic::ROW_COUNT * CardDimensions::HEIGHT +
|
||||
(TableZoneLogic::ROW_COUNT - 1) * PADDING_Y;
|
||||
width = MIN_WIDTH;
|
||||
currentMinimumWidth = width;
|
||||
|
||||
|
|
@ -397,7 +398,7 @@ QPointF TableZone::mapFromGrid(QPoint gridPoint) const
|
|||
}
|
||||
|
||||
if (isInverted()) {
|
||||
gridPoint.setY(TABLEROWS - 1 - gridPoint.y());
|
||||
gridPoint.setY(TableZoneLogic::ROW_COUNT - 1 - gridPoint.y());
|
||||
}
|
||||
|
||||
// Start with margin plus stacked card offset
|
||||
|
|
@ -423,10 +424,10 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
|||
const int gridPointHeight = CardDimensions::HEIGHT + PADDING_Y;
|
||||
int gridPointY = (y + PADDING_Y / 2) / gridPointHeight;
|
||||
|
||||
gridPointY = clampValidTableRow(gridPointY);
|
||||
gridPointY = TableZoneLogic::clampValidTableRow(gridPointY);
|
||||
|
||||
if (isInverted()) {
|
||||
gridPointY = TABLEROWS - 1 - gridPointY;
|
||||
gridPointY = TableZoneLogic::ROW_COUNT - 1 - gridPointY;
|
||||
}
|
||||
|
||||
// Calculating the x-coordinate of the grid space requires adding up the
|
||||
|
|
@ -471,22 +472,3 @@ QPointF TableZone::closestGridPoint(const QPointF &point)
|
|||
}
|
||||
return mapFromGrid(gridPoint);
|
||||
}
|
||||
|
||||
int TableZone::clampValidTableRow(const int row)
|
||||
{
|
||||
if (row < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (row >= TABLEROWS) {
|
||||
return TABLEROWS - 1;
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
int TableZone::tableRowToGridY(int tableRow)
|
||||
{
|
||||
if (tableRow > 2) {
|
||||
tableRow = 1;
|
||||
}
|
||||
return clampValidTableRow(2 - tableRow);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue