aboutsummaryrefslogtreecommitdiff
path: root/src/BarDisplay.cpp
blob: 9f2d92c198cb008ef0bdcaaa0c2cc7d3223dbb9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <QPainter>

#include "BarDisplay.h"

BarDisplay::BarDisplay(int w, int h) :
    QPixmap(w, h)
{
    m_partCount = 4;
    m_maxValue = 50;
    m_value = 50;

    fill(QColor(Qt::transparent));
}

BarDisplay::~BarDisplay()
{
}

void BarDisplay::initShape()
{
    QPainter p(this);
    QPen pen(QColor(0, 0, 0, 255));
    QBrush brush(m_displayColor);

    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);

    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, 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, 4, (160 / 3) * i, height() - 1 - 5);
}

void BarDisplay::collected(int amount)
{
    m_value += amount;

    if (m_value > m_maxValue)
        m_value = m_maxValue;

    updateDisplay();
}

void BarDisplay::consumed(int amount)
{
    m_value -= amount;

    if (m_value < 0)
        m_value = 0;

    updateDisplay();
}

void BarDisplay::setDisplayColor(QColor col)
{
    m_displayColor = col;
}

void BarDisplay::updateDisplay()
{
    // TODO: update graphics so user knows he is hit
}