1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 #include "ui/effects/animations.h"
11 
12 namespace Ui {
13 
14 class FireworksAnimation final {
15 public:
16 	explicit FireworksAnimation(Fn<void()> repaint);
17 
18 	bool paint(QPainter &p, const QRect &rect);
19 
20 private:
21 	struct Particle {
22 		enum class Type : uchar {
23 			Circle,
24 			Rectangle
25 		};
26 
27 		float64 x = 0.;
28 		float64 y = 0.;
29 		float64 moveX = 0.;
30 		float64 moveY = 0.;
31 		uint16 rotation = 0;
32 
33 		Type type = Type::Circle;
34 		uchar color = 0;
35 		bool right = false;
36 		uchar size = 0;
37 		uchar xFinished = 0;
38 		uchar finishedStart = 0;
39 		bool finished = false;
40 	};
41 
42 	void update(crl::time now);
43 	void startFall();
44 	void paintParticle(
45 		QPainter &p,
46 		const Particle &particle,
47 		const QRect &rect);
48 	void initParticle(Particle &particle, bool falling);
49 	void updateParticle(Particle &particle, crl::time dt);
50 
51 	std::vector<Particle> _particles;
52 	std::vector<QBrush> _brushes;
53 	Ui::Animations::Basic _animation;
54 	Fn<void()> _repaint;
55 	crl::time _lastUpdate = 0;
56 	float64 _speedCoef = 1.;
57 	int _fallingDown = 0;
58 	int _smallSide = 0;
59 	bool _startedFall = false;
60 
61 };
62 
63 } // namespace Ui
64