Replaced gradient stops with gradient colors in EmojiUserpic of builder.
This commit is contained in:
parent
2f7e4ae8fb
commit
cae97cb062
|
@ -12,8 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_document_media.h"
|
#include "data/data_document_media.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "history/view/media/history_view_sticker_player.h"
|
#include "history/view/media/history_view_sticker_player.h"
|
||||||
|
#include "info/userpic/info_userpic_emoji_builder_common.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "ui/painter.h"
|
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
|
|
||||||
namespace UserpicBuilder {
|
namespace UserpicBuilder {
|
||||||
|
@ -78,11 +78,8 @@ void PreviewPainter::setDocument(
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewPainter::paintBackground(QPainter &p, const QBrush &brush) {
|
void PreviewPainter::paintBackground(QPainter &p, const QImage &image) {
|
||||||
PainterHighQualityEnabler hq(p);
|
p.drawImage(0, 0, image);
|
||||||
p.setPen(Qt::NoPen);
|
|
||||||
p.setBrush(brush);
|
|
||||||
p.drawEllipse(0, 0, _size, _size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PreviewPainter::paintForeground(QPainter &p) {
|
bool PreviewPainter::paintForeground(QPainter &p) {
|
||||||
|
@ -126,15 +123,10 @@ void EmojiUserpic::setDocument(not_null<DocumentData*> document) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmojiUserpic::result(int size, Fn<void(QImage &&image)> done) {
|
void EmojiUserpic::result(int size, Fn<void(QImage &&image)> done) {
|
||||||
const auto colors = ranges::views::all(
|
|
||||||
_stops
|
|
||||||
) | ranges::views::transform([](const QGradientStop &stop) {
|
|
||||||
return stop.second;
|
|
||||||
}) | ranges::to_vector;
|
|
||||||
const auto painter = lifetime().make_state<PreviewPainter>(size);
|
const auto painter = lifetime().make_state<PreviewPainter>(size);
|
||||||
// Reset to the first frame.
|
// Reset to the first frame.
|
||||||
painter->setDocument(_painter.document(), [=] {
|
painter->setDocument(_painter.document(), [=] {
|
||||||
auto background = Images::GenerateLinearGradient(Size(size), colors);
|
auto background = GenerateGradient(Size(size), _colors, false);
|
||||||
|
|
||||||
auto p = QPainter(&background);
|
auto p = QPainter(&background);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -146,20 +138,16 @@ void EmojiUserpic::result(int size, Fn<void(QImage &&image)> done) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmojiUserpic::setGradientStops(QGradientStops stops) {
|
void EmojiUserpic::setGradientColors(std::vector<QColor> colors) {
|
||||||
if (_stops == stops) {
|
if (_colors == colors) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!_stops.empty()) {
|
if (const auto colors = base::take(_colors); !colors.empty()) {
|
||||||
auto gradient = QLinearGradient(0, 0, width() / 2., height());
|
_previousImage = GenerateGradient(size(), colors);
|
||||||
gradient.setStops(base::take(_stops));
|
|
||||||
_previousBrush = QBrush(std::move(gradient));
|
|
||||||
}
|
}
|
||||||
_stops = std::move(stops);
|
_colors = std::move(colors);
|
||||||
{
|
{
|
||||||
auto gradient = QLinearGradient(0, 0, width() / 2., height());
|
_image = GenerateGradient(size(), _colors);
|
||||||
gradient.setStops(_stops);
|
|
||||||
_brush = QBrush(std::move(gradient));
|
|
||||||
}
|
}
|
||||||
if (_duration) {
|
if (_duration) {
|
||||||
_animation.stop();
|
_animation.stop();
|
||||||
|
@ -172,13 +160,13 @@ void EmojiUserpic::setGradientStops(QGradientStops stops) {
|
||||||
void EmojiUserpic::paintEvent(QPaintEvent *event) {
|
void EmojiUserpic::paintEvent(QPaintEvent *event) {
|
||||||
auto p = QPainter(this);
|
auto p = QPainter(this);
|
||||||
|
|
||||||
if (_animation.animating() && (_previousBrush != Qt::NoBrush)) {
|
if (_animation.animating() && !_previousImage.isNull()) {
|
||||||
_painter.paintBackground(p, _previousBrush);
|
_painter.paintBackground(p, _previousImage);
|
||||||
|
|
||||||
p.setOpacity(_animation.value(1.));
|
p.setOpacity(_animation.value(1.));
|
||||||
}
|
}
|
||||||
|
|
||||||
_painter.paintBackground(p, _brush);
|
_painter.paintBackground(p, _image);
|
||||||
|
|
||||||
p.setOpacity(1.);
|
p.setOpacity(1.);
|
||||||
_painter.paintForeground(p);
|
_painter.paintForeground(p);
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
Fn<void()> updateCallback);
|
Fn<void()> updateCallback);
|
||||||
|
|
||||||
void paintBackground(QPainter &p, const QBrush &brush);
|
void paintBackground(QPainter &p, const QImage &image);
|
||||||
bool paintForeground(QPainter &p);
|
bool paintForeground(QPainter &p);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
EmojiUserpic(not_null<Ui::RpWidget*> parent, const QSize &size);
|
EmojiUserpic(not_null<Ui::RpWidget*> parent, const QSize &size);
|
||||||
|
|
||||||
void result(int size, Fn<void(QImage &&image)> done);
|
void result(int size, Fn<void(QImage &&image)> done);
|
||||||
void setGradientStops(QGradientStops stops);
|
void setGradientColors(std::vector<QColor> colors);
|
||||||
void setDocument(not_null<DocumentData*> document);
|
void setDocument(not_null<DocumentData*> document);
|
||||||
void setDuration(crl::time duration);
|
void setDuration(crl::time duration);
|
||||||
|
|
||||||
|
@ -63,9 +63,9 @@ protected:
|
||||||
private:
|
private:
|
||||||
PreviewPainter _painter;
|
PreviewPainter _painter;
|
||||||
|
|
||||||
QBrush _previousBrush;
|
QImage _previousImage;
|
||||||
QBrush _brush;
|
QImage _image;
|
||||||
QGradientStops _stops;
|
std::vector<QColor> _colors;
|
||||||
|
|
||||||
crl::time _duration;
|
crl::time _duration;
|
||||||
Ui::Animations::Simple _animation;
|
Ui::Animations::Simple _animation;
|
||||||
|
|
|
@ -277,7 +277,12 @@ not_null<Ui::VerticalLayout*> CreateUserpicBuilder(
|
||||||
data.builderColorIndex);
|
data.builderColorIndex);
|
||||||
palette->stopsValue(
|
palette->stopsValue(
|
||||||
) | rpl::start_with_next([=](QGradientStops stops) {
|
) | rpl::start_with_next([=](QGradientStops stops) {
|
||||||
preview->setGradientStops(std::move(stops));
|
const auto colors = ranges::views::all(
|
||||||
|
stops
|
||||||
|
) | ranges::views::transform([](const QGradientStop &stop) {
|
||||||
|
return stop.second;
|
||||||
|
}) | ranges::to_vector;
|
||||||
|
preview->setGradientColors(colors);
|
||||||
}, preview->lifetime());
|
}, preview->lifetime());
|
||||||
paletteBg->innerRectValue(
|
paletteBg->innerRectValue(
|
||||||
) | rpl::start_with_next([=](const QRect &r) {
|
) | rpl::start_with_next([=](const QRect &r) {
|
||||||
|
@ -339,7 +344,7 @@ not_null<Ui::RpWidget*> CreateEmojiUserpic(
|
||||||
) | rpl::start_with_next([=](int index) {
|
) | rpl::start_with_next([=](int index) {
|
||||||
const auto c = Ui::EmptyUserpic::UserpicColor(
|
const auto c = Ui::EmptyUserpic::UserpicColor(
|
||||||
Ui::EmptyUserpic::ColorIndex(index));
|
Ui::EmptyUserpic::ColorIndex(index));
|
||||||
widget->setGradientStops({ { 0, c.color1->c }, { 1, c.color2->c } });
|
widget->setGradientColors({ c.color1->c, c.color2->c });
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue