-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabels.cpp
More file actions
executable file
·47 lines (36 loc) · 1.44 KB
/
labels.cpp
File metadata and controls
executable file
·47 lines (36 loc) · 1.44 KB
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
#include "labels.h"
Labels::Labels(int height, Player *player, QGraphicsView* view){
QFont font;
healthlabel = new QLabel("Health: "+ QString::number(player->health), view);
healthlabel->setStyleSheet("background-color: rgba(255, 255, 255, 50); border: none; color: red");
scorelabel = new QLabel("Score: "+ QString::number(player->score), view);
scorelabel->setStyleSheet("background-color: rgba(255, 255, 255, 50); border: none;color: yellow");
healthlabel->show();
healthlabel->move(0,height);
scorelabel->show();
scorelabel->move(0,height+healthlabel->geometry().height());
font = healthlabel->font();
font.setPixelSize(18);
healthlabel->setFont(font);
scorelabel->setFont(font);
Labels::player = player;
Labels::view = view;
}
void Labels::update(){
// Used to update labels
if (player == nullptr){
return;
}
healthlabel->setText("Health: "+ QString::number(player->health));
scorelabel->setText("Score: "+ QString::number(player->score));
auto geo = healthlabel->geometry();
geo.setWidth(healthlabel->fontMetrics().horizontalAdvance(healthlabel->text()));
healthlabel->setGeometry(geo);
geo = scorelabel->geometry();
geo.setWidth(scorelabel->fontMetrics().horizontalAdvance(scorelabel->text()));
scorelabel->setGeometry(geo);
}
void Labels::removePlayer(){
// Used when player is removed and no need for updating
player = nullptr;
}