New wind animations

This commit is contained in:
Victor Tran 2018-08-19 17:44:49 +10:00
parent 8ff2168750
commit e84086cad2
No known key found for this signature in database
GPG key ID: FBA10B22D602BAC1
2 changed files with 62 additions and 1 deletions

View file

@ -226,6 +226,8 @@ bool Overview::eventFilter(QObject *watched, QEvent *event) {
//Draw background objects if neccessary
if (currentWeather.isRainy) {
drawRaindrops(&p);
} else if (currentWeather.isWindy) {
drawWind(&p);
}
drawObjects(&p);
@ -420,6 +422,35 @@ void Overview::drawRaindrops(QPainter* p) {
p->restore();
}
void Overview::drawWind(QPainter* p) {
p->save();
for (int i = 0; i < 3; i++) {
if (QRandomGenerator::global()->bounded(4) == 2) {
Wind* w = new Wind();
w->location.setY(QRandomGenerator::global()->bounded(ui->overviewLeftPane->height()));
w->location.setX(QRandomGenerator::global()->bounded(ui->overviewLeftPane->width() * 2) - ui->overviewLeftPane->width() / 2);
w->scale = QRandomGenerator::global()->bounded((double) 3);
w->timeScale = QRandomGenerator::global()->bounded(5) + 1;
winds.append(w);
}
}
QList<Wind*> done;
for (Wind* w : winds) {
w->advance(ui->overviewLeftPane->height(), ui->overviewLeftPane->width());
w->paint(p);
if (w->done) done.append(w);
}
for (Wind* w : done) {
winds.removeAll(w);
delete w;
}
p->restore();
}
void Overview::drawObjects(QPainter* p) {
p->save();
QList<BgObject*> done;
@ -683,6 +714,9 @@ WeatherCondition::WeatherCondition(int code) {
case 21:
explanation = tr("and smoky");
break;
case 23:
explanation = tr("and breezy");
break;
case 24:
explanation = tr("and windy");
break;
@ -733,7 +767,7 @@ WeatherCondition::WeatherCondition(int code) {
}
int cloudyArray[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
20, 21, 22, 23, 27, 28, 35, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47};
20, 21, 22, 27, 28, 35, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47};
isCloudy = (std::find(std::begin(cloudyArray), std::end(cloudyArray), code) != std::end(cloudyArray));
int rainyArray[] = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 17, 35, 37, 38, 39, 40, 45, 47};
@ -742,6 +776,9 @@ WeatherCondition::WeatherCondition(int code) {
int snowyArray[] = {5, 7, 14, 15, 16, 41, 42, 43, 46};
isSnowy = (std::find(std::begin(snowyArray), std::end(snowyArray), code) != std::end(snowyArray));
int windyArray[] = {0, 1, 2, 15, 23, 24};
isWindy = (std::find(std::begin(windyArray), std::end(windyArray), code) != std::end(windyArray));
isNull = false;
}
@ -760,3 +797,15 @@ void Overview::setAttribution(int attrib) {
}
}
}
void Wind::advance(int maxHeight, int maxWidth) {
progress += timeScale;
if (progress >= 100) {
done = true;
}
}
void Wind::paint(QPainter *p) {
p->setPen(QColor(255, 255, 255, 255 - ((float) qBound(0, progress, 100) / 100 * 255)));
p->drawLine(location.x() + progress * scale, location.y(), location.x() + progress * scale + progress * scale, location.y());
}

View file

@ -36,6 +36,15 @@ struct Aircraft : public BgObject {
void paint(QPainter* p);
};
struct Wind : public BgObject {
float scale;
int timeScale;
int progress;
void advance(int maxHeight, int maxWidth);
void paint(QPainter *p);
};
struct WeatherCondition {
Q_DECLARE_TR_FUNCTIONS(WeatherCondition)
@ -49,6 +58,7 @@ public:
bool isCloudy = false;
bool isRainy = false;
bool isSnowy = false;
bool isWindy = false;
bool isNull = true;
};
@ -82,6 +92,7 @@ class Overview : public QWidget, public StatusCenterPaneObject
bool eventFilter(QObject *watched, QEvent *event);
void drawRaindrops(QPainter* p);
void drawWind(QPainter* p);
void drawObjects(QPainter* p);
QTimer *animationTimer, *randomObjectTimer;
@ -94,6 +105,7 @@ class Overview : public QWidget, public StatusCenterPaneObject
int currentYahooAttrib = 0;
QList<Raindrop*> raindrops;
QList<Wind*> winds;
QList<BgObject*> objects;
QSettings settings;