ripple_animation.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include <deque>
  9. namespace Images {
  10. struct CornersMaskRef;
  11. } // namespace Images
  12. namespace style {
  13. struct RippleAnimation;
  14. } // namespace style
  15. namespace Ui {
  16. class RippleAnimation {
  17. public:
  18. // White upon transparent mask,
  19. // like colorizeImage(black-white-mask, white).
  20. RippleAnimation(
  21. const style::RippleAnimation &st,
  22. QImage mask,
  23. Fn<void()> update);
  24. void add(QPoint origin, int startRadius = 0);
  25. void addFading();
  26. void lastStop();
  27. void lastUnstop();
  28. void lastFinish();
  29. void forceRepaint();
  30. void paint(
  31. QPainter &p,
  32. int x,
  33. int y,
  34. int outerWidth,
  35. const QColor *colorOverride = nullptr);
  36. bool empty() const {
  37. return _ripples.empty();
  38. }
  39. static QImage MaskByDrawer(
  40. QSize size,
  41. bool filled,
  42. Fn<void(QPainter &p)> drawer);
  43. static QImage RectMask(QSize size);
  44. static QImage RoundRectMask(QSize size, int radius);
  45. static QImage RoundRectMask(QSize size, Images::CornersMaskRef corners);
  46. static QImage EllipseMask(QSize size);
  47. ~RippleAnimation();
  48. private:
  49. void clear();
  50. void clearFinished();
  51. const style::RippleAnimation &_st;
  52. QPixmap _mask;
  53. Fn<void()> _update;
  54. class Ripple;
  55. std::deque<std::unique_ptr<Ripple>> _ripples;
  56. };
  57. } // namespace Ui