mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 17:32:17 -07:00
Lambda to re-use path calculation.
Took 8 minutes
This commit is contained in:
parent
0fa9fdb967
commit
7a0acb1e5c
1 changed files with 14 additions and 7 deletions
|
|
@ -26,12 +26,19 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
|
||||||
{
|
{
|
||||||
const int radius = 15;
|
const int radius = 15;
|
||||||
const qreal border = 1.5;
|
const qreal border = 1.5;
|
||||||
QPainterPath path(QPointF(50 - border / 2, border / 2));
|
// The box is drawn with a border-wide stroke straddling the path, so the
|
||||||
path.lineTo(radius, border / 2);
|
// visible outline spans [inset, inset + border]. Fills that must not cover
|
||||||
path.arcTo(border / 2, border / 2, 2 * radius, 2 * radius, 90, 90);
|
// the outline (e.g. the life-change flash) use a path inset by `border`.
|
||||||
path.lineTo(border / 2, 30 - border / 2);
|
const auto makePath = [radius](qreal inset) {
|
||||||
path.lineTo(50 - border / 2, 30 - border / 2);
|
QPainterPath path(QPointF(50 - inset, inset));
|
||||||
path.closeSubpath();
|
path.lineTo(radius, inset);
|
||||||
|
path.arcTo(inset, inset, 2 * radius, 2 * radius, 90, 90);
|
||||||
|
path.lineTo(inset, 30 - inset);
|
||||||
|
path.lineTo(50 - inset, 30 - inset);
|
||||||
|
path.closeSubpath();
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
QPainterPath path = makePath(border / 2);
|
||||||
|
|
||||||
QPen pen(QColor(100, 100, 100));
|
QPen pen(QColor(100, 100, 100));
|
||||||
pen.setWidthF(border);
|
pen.setWidthF(border);
|
||||||
|
|
@ -57,7 +64,7 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
painter->setBrush(flashColor);
|
painter->setBrush(flashColor);
|
||||||
painter->setOpacity(0.85);
|
painter->setOpacity(0.85);
|
||||||
painter->drawPath(path);
|
painter->drawPath(makePath(border));
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue