mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved out generation of credits menu icon from svg to td_ui.
This commit is contained in:
parent
2e0e4006a1
commit
9e0c731b32
3 changed files with 47 additions and 29 deletions
|
@ -46,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/admin_log/history_admin_log_section.h"
|
#include "history/admin_log/history_admin_log_section.h"
|
||||||
#include "info/bot/earn/info_bot_earn_widget.h"
|
#include "info/bot/earn/info_bot_earn_widget.h"
|
||||||
#include "info/channel_statistics/boosts/info_boosts_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/profile/info_profile_values.h"
|
||||||
#include "info/info_memento.h"
|
#include "info/info_memento.h"
|
||||||
#include "lang/lang_keys.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<Ui::RpWidget>(button);
|
const auto icon = Ui::CreateChild<Ui::RpWidget>(button);
|
||||||
icon->resize(Size(st::menuIconLinks.width() - kSizeShift));
|
const auto image = Ui::Earn::MenuIconCredits();
|
||||||
|
icon->resize(image.size() / style::DevicePixelRatio());
|
||||||
auto colorized = [&] {
|
icon->paintRequest() | rpl::start_with_next([=] {
|
||||||
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<QSvgRenderer>(
|
|
||||||
colorized.toUtf8());
|
|
||||||
svg->setViewBox(svg->viewBox() + Margins(kStrokeWidth));
|
|
||||||
|
|
||||||
const auto starSize = Size(icon->height());
|
|
||||||
|
|
||||||
icon->paintRequest(
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
auto p = QPainter(icon);
|
auto p = QPainter(icon);
|
||||||
svg->render(&p, Rect(starSize));
|
p.drawImage(0, 0, image);
|
||||||
}, icon->lifetime());
|
}, icon->lifetime());
|
||||||
|
|
||||||
button->sizeValue(
|
button->sizeValue(
|
||||||
) | rpl::start_with_next([=](const QSize &size) {
|
) | rpl::start_with_next([=](const QSize &size) {
|
||||||
icon->moveToLeft(
|
icon->moveToLeft(
|
||||||
button->st().iconLeft + kSizeShift / 2.,
|
button->st().iconLeft,
|
||||||
(size.height() - icon->height()) / 2);
|
(size.height() - icon->height()) / 2);
|
||||||
}, icon->lifetime());
|
}, icon->lifetime());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "info/channel_statistics/earn/earn_icons.h"
|
#include "info/channel_statistics/earn/earn_icons.h"
|
||||||
|
|
||||||
|
#include "ui/effects/premium_graphics.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
|
#include "styles/style_menu_icons.h"
|
||||||
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
#include <QtSvg/QSvgRenderer>
|
#include <QtSvg/QSvgRenderer>
|
||||||
|
|
||||||
namespace Ui::Earn {
|
namespace Ui::Earn {
|
||||||
|
@ -58,4 +62,39 @@ QImage IconCurrencyColored(
|
||||||
return image;
|
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
|
} // namespace Ui::Earn
|
||||||
|
|
|
@ -13,4 +13,6 @@ namespace Ui::Earn {
|
||||||
const style::font &font,
|
const style::font &font,
|
||||||
const QColor &c);
|
const QColor &c);
|
||||||
|
|
||||||
|
[[nodiscard]] QImage MenuIconCredits();
|
||||||
|
|
||||||
} // namespace Ui::Earn
|
} // namespace Ui::Earn
|
||||||
|
|
Loading…
Add table
Reference in a new issue