diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc
index bea7ad2c..4943700d 100644
--- a/cockatrice/cockatrice.qrc
+++ b/cockatrice/cockatrice.qrc
@@ -74,6 +74,19 @@
resources/countries/uk.svg
resources/countries/us.svg
+ resources/counters/w.svg
+ resources/counters/w_highlight.svg
+ resources/counters/u.svg
+ resources/counters/u_highlight.svg
+ resources/counters/b.svg
+ resources/counters/b_highlight.svg
+ resources/counters/r.svg
+ resources/counters/r_highlight.svg
+ resources/counters/g.svg
+ resources/counters/g_highlight.svg
+ resources/counters/general.svg
+ resources/counters/general_highlight.svg
+
resources/userlevels/normal.svg
resources/userlevels/registered.svg
resources/userlevels/judge.svg
diff --git a/cockatrice/resources/counters/b.svg b/cockatrice/resources/counters/b.svg
new file mode 100644
index 00000000..f3c31498
--- /dev/null
+++ b/cockatrice/resources/counters/b.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/b_highlight.svg b/cockatrice/resources/counters/b_highlight.svg
new file mode 100644
index 00000000..db167f98
--- /dev/null
+++ b/cockatrice/resources/counters/b_highlight.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/g.svg b/cockatrice/resources/counters/g.svg
new file mode 100644
index 00000000..bf44af65
--- /dev/null
+++ b/cockatrice/resources/counters/g.svg
@@ -0,0 +1,250 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/g_highlight.svg b/cockatrice/resources/counters/g_highlight.svg
new file mode 100644
index 00000000..2d390f4d
--- /dev/null
+++ b/cockatrice/resources/counters/g_highlight.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/general.svg b/cockatrice/resources/counters/general.svg
new file mode 100644
index 00000000..beec030f
--- /dev/null
+++ b/cockatrice/resources/counters/general.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/general_highlight.svg b/cockatrice/resources/counters/general_highlight.svg
new file mode 100644
index 00000000..f54eb23f
--- /dev/null
+++ b/cockatrice/resources/counters/general_highlight.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/r.svg b/cockatrice/resources/counters/r.svg
new file mode 100644
index 00000000..339b0ebb
--- /dev/null
+++ b/cockatrice/resources/counters/r.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/r_highlight.svg b/cockatrice/resources/counters/r_highlight.svg
new file mode 100644
index 00000000..3f1d398c
--- /dev/null
+++ b/cockatrice/resources/counters/r_highlight.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/u.svg b/cockatrice/resources/counters/u.svg
new file mode 100644
index 00000000..5dfe5d89
--- /dev/null
+++ b/cockatrice/resources/counters/u.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/u_highlight.svg b/cockatrice/resources/counters/u_highlight.svg
new file mode 100644
index 00000000..d2b78a0d
--- /dev/null
+++ b/cockatrice/resources/counters/u_highlight.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/w.svg b/cockatrice/resources/counters/w.svg
new file mode 100644
index 00000000..60548880
--- /dev/null
+++ b/cockatrice/resources/counters/w.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/resources/counters/w_highlight.svg b/cockatrice/resources/counters/w_highlight.svg
new file mode 100644
index 00000000..8862981d
--- /dev/null
+++ b/cockatrice/resources/counters/w_highlight.svg
@@ -0,0 +1,249 @@
+
+
+
+
diff --git a/cockatrice/src/counter_general.cpp b/cockatrice/src/counter_general.cpp
index 6b722834..6ded4732 100644
--- a/cockatrice/src/counter_general.cpp
+++ b/cockatrice/src/counter_general.cpp
@@ -1,9 +1,11 @@
#include "counter_general.h"
+#include "pixmapgenerator.h"
#include
GeneralCounter::GeneralCounter(Player *_player, int _id, const QString &_name, const QColor &_color, int _radius, int _value, QGraphicsItem *parent)
: AbstractCounter(_player, _id, _name, true, _value, parent), color(_color), radius(_radius)
{
+ setCacheMode(DeviceCoordinateCache);
}
QRectF GeneralCounter::boundingRect() const
@@ -13,14 +15,22 @@ QRectF GeneralCounter::boundingRect() const
void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
- painter->setBrush(QBrush(color));
- painter->drawEllipse(boundingRect());
+ QRectF mapRect = painter->combinedTransform().mapRect(boundingRect());
+ int translatedHeight = mapRect.size().height();
+ qreal scaleFactor = translatedHeight / boundingRect().height();
+ QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered);
+
+ painter->save();
+ painter->resetTransform();
+ painter->drawPixmap(QPoint(0, 0), pixmap);
+
if (value) {
QFont f("Serif");
- f.setPixelSize(radius * 0.8);
+ f.setPixelSize(qMax((int) (radius * scaleFactor), 10));
f.setWeight(QFont::Bold);
+ painter->setPen(Qt::black);
painter->setFont(f);
- painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(value));
+ painter->drawText(mapRect, Qt::AlignCenter, QString::number(value));
}
+ painter->restore();
}
-
diff --git a/cockatrice/src/pixmapgenerator.cpp b/cockatrice/src/pixmapgenerator.cpp
index 507042f0..e3325d42 100644
--- a/cockatrice/src/pixmapgenerator.cpp
+++ b/cockatrice/src/pixmapgenerator.cpp
@@ -5,6 +5,34 @@
#include
#include
+QMap CounterPixmapGenerator::pmCache;
+
+QPixmap CounterPixmapGenerator::generatePixmap(int height, QString name, bool highlight)
+{
+ if (highlight)
+ name.append("_highlight");
+ QString key = name + QString::number(height);
+ if (pmCache.contains(key))
+ return pmCache.value(key);
+
+ QSvgRenderer svg(QString(":/resources/counters/" + name + ".svg"));
+
+ if (!svg.isValid()) {
+ name = "general";
+ if (highlight)
+ name.append("_highlight");
+ svg.load(QString(":/resources/counters/" + name + ".svg"));
+ }
+
+ int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
+ QPixmap pixmap(width, height);
+ pixmap.fill(Qt::transparent);
+ QPainter painter(&pixmap);
+ svg.render(&painter, QRectF(0, 0, width, height));
+ pmCache.insert(key, pixmap);
+ return pixmap;
+}
+
QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max)
{
int key = size * 1000000 + max * 1000 + value;
diff --git a/cockatrice/src/pixmapgenerator.h b/cockatrice/src/pixmapgenerator.h
index 2479bf28..d988b679 100644
--- a/cockatrice/src/pixmapgenerator.h
+++ b/cockatrice/src/pixmapgenerator.h
@@ -4,6 +4,14 @@
#include
#include
+class CounterPixmapGenerator {
+private:
+ static QMap pmCache;
+public:
+ static QPixmap generatePixmap(int size, QString name, bool highlight);
+ static void clear() { pmCache.clear(); }
+};
+
class PingPixmapGenerator {
private:
static QMap pmCache;
diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp
index 0d7ab7a4..8219c0ff 100644
--- a/cockatrice/src/player.cpp
+++ b/cockatrice/src/player.cpp
@@ -1220,7 +1220,6 @@ void Player::clearArrows()
void Player::rearrangeCounters()
{
qreal marginTop = 80;
- qreal marginBottom = 10;
// Determine total height of bounding rectangles
qreal totalHeight = 0;
@@ -1231,15 +1230,9 @@ void Player::rearrangeCounters()
totalHeight += counterIterator.value()->boundingRect().height();
}
- // Determine free space between objects
- qreal padding = (boundingRect().height() - marginTop - marginBottom - totalHeight) / (counters.size() - 1);
+ const qreal padding = 10;
qreal y = boundingRect().y() + marginTop;
- if (counters.size() == 1) {
- padding = 0;
- y += (boundingRect().height() - marginTop - marginBottom) / 2;
- }
-
// Place objects
for (counterIterator.toFront(); counterIterator.hasNext(); ) {
AbstractCounter *c = counterIterator.next().value();