From 9e0c731b32a4eed70038e1d68c71d3847814ca2e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 27 Oct 2024 11:25:53 +0300 Subject: [PATCH] Moved out generation of credits menu icon from svg to td_ui. --- .../boxes/peers/edit_peer_info_box.cpp | 35 +++-------------- .../channel_statistics/earn/earn_icons.cpp | 39 +++++++++++++++++++ .../info/channel_statistics/earn/earn_icons.h | 2 + 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 4b11e3745..a9b892ae6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -46,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/admin_log/history_admin_log_section.h" #include "info/bot/earn/info_bot_earn_widget.h" #include "info/channel_statistics/boosts/info_boosts_widget.h" +#include "info/channel_statistics/earn/earn_icons.h" #include "info/profile/info_profile_values.h" #include "info/info_memento.h" #include "lang/lang_keys.h" @@ -1622,42 +1623,18 @@ void Controller::fillBotBalanceButton() { }); } { - constexpr auto kSizeShift = 3; - constexpr auto kStrokeWidth = 5; - const auto icon = Ui::CreateChild(button); - icon->resize(Size(st::menuIconLinks.width() - kSizeShift)); - - auto colorized = [&] { - auto f = QFile(Ui::Premium::Svg()); - if (!f.open(QIODevice::ReadOnly)) { - return QString(); - } - return QString::fromUtf8( - f.readAll()).replace(u"#fff"_q, u"#ffffff00"_q); - }(); - colorized.replace( - u"stroke=\"none\""_q, - u"stroke=\"%1\""_q.arg(st::menuIconColor->c.name())); - colorized.replace( - u"stroke-width=\"1\""_q, - u"stroke-width=\"%1\""_q.arg(kStrokeWidth)); - const auto svg = icon->lifetime().make_state( - colorized.toUtf8()); - svg->setViewBox(svg->viewBox() + Margins(kStrokeWidth)); - - const auto starSize = Size(icon->height()); - - icon->paintRequest( - ) | rpl::start_with_next([=] { + const auto image = Ui::Earn::MenuIconCredits(); + icon->resize(image.size() / style::DevicePixelRatio()); + icon->paintRequest() | rpl::start_with_next([=] { auto p = QPainter(icon); - svg->render(&p, Rect(starSize)); + p.drawImage(0, 0, image); }, icon->lifetime()); button->sizeValue( ) | rpl::start_with_next([=](const QSize &size) { icon->moveToLeft( - button->st().iconLeft + kSizeShift / 2., + button->st().iconLeft, (size.height() - icon->height()) / 2); }, icon->lifetime()); } diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp index 47616dff4..cc32bf31f 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp @@ -7,8 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/channel_statistics/earn/earn_icons.h" +#include "ui/effects/premium_graphics.h" #include "ui/rect.h" +#include "styles/style_menu_icons.h" +#include "styles/style_widgets.h" +#include #include namespace Ui::Earn { @@ -58,4 +62,39 @@ QImage IconCurrencyColored( return image; } +QImage MenuIconCredits() { + constexpr auto kStrokeWidth = 5; + const auto sizeShift = st::lineWidth * 1.5; + + auto colorized = [&] { + auto f = QFile(Ui::Premium::Svg()); + if (!f.open(QIODevice::ReadOnly)) { + return QString(); + } + return QString::fromUtf8(f.readAll()).replace( + u"#fff"_q, + u"#ffffff00"_q); + }(); + colorized.replace( + u"stroke=\"none\""_q, + u"stroke=\"%1\""_q.arg(st::menuIconColor->c.name())); + colorized.replace( + u"stroke-width=\"1\""_q, + u"stroke-width=\"%1\""_q.arg(kStrokeWidth)); + auto svg = QSvgRenderer(colorized.toUtf8()); + svg.setViewBox(svg.viewBox() + + Margins(style::ConvertScale(kStrokeWidth))); + + auto image = QImage( + st::menuIconLinks.size() * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + image.setDevicePixelRatio(style::DevicePixelRatio()); + image.fill(Qt::transparent); + { + auto p = QPainter(&image); + svg.render(&p, Rect(st::menuIconLinks.size()) - Margins(sizeShift)); + } + return image; +} + } // namespace Ui::Earn diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h index e7f7f7d34..72817de9d 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h +++ b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h @@ -13,4 +13,6 @@ namespace Ui::Earn { const style::font &font, const QColor &c); +[[nodiscard]] QImage MenuIconCredits(); + } // namespace Ui::Earn