mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Added ministars to button in service messages for gifts.
This commit is contained in:
parent
a8a1b08127
commit
7f20cf59d1
6 changed files with 52 additions and 2 deletions
|
@ -151,6 +151,10 @@ rpl::producer<QString> PremiumGift::button() {
|
|||
: tr::lng_prize_open();
|
||||
}
|
||||
|
||||
bool PremiumGift::buttonMinistars() {
|
||||
return true;
|
||||
}
|
||||
|
||||
ClickHandlerPtr PremiumGift::createViewLink() {
|
||||
if (starGift() && outgoingGift()) {
|
||||
return nullptr;
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
QString title() override;
|
||||
TextWithEntities subtitle() override;
|
||||
rpl::producer<QString> button() override;
|
||||
bool buttonMinistars() override;
|
||||
QString cornerTagText() override;
|
||||
int buttonSkip() override;
|
||||
void draw(
|
||||
|
|
|
@ -16,9 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_keys.h"
|
||||
#include "ui/chat/chat_style.h"
|
||||
#include "ui/effects/animation_value.h"
|
||||
#include "ui/effects/premium_stars_colored.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/power_saving.h"
|
||||
#include "styles/style_chat.h"
|
||||
#include "styles/style_premium.h"
|
||||
|
@ -98,6 +100,12 @@ ServiceBox::ServiceBox(
|
|||
}
|
||||
}, _lifetime);
|
||||
}
|
||||
if (_content->buttonMinistars()) {
|
||||
_button.stars = std::make_unique<Ui::Premium::ColoredMiniStars>(
|
||||
[=](const QRect &) { repaint(); },
|
||||
Ui::Premium::MiniStars::Type::SlowStars);
|
||||
_button.lastFg = std::make_unique<QColor>();
|
||||
}
|
||||
}
|
||||
|
||||
ServiceBox::~ServiceBox() = default;
|
||||
|
@ -117,7 +125,21 @@ void ServiceBox::draw(Painter &p, const PaintContext &context) const {
|
|||
const auto radius = st::msgServiceGiftBoxRadius;
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(context.st->msgServiceBg());
|
||||
p.drawRoundedRect(QRect(QPoint(), _innerSize), radius, radius);
|
||||
p.drawRoundedRect(Rect(_innerSize), radius, radius);
|
||||
|
||||
if (_button.stars) {
|
||||
const auto &c = context.st->msgServiceFg()->c;
|
||||
if ((*_button.lastFg) != c) {
|
||||
_button.lastFg->setRgb(c.red(), c.green(), c.blue());
|
||||
const auto padding = _button.size.height() / 2;
|
||||
_button.stars->setColorOverride(QGradientStops{
|
||||
{ 0., anim::with_alpha(c, .3) },
|
||||
{ 1., c },
|
||||
});
|
||||
_button.stars->setCenter(
|
||||
Rect(_button.size) - QMargins(padding, 0, padding, 0));
|
||||
}
|
||||
}
|
||||
|
||||
const auto content = contentRect();
|
||||
auto top = content.top() + content.height();
|
||||
|
@ -340,7 +362,15 @@ bool ServiceBox::Button::empty() const {
|
|||
|
||||
void ServiceBox::Button::drawBg(QPainter &p) const {
|
||||
const auto radius = size.height() / 2.;
|
||||
p.drawRoundedRect(0, 0, size.width(), size.height(), radius, radius);
|
||||
const auto r = Rect(size);
|
||||
p.drawRoundedRect(r, radius, radius);
|
||||
if (stars) {
|
||||
auto clipPath = QPainterPath();
|
||||
clipPath.addRoundedRect(r, radius, radius);
|
||||
p.setClipPath(clipPath);
|
||||
stars->paint(p);
|
||||
p.setClipping(false);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -11,6 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace Ui {
|
||||
class RippleAnimation;
|
||||
namespace Premium {
|
||||
class ColoredMiniStars;
|
||||
} // namespace Premium
|
||||
} // namespace Ui
|
||||
|
||||
namespace HistoryView {
|
||||
|
@ -28,6 +31,9 @@ public:
|
|||
return top();
|
||||
}
|
||||
[[nodiscard]] virtual rpl::producer<QString> button() = 0;
|
||||
[[nodiscard]] virtual bool buttonMinistars() {
|
||||
return false;
|
||||
}
|
||||
[[nodiscard]] virtual QString cornerTagText() {
|
||||
return {};
|
||||
}
|
||||
|
@ -106,6 +112,8 @@ private:
|
|||
|
||||
ClickHandlerPtr link;
|
||||
std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||
std::unique_ptr<Ui::Premium::ColoredMiniStars> stars;
|
||||
std::unique_ptr<QColor> lastFg;
|
||||
|
||||
mutable QPoint lastPoint;
|
||||
} _button;
|
||||
|
|
|
@ -27,6 +27,12 @@ ColoredMiniStars::ColoredMiniStars(
|
|||
type) {
|
||||
}
|
||||
|
||||
ColoredMiniStars::ColoredMiniStars(
|
||||
Fn<void(const QRect &)> update,
|
||||
MiniStars::Type type)
|
||||
: _ministars(update, true, type) {
|
||||
}
|
||||
|
||||
void ColoredMiniStars::setSize(const QSize &size) {
|
||||
_frame = QImage(
|
||||
size * style::DevicePixelRatio(),
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
not_null<Ui::RpWidget*> parent,
|
||||
bool optimizeUpdate,
|
||||
MiniStars::Type type = MiniStars::Type::MonoStars);
|
||||
ColoredMiniStars(Fn<void(const QRect &)> update, MiniStars::Type type);
|
||||
|
||||
void setSize(const QSize &size);
|
||||
void setPosition(QPoint position);
|
||||
|
|
Loading…
Add table
Reference in a new issue