window_slide_animation.h 1.4 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 Window {
  10. enum class SlideDirection {
  11. FromRight,
  12. FromLeft,
  13. };
  14. class SlideAnimation {
  15. public:
  16. void paintContents(QPainter &p) const;
  17. [[nodiscard]] float64 progress() const;
  18. void setDirection(SlideDirection direction);
  19. void setPixmaps(
  20. const QPixmap &oldContentCache,
  21. const QPixmap &newContentCache);
  22. void setTopBarShadow(bool enabled);
  23. void setTopSkip(int skip);
  24. void setTopBarMask(const QPixmap &mask);
  25. void setWithFade(bool withFade);
  26. using RepaintCallback = Fn<void()>;
  27. void setRepaintCallback(RepaintCallback &&callback);
  28. using FinishedCallback = Fn<void()>;
  29. void setFinishedCallback(FinishedCallback &&callback);
  30. void start();
  31. static const anim::transition &transition() {
  32. return anim::easeOutCirc;
  33. }
  34. private:
  35. void animationCallback();
  36. SlideDirection _direction = SlideDirection::FromRight;
  37. int _topSkip = 0;
  38. bool _topBarShadowEnabled = false;
  39. bool _withFade = false;
  40. mutable Ui::Animations::Simple _animation;
  41. QPixmap _cacheUnder, _cacheOver;
  42. QPixmap _mask;
  43. RepaintCallback _repaintCallback;
  44. FinishedCallback _finishedCallback;
  45. };
  46. } // namespace Window