From d2ae2cf8f6ef6a1756367973464c3a9fe89872ce Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 13 Oct 2020 18:10:58 +0300 Subject: [PATCH] Allow RoundRect to have arbitrary radius. --- ui/image/image_prepare.cpp | 14 ++++++++++++++ ui/image/image_prepare.h | 6 ++++++ ui/round_rect.cpp | 11 +++++++++++ ui/round_rect.h | 1 + 4 files changed, 32 insertions(+) diff --git a/ui/image/image_prepare.cpp b/ui/image/image_prepare.cpp index d372b22..3e48444 100644 --- a/ui/image/image_prepare.cpp +++ b/ui/image/image_prepare.cpp @@ -97,6 +97,20 @@ std::array PrepareCorners( return result; } +std::array CornersMask(int radius) { + return PrepareCornersMask(radius); +} + +std::array PrepareCorners( + int radius, + const style::color &color) { + auto result = CornersMask(radius); + for (auto &image : result) { + style::colorizeImage(image, color->c, &image); + } + return result; +} + QImage prepareBlur(QImage img) { if (img.isNull()) { return img; diff --git a/ui/image/image_prepare.h b/ui/image/image_prepare.h index ddfe40a..60261b7 100644 --- a/ui/image/image_prepare.h +++ b/ui/image/image_prepare.h @@ -27,12 +27,18 @@ namespace Images { [[nodiscard]] QPixmap PixmapFast(QImage &&image); [[nodiscard]] QImage BlurLargeImage(QImage image, int radius); + [[nodiscard]] const std::array &CornersMask( ImageRoundRadius radius); [[nodiscard]] std::array PrepareCorners( ImageRoundRadius radius, const style::color &color); +[[nodiscard]] std::array CornersMask(int radius); +[[nodiscard]] std::array PrepareCorners( + int radius, + const style::color &color); + QImage prepareBlur(QImage image); void prepareRound( QImage &image, diff --git a/ui/round_rect.cpp b/ui/round_rect.cpp index 0af480b..eb42a51 100644 --- a/ui/round_rect.cpp +++ b/ui/round_rect.cpp @@ -74,6 +74,17 @@ RoundRect::RoundRect( }, _lifetime); } +RoundRect::RoundRect( + int radius, + const style::color &color) +: _color(color) +, _corners(Images::PrepareCorners(radius, color)) { + style::PaletteChanged( + ) | rpl::start_with_next([=] { + _corners = Images::PrepareCorners(radius, _color); + }, _lifetime); +} + const style::color &RoundRect::color() const { return _color; } diff --git a/ui/round_rect.h b/ui/round_rect.h index 4d65f4a..920c3dd 100644 --- a/ui/round_rect.h +++ b/ui/round_rect.h @@ -24,6 +24,7 @@ void DrawRoundedRect( class RoundRect final { public: RoundRect(ImageRoundRadius radius, const style::color &color); + RoundRect(int radius, const style::color &color); [[nodiscard]] const style::color &color() const; void paint(