-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflapsindicator.cpp
110 lines (85 loc) · 3.08 KB
/
flapsindicator.cpp
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
108
#include "flapsindicator.h"
#include <cmath>
#include <iostream>
FlapsIndicator::FlapsIndicator(QJsonObject params, int nr, InstrumentPanel *parent, bool edit) :
GenericIndicator(params, nr, parent, edit)
{
text.setText("");
text.resize(params["w"].toDouble(), params["h"].toDouble());
this->resize(text.size());
pic = new QPixmap("./images/flaps.png");
painter = new QPainter();
text.setPixmap(pic->scaled(text.size(), Qt::KeepAspectRatio));
}
void FlapsIndicator::update_ind(Gamestate* actual)
{
QJsonObject info = actual->state.object();
if(actual->state.object()["valid"].toBool())
{
text.setPixmap(pic->scaled(text.size(), Qt::KeepAspectRatio));
QPixmap dev = *(text.pixmap());
painter->begin(&dev);
QPen pen(QColor(255,0,0));
pen.setWidthF(0.3/4.8*text.size().height());
painter->setPen(pen);
int flaps = info["flaps, %"].toDouble();
int airbrake = info["airbrake, %"].toDouble();
int gear = info["gear, %"].toDouble();
int x1, x2, y1, y2;
if(flaps>0)
{
x1 = 3.0/6.4*text.size().width();
y1 = 1.9/4.8*text.size().height();
x2 = x1+cos(M_PI/2*flaps/100.0)*0.3*text.size().width();
y2 = y1+sin(M_PI/2*flaps/100.0)*0.3*text.size().height();
painter->drawLine(x1, y1, x2, y2);
}
if(airbrake>0)
{
x1 = .4/6.4*text.size().width();
y1 = 1.8/4.8*text.size().height();
x2 = x1+cos(M_PI/2*airbrake/100.0)*0.2*text.size().width();
y2 = y1+sin(M_PI/2*airbrake/100.0)*0.2*text.size().height();
painter->drawLine(x1, y1, x2, y2);
x1 = .4/6.4*text.size().width();
y1 = 1.8/4.8*text.size().height();
x2 = x1+cos(-M_PI/2*airbrake/100.0)*0.2*text.size().width();
y2 = y1+sin(-M_PI/2*airbrake/100.0)*0.2*text.size().height();
painter->drawLine(x1, y1, x2, y2);
}
if(gear>0)
{
x1 = 1.4/6.4*text.size().width();
y1 = 2.38/4.8*text.size().height();
x2 = x1+cos(M_PI/2*gear/100.0)*0.15*text.size().width();
y2 = y1+sin(M_PI/2*gear/100.0)*0.15*text.size().height();
painter->drawLine(x1, y1, x2, y2);
int eclsize = 0.1*text.size().width();
painter->drawEllipse(x2-eclsize/2,y2-eclsize/2, eclsize , eclsize);
}
painter->end();
text.setPixmap(dev);
}
if(!(actual->state.object()["valid"].toBool()) or\
(info["flaps, %"].isNull()\
and info["gear, %"].isNull()\
and info["airbrake, %"].isNull()))
{
this->hide();
}
else
this->show();
}
void FlapsIndicator::wheelEvent(QWheelEvent *e)
{
if(editMode)
{
float diff = e->angleDelta().y()/120;
QSize d(diff, diff);
QSize old = this->size();
text.resize(old+=d);
this->resize(text.size());
text.setPixmap(pic->scaled(text.size(), Qt::KeepAspectRatio));
e->accept();
}
}