fireworks_animation.h 1.3 KB

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