round_area_with_shadow.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. namespace Ui {
  9. struct ImageSubrect {
  10. not_null<QImage*> image;
  11. QRect rect;
  12. };
  13. class RoundAreaWithShadow final {
  14. public:
  15. static constexpr auto kFramesCount = 32;
  16. [[nodiscard]] static QImage PrepareImage(QSize size);
  17. [[nodiscard]] static QImage PrepareFramesCache(
  18. QSize frame,
  19. int columns = 1);
  20. [[nodiscard]] static QRect FrameCacheRect(
  21. int frameIndex,
  22. int column,
  23. QSize frame);
  24. // Returns center area which could be just filled with a solid color.
  25. static QRect FillWithImage(
  26. QPainter &p,
  27. QRect geometry,
  28. const ImageSubrect &pattern);
  29. RoundAreaWithShadow(QSize inner, QMargins shadow, int twiceRadiusMax);
  30. void setBackgroundColor(const QColor &background);
  31. void setShadowColor(const QColor &shadow);
  32. [[nodiscard]] ImageSubrect validateFrame(
  33. int frameIndex,
  34. float64 scale,
  35. float64 radius);
  36. [[nodiscard]] ImageSubrect validateOverlayMask(
  37. int frameIndex,
  38. QSize innerSize,
  39. float64 radius,
  40. int twiceRadius,
  41. float64 scale);
  42. [[nodiscard]] ImageSubrect validateOverlayShadow(
  43. int frameIndex,
  44. QSize innerSize,
  45. float64 radius,
  46. int twiceRadius,
  47. float64 scale,
  48. const ImageSubrect &mask);
  49. void overlayExpandedBorder(
  50. QPainter &p,
  51. QSize size,
  52. float64 expandRatio,
  53. float64 radiusFrom,
  54. float64 radiusTill,
  55. float64 scale);
  56. private:
  57. [[nodiscard]] QRect validateShadow(
  58. int frameIndex,
  59. float64 scale,
  60. float64 radius);
  61. QRect _inner;
  62. QSize _outer;
  63. QSize _overlay;
  64. std::array<bool, kFramesCount> _validBg = { { false } };
  65. std::array<bool, kFramesCount> _validShadow = { { false } };
  66. std::array<bool, kFramesCount> _validOverlayMask = { { false } };
  67. std::array<bool, kFramesCount> _validOverlayShadow = { { false } };
  68. QColor _background;
  69. QColor _gradient;
  70. QColor _shadow;
  71. QImage _cacheBg;
  72. QImage _shadowParts;
  73. QImage _overlayCacheParts;
  74. QImage _overlayMaskScaled;
  75. QImage _overlayShadowScaled;
  76. QImage _shadowBuffer;
  77. };
  78. } // namespace Ui