snowflakes.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 Snowflakes final {
  11. public:
  12. Snowflakes(Fn<void(const QRect &r)> updateCallback);
  13. void paint(QPainter &p, const QRectF &rect);
  14. void setPaused(bool paused);
  15. void setBrush(QBrush brush);
  16. private:
  17. enum class Type {
  18. Dot,
  19. Snowflake,
  20. };
  21. struct Interval {
  22. int from = 0;
  23. int length = 0;
  24. };
  25. struct Particle {
  26. crl::time birthTime = 0;
  27. crl::time deathTime = 0;
  28. float64 scale = 0.;
  29. float64 alpha = 0.;
  30. float64 relativeX = 0.; // Relative to a width.
  31. float64 relativeY = 0.; // Relative to a height.
  32. float64 velocityX = 0.;
  33. float64 velocityY = 0.;
  34. Type type;
  35. };
  36. void createParticle(crl::time now);
  37. [[nodiscard]] crl::time timeNow() const;
  38. [[nodiscard]] int randomInterval(
  39. const Interval &interval,
  40. const gsl::byte &random) const;
  41. const Interval _lifeLength;
  42. const Interval _deathTime;
  43. const Interval _scale;
  44. const Interval _velocity;
  45. const Interval _angle;
  46. const Interval _relativeX;
  47. const Interval _relativeY;
  48. const float64 _appearProgressTill;
  49. const float64 _disappearProgressAfter;
  50. const QMarginsF _dotMargins;
  51. const QMargins _renderMargins;
  52. Ui::Animations::Basic _animation;
  53. QImage _sprite;
  54. std::vector<Particle> _particles;
  55. crl::time _nextBirthTime = 0;
  56. struct {
  57. crl::time diff = 0;
  58. crl::time at = 0;
  59. } _paused;
  60. QBrush _brush;
  61. QRect _rectToUpdate;
  62. };
  63. } // namespace Ui