premium_stars.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include <QSvgRenderer>
  10. namespace Ui {
  11. namespace Premium {
  12. class MiniStars final {
  13. public:
  14. enum class Type {
  15. MonoStars,
  16. BiStars,
  17. SlowStars,
  18. };
  19. MiniStars(
  20. Fn<void(const QRect &r)> updateCallback,
  21. bool opaque = false,
  22. Type type = Type::MonoStars);
  23. void paint(QPainter &p, const QRectF &rect);
  24. void setPaused(bool paused);
  25. static constexpr auto kSizeFactor = 1.5;
  26. private:
  27. struct MiniStar {
  28. crl::time birthTime = 0;
  29. crl::time deathTime = 0;
  30. int angle = 0;
  31. float64 size = 0.;
  32. float64 alpha = 0.;
  33. float64 sinFactor = 0.;
  34. not_null<QSvgRenderer*> sprite;
  35. };
  36. struct Interval {
  37. int from = 0;
  38. int length = 0;
  39. };
  40. void createStar(crl::time now);
  41. [[nodiscard]] crl::time timeNow() const;
  42. [[nodiscard]] int randomInterval(
  43. const Interval &interval,
  44. const gsl::byte &random) const;
  45. const std::vector<Interval> _availableAngles;
  46. const Interval _lifeLength;
  47. const Interval _deathTime;
  48. const Interval _size;
  49. const Interval _alpha;
  50. const Interval _sinFactor;
  51. const Interval _spritesCount;
  52. const float64 _appearProgressTill;
  53. const float64 _disappearProgressAfter;
  54. const float64 _distanceProgressStart;
  55. QSvgRenderer _sprite;
  56. std::unique_ptr<QSvgRenderer> _secondSprite;
  57. Ui::Animations::Basic _animation;
  58. std::vector<MiniStar> _ministars;
  59. crl::time _nextBirthTime = 0;
  60. bool _paused = false;
  61. QRect _rectToUpdate;
  62. };
  63. } // namespace Premium
  64. } // namespace Ui