mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-03 12:03:55 -07:00
[Refactor] Move AbstractGraphicsItem and GraphicsItemType to game_graphics/board (#6342)
* [Refactor] Move AbstractGraphicsItem and GraphicsItemType to game_graphics/board folder. Took 3 minutes * Update CMakeLists.txt Took 12 minutes * Update CMakeLists.txt Took 12 minutes Took 2 minutes Took 16 seconds --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
8788a7aada
commit
9957cb20e2
13 changed files with 12 additions and 12 deletions
|
|
@ -0,0 +1,65 @@
|
|||
#include "abstract_graphics_item.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
void AbstractGraphicsItem::paintNumberEllipse(int number,
|
||||
int fontSize,
|
||||
const QColor &color,
|
||||
int position,
|
||||
int count,
|
||||
QPainter *painter)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QString numStr = QString::number(number);
|
||||
QFont font("Serif");
|
||||
font.setPixelSize(fontSize);
|
||||
font.setWeight(QFont::Bold);
|
||||
|
||||
QFontMetrics fm(font);
|
||||
double w = 1.3 *
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
fm.horizontalAdvance(numStr);
|
||||
#else
|
||||
fm.width(numStr);
|
||||
#endif
|
||||
double h = fm.height() * 1.3;
|
||||
if (w < h)
|
||||
w = h;
|
||||
|
||||
painter->setPen(QColor(255, 255, 255, 0));
|
||||
painter->setBrush(QBrush(QColor(color)));
|
||||
|
||||
QRectF textRect;
|
||||
if (position == -1)
|
||||
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
|
||||
else {
|
||||
qreal xOffset = 10;
|
||||
qreal yOffset = 20;
|
||||
qreal spacing = 2;
|
||||
if (position < 2)
|
||||
textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0)
|
||||
: (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)),
|
||||
yOffset, w, h);
|
||||
else
|
||||
textRect = QRectF(count == 3 ? ((boundingRect().width() - w) / 2.0)
|
||||
: (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)),
|
||||
yOffset + (spacing + h) * (position / 2), w, h);
|
||||
}
|
||||
|
||||
painter->drawEllipse(textRect);
|
||||
|
||||
painter->setPen(Qt::black);
|
||||
painter->setFont(font);
|
||||
painter->drawText(textRect, Qt::AlignCenter, numStr);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
int resetPainterTransform(QPainter *painter)
|
||||
{
|
||||
painter->resetTransform();
|
||||
auto tx = painter->deviceTransform().inverted();
|
||||
painter->setTransform(tx);
|
||||
return tx.isScaling() ? 1.0 / tx.m11() : 1;
|
||||
}
|
||||
30
cockatrice/src/game_graphics/board/abstract_graphics_item.h
Normal file
30
cockatrice/src/game_graphics/board/abstract_graphics_item.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @file abstract_graphics_item.h
|
||||
* @ingroup GameGraphics
|
||||
* @brief TODO: Document this.
|
||||
*/
|
||||
|
||||
#ifndef ABSTRACTGRAPHICSITEM_H
|
||||
#define ABSTRACTGRAPHICSITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
/**
|
||||
* Parent class of all objects that appear in a game.
|
||||
*/
|
||||
class AbstractGraphicsItem : public QGraphicsObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter);
|
||||
|
||||
public:
|
||||
explicit AbstractGraphicsItem(QGraphicsItem *parent = nullptr) : QGraphicsObject(parent)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
int resetPainterTransform(QPainter *painter);
|
||||
|
||||
#endif
|
||||
22
cockatrice/src/game_graphics/board/graphics_item_type.h
Normal file
22
cockatrice/src/game_graphics/board/graphics_item_type.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* @file graphics_item_type.h
|
||||
* @ingroup GameGraphics
|
||||
* @brief TODO: Document this.
|
||||
*/
|
||||
|
||||
#ifndef COCKATRICE_GRAPHICS_ITEM_TYPE_H
|
||||
#define COCKATRICE_GRAPHICS_ITEM_TYPE_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
enum GraphicsItemType
|
||||
{
|
||||
typeCard = QGraphicsItem::UserType + 1,
|
||||
typeCardDrag = QGraphicsItem::UserType + 2,
|
||||
typeZone = QGraphicsItem::UserType + 3,
|
||||
typePlayerTarget = QGraphicsItem::UserType + 4,
|
||||
typeDeckViewCardContainer = QGraphicsItem::UserType + 5,
|
||||
typeOther = QGraphicsItem::UserType + 6
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_GRAPHICS_ITEM_TYPE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue