mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Improved round corners of emoji on userpic preview in builder.
This commit is contained in:
parent
5558ac22f5
commit
322cbc5ed0
2 changed files with 42 additions and 12 deletions
|
@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_account.h"
|
#include "main/main_account.h"
|
||||||
#include "main/main_app_config.h"
|
#include "main/main_app_config.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 {
|
||||||
|
@ -23,7 +24,27 @@ namespace UserpicBuilder {
|
||||||
PreviewPainter::PreviewPainter(int size)
|
PreviewPainter::PreviewPainter(int size)
|
||||||
: _size(size)
|
: _size(size)
|
||||||
, _emojiSize(base::SafeRound(_size / M_SQRT2))
|
, _emojiSize(base::SafeRound(_size / M_SQRT2))
|
||||||
, _frameRect(Rect(Size(_size)) - Margins((_size - _emojiSize) / 2)) {
|
, _frameGeometry(Rect(Size(_size)) - Margins((_size - _emojiSize) / 2))
|
||||||
|
, _frameRect(Rect(_frameGeometry.size()))
|
||||||
|
, _mask(
|
||||||
|
_frameRect.size() * style::DevicePixelRatio(),
|
||||||
|
QImage::Format_ARGB32_Premultiplied)
|
||||||
|
, _frame(_mask.size(), QImage::Format_ARGB32_Premultiplied) {
|
||||||
|
_frame.setDevicePixelRatio(style::DevicePixelRatio());
|
||||||
|
_mask.setDevicePixelRatio(style::DevicePixelRatio());
|
||||||
|
_mask.fill(Qt::transparent);
|
||||||
|
{
|
||||||
|
auto p = QPainter(&_mask);
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
p.setBrush(st::windowBg);
|
||||||
|
constexpr auto kFrameRadiusPercent = 25;
|
||||||
|
p.drawRoundedRect(
|
||||||
|
_frameRect,
|
||||||
|
kFrameRadiusPercent,
|
||||||
|
kFrameRadiusPercent,
|
||||||
|
Qt::RelativeSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<DocumentData*> PreviewPainter::document() const {
|
not_null<DocumentData*> PreviewPainter::document() const {
|
||||||
|
@ -115,18 +136,23 @@ bool PreviewPainter::paintForeground(QPainter &p) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.image = Images::Round(
|
_frame.fill(Qt::transparent);
|
||||||
base::take(frame.image),
|
{
|
||||||
ImageRoundRadius::Large);
|
QPainter q(&_frame);
|
||||||
if (frame.image.width() == frame.image.height()) {
|
if (frame.image.width() == frame.image.height()) {
|
||||||
p.drawImage(_frameRect, frame.image);
|
q.drawImage(_frameRect, frame.image);
|
||||||
} else {
|
} else {
|
||||||
auto frameRect = Rect(frame.image.size().scaled(
|
auto frameRect = Rect(frame.image.size().scaled(
|
||||||
_frameRect.size(),
|
_frameRect.size(),
|
||||||
Qt::KeepAspectRatio));
|
Qt::KeepAspectRatio));
|
||||||
frameRect.moveCenter(_frameRect.center());
|
frameRect.moveCenter(_frameRect.center());
|
||||||
p.drawImage(frameRect, frame.image);
|
q.drawImage(frameRect, frame.image);
|
||||||
|
}
|
||||||
|
q.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||||
|
q.drawImage(0, 0, _mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.drawImage(_frameGeometry.topLeft(), _frame);
|
||||||
if (!_paused) {
|
if (!_paused) {
|
||||||
_player->markFrameShown();
|
_player->markFrameShown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,12 @@ public:
|
||||||
private:
|
private:
|
||||||
const int _size;
|
const int _size;
|
||||||
const int _emojiSize;
|
const int _emojiSize;
|
||||||
|
const QRect _frameGeometry;
|
||||||
const QRect _frameRect;
|
const QRect _frameRect;
|
||||||
|
|
||||||
|
QImage _mask;
|
||||||
|
QImage _frame;
|
||||||
|
|
||||||
std::shared_ptr<Data::DocumentMedia> _media;
|
std::shared_ptr<Data::DocumentMedia> _media;
|
||||||
std::unique_ptr<HistoryView::StickerPlayer> _player;
|
std::unique_ptr<HistoryView::StickerPlayer> _player;
|
||||||
bool _playOnce = false;
|
bool _playOnce = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue