diff options
| author | Samu Laaksonen <laaksonen.sj@gmail.com> | 2012-10-21 15:46:32 +0300 |
|---|---|---|
| committer | Samu Laaksonen <laaksonen.sj@gmail.com> | 2012-10-21 15:46:32 +0300 |
| commit | 9674c5ea91912d07f4726140ca2c88669c03f874 (patch) | |
| tree | 3b48d5e812b02fb2bfa581856e0b42bbeafe4fbf | |
| parent | fe15901cad4ccc90b5702cf5061849c1ab1fd40d (diff) | |
| download | prism-9674c5ea91912d07f4726140ca2c88669c03f874.tar.gz prism-9674c5ea91912d07f4726140ca2c88669c03f874.zip | |
HUD demo
Added:
- some ideas to test display of hud elements
Fixed:
- HUD now follows the scene when it moves
| -rw-r--r-- | src/ActionScene.cpp | 6 | ||||
| -rw-r--r-- | src/BarDisplay.cpp | 50 | ||||
| -rw-r--r-- | src/BarDisplay.h | 1 | ||||
| -rw-r--r-- | src/CircularDisplay.cpp | 25 | ||||
| -rw-r--r-- | src/HeadsUpDisplay.cpp | 4 |
5 files changed, 69 insertions, 17 deletions
diff --git a/src/ActionScene.cpp b/src/ActionScene.cpp index 8c6d374..c10bcf6 100644 --- a/src/ActionScene.cpp +++ b/src/ActionScene.cpp @@ -113,7 +113,11 @@ void ActionScene::keyPressEvent(QKeyEvent *event) // button d case 68 : break; + case 16777216 : + gameView()->changeScene(gameView()->getScene("LevelSelectionScene")); + break; default: + qDebug() << event->key(); break; } } @@ -125,7 +129,7 @@ void ActionScene::drawBackground(QPainter *painter, const QRectF &rect) void ActionScene::drawForeground(QPainter *painter, const QRectF &rect) { - painter->drawPixmap(0, 0, width(), height(), *m_hud); + painter->drawPixmap(rect.x(), rect.y(), sceneRect().width(), sceneRect().height(), *m_hud); } void ActionScene::loadMap(QString target) diff --git a/src/BarDisplay.cpp b/src/BarDisplay.cpp index b3e6260..9f2d92c 100644 --- a/src/BarDisplay.cpp +++ b/src/BarDisplay.cpp @@ -20,28 +20,60 @@ void BarDisplay::initShape() { QPainter p(this); QPen pen(QColor(0, 0, 0, 255)); - pen.setWidth(1); - QBrush brush(m_displayColor); - p.setPen(pen); - p.fillRect(0, 0, width(), height(), brush); + p.setPen(Qt::NoPen); + p.setBrush(brush); + + QPolygon one; + one.append(QPoint(0, 0)); + one.append(QPoint(0, height() - 1)); + one.append(QPoint((160 / 3 * 1), height())); + one.append(QPoint((160 / 3 * 1), 0)); + m_healthIndicators.append(one); + + QPolygon two; + two.append(QPoint(0, 0)); + two.append(QPoint(0, height() - 1)); + two.append(QPoint((160 / 3 * 2), height())); + two.append(QPoint((160 / 3 * 2), 0)); + m_healthIndicators.append(two); + + QPolygon three; + three.append(QPoint(0, 0)); + three.append(QPoint(0, height() - 1)); + three.append(QPoint((160 / 3 * 3), height())); + three.append(QPoint((160 / 3 * 3), 0)); + m_healthIndicators.append(three); + + QPolygon four; + four.append(QPoint(0, 0)); + four.append(QPoint(0, height() - 1)); + four.append(QPoint(width() - 1, height())); + four.append(QPoint(width() - 1, 0)); + m_healthIndicators.append(four); + + p.drawPolygon(three); + + p.setBrush(Qt::NoBrush); - // left side - p.drawLine(0, 0, 0, height() - 1); - p.drawLine(0, 0, 20, 0); + pen.setWidth(2); + p.setPen(pen); + // lefttside + p.drawLine(0, 1, 20, 0); + p.drawLine(1, 0, 0, height() - 1); p.drawLine(0, height() - 1, 20, height() - 1); // right side + p.drawLine(width() - 1, 1, width() -1 - 20, 1); p.drawLine(width() - 1, 0, width() - 1, height() - 1); - p.drawLine(width() - 1, 0, width() -1 - 20, 0); p.drawLine(width() - 1, height() - 1, width() - 1 - 20, height() - 1); pen.setWidth(2); p.setPen(pen); // the | -lines for (int i = 1; i < 4; i++) - p.drawLine((160 / 3) * i, 0, (160 / 3) * i - 15, height() - 1); + p.drawLine((160 / 3) * i, 4, (160 / 3) * i, height() - 1 - 5); } void BarDisplay::collected(int amount) diff --git a/src/BarDisplay.h b/src/BarDisplay.h index 27b4d2a..d1ab534 100644 --- a/src/BarDisplay.h +++ b/src/BarDisplay.h @@ -24,6 +24,7 @@ private: int m_value; int m_maxValue; QColor m_displayColor; + QVector<QPolygon> m_healthIndicators; void updateDisplay(); diff --git a/src/CircularDisplay.cpp b/src/CircularDisplay.cpp index 31136e7..7a1dc0f 100644 --- a/src/CircularDisplay.cpp +++ b/src/CircularDisplay.cpp @@ -23,17 +23,32 @@ void CircularDisplay::initShape() QPen pen(QColor(0, 0, 0, 255)); QBrush brush(m_displayColor); - pen.setWidth(5); + pen.setWidth(4); p.setPen(pen); - p.setBrush(brush); // draw base ellipse p.drawEllipse(QPointF(25, 35), 20, 20); + p.setBrush(brush); + + // first 1/4th + //p.drawPie(5, 15, 40, 20, 0, 180 * 16); + + // last 1/4th + //p.drawPie(25, 35, 40, 20, 0, -180 * 16); + + // upper half + //p.drawPie(5, 15, 40, 40, 0, 180 * 16); + + // lower half + pen.setWidth(2); + p.setPen(pen); + p.drawPie(5, 15, 40, 40, 0, -180 * 16); + // draw "tick" lines - p.drawLine(25, 15, 25, 0); // 12 o'clock - p.drawLine(45, 35, 60, 35); // 3 o'clock - p.drawLine(25, 55, 25, 70); // 6 o'clock + //p.drawLine(25, 15, 25, 0); // 12 o'clock + //p.drawLine(45, 35, 60, 35); // 3 o'clock + //p.drawLine(25, 55, 25, 70); // 6 o'clock } void CircularDisplay::setDisplayColor(QColor col) diff --git a/src/HeadsUpDisplay.cpp b/src/HeadsUpDisplay.cpp index 2afa0a5..a455c9b 100644 --- a/src/HeadsUpDisplay.cpp +++ b/src/HeadsUpDisplay.cpp @@ -1,5 +1,5 @@ #include <QPainter> - +#include <QRgb> #include "BarDisplay.h" #include "CircularDisplay.h" @@ -10,7 +10,7 @@ HeadsUpDisplay::HeadsUpDisplay(int w, int h, QGraphicsScene *anchorScene, QObjec { fill(QColor(Qt::transparent)); m_healtBar = new BarDisplay(200, 40); - m_healtBar->setDisplayColor(QColor(255, 0, 127, 127)); + m_healtBar->setDisplayColor(QColor(255, 204, 51, 127)); m_healtBar->initShape(); m_redColor = new CircularDisplay(70, 70); |
