path_shift_gradient.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "ui/style/style_core_types.h"
  9. #include <QtGui/QLinearGradient>
  10. namespace Ui {
  11. class PathShiftGradient final {
  12. public:
  13. PathShiftGradient(
  14. const style::color &bg,
  15. const style::color &fg,
  16. Fn<void()> animationCallback,
  17. rpl::producer<> paletteUpdated = nullptr);
  18. ~PathShiftGradient();
  19. void startFrame(
  20. int viewportLeft,
  21. int viewportWidth,
  22. int gradientWidth);
  23. void overrideColors(const style::color &bg, const style::color &fg);
  24. void clearOverridenColors();
  25. using Background = std::variant<QLinearGradient*, style::color>;
  26. bool paint(Fn<bool(const Background&)> painter);
  27. private:
  28. struct AnimationData;
  29. void refreshColors();
  30. void refreshColors(const style::color &bg, const style::color &fg);
  31. void updateGeometry();
  32. void activateAnimation();
  33. static std::weak_ptr<AnimationData> Animation;
  34. const style::color &_bg;
  35. const style::color &_fg;
  36. const style::color *_bgOverride = nullptr;
  37. QLinearGradient _gradient;
  38. std::shared_ptr<AnimationData> _animation;
  39. const Fn<void()> _animationCallback;
  40. int _viewportLeft = 0;
  41. int _viewportWidth = 0;
  42. int _gradientWidth = 0;
  43. int _gradientStart = 0;
  44. int _gradientFinalStop = 0;
  45. bool _gradientEnabled = false;
  46. bool _geometryUpdated = false;
  47. bool _animationActive = false;
  48. bool _colorsOverriden = false;
  49. rpl::lifetime _lifetime;
  50. };
  51. } // namespace Ui