mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Support new rounding for comments button.
This commit is contained in:
parent
e5f2d83548
commit
09ab83836f
2 changed files with 80 additions and 24 deletions
|
@ -259,6 +259,7 @@ style::color FromNameFg(
|
||||||
|
|
||||||
struct Message::CommentsButton {
|
struct Message::CommentsButton {
|
||||||
std::unique_ptr<Ui::RippleAnimation> ripple;
|
std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||||
|
int rippleShift = 0;
|
||||||
std::vector<UserpicInRow> userpics;
|
std::vector<UserpicInRow> userpics;
|
||||||
QImage cachedUserpics;
|
QImage cachedUserpics;
|
||||||
ClickHandlerPtr link;
|
ClickHandlerPtr link;
|
||||||
|
@ -1004,7 +1005,12 @@ void Message::paintCommentsButton(
|
||||||
if (_comments->ripple) {
|
if (_comments->ripple) {
|
||||||
p.setOpacity(st::historyPollRippleOpacity);
|
p.setOpacity(st::historyPollRippleOpacity);
|
||||||
const auto colorOverride = &stm->msgWaveformInactive->c;
|
const auto colorOverride = &stm->msgWaveformInactive->c;
|
||||||
_comments->ripple->paint(p, left, top, width, colorOverride);
|
_comments->ripple->paint(
|
||||||
|
p,
|
||||||
|
left - _comments->rippleShift,
|
||||||
|
top,
|
||||||
|
width,
|
||||||
|
colorOverride);
|
||||||
if (_comments->ripple->empty()) {
|
if (_comments->ripple->empty()) {
|
||||||
_comments->ripple.reset();
|
_comments->ripple.reset();
|
||||||
}
|
}
|
||||||
|
@ -1439,30 +1445,8 @@ void Message::toggleCommentsButtonRipple(bool pressed) {
|
||||||
if (!drawBubble()) {
|
if (!drawBubble()) {
|
||||||
return;
|
return;
|
||||||
} else if (pressed) {
|
} else if (pressed) {
|
||||||
const auto g = countGeometry();
|
|
||||||
const auto linkWidth = g.width();
|
|
||||||
const auto linkHeight = st::historyCommentsButtonHeight;
|
|
||||||
if (!_comments->ripple) {
|
if (!_comments->ripple) {
|
||||||
const auto drawMask = [&](QPainter &p) {
|
createCommentsRipple();
|
||||||
// #TODO rounding
|
|
||||||
const auto radius = st::bubbleRadiusSmall;
|
|
||||||
p.drawRoundedRect(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
linkWidth,
|
|
||||||
linkHeight,
|
|
||||||
radius,
|
|
||||||
radius);
|
|
||||||
p.fillRect(0, 0, linkWidth, radius * 2, Qt::white);
|
|
||||||
};
|
|
||||||
auto mask = Ui::RippleAnimation::MaskByDrawer(
|
|
||||||
QSize(linkWidth, linkHeight),
|
|
||||||
false,
|
|
||||||
drawMask);
|
|
||||||
_comments->ripple = std::make_unique<Ui::RippleAnimation>(
|
|
||||||
st::defaultRippleAnimation,
|
|
||||||
std::move(mask),
|
|
||||||
[=] { repaint(); });
|
|
||||||
}
|
}
|
||||||
_comments->ripple->add(_comments->lastPoint);
|
_comments->ripple->add(_comments->lastPoint);
|
||||||
} else if (_comments->ripple) {
|
} else if (_comments->ripple) {
|
||||||
|
@ -1470,6 +1454,77 @@ void Message::toggleCommentsButtonRipple(bool pressed) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Message::createCommentsRipple() {
|
||||||
|
using namespace Ui;
|
||||||
|
using namespace Images;
|
||||||
|
using Radius = CachedCornerRadius;
|
||||||
|
using Corner = BubbleCornerRounding;
|
||||||
|
const auto g = countGeometry();
|
||||||
|
const auto linkWidth = g.width();
|
||||||
|
const auto linkHeight = st::historyCommentsButtonHeight;
|
||||||
|
const auto &large = CachedCornersMasks(Radius::BubbleLarge);
|
||||||
|
const auto &small = CachedCornersMasks(Radius::BubbleSmall);
|
||||||
|
const auto rounding = countBubbleRounding();
|
||||||
|
const auto icon = (rounding.bottomLeft == Corner::Tail)
|
||||||
|
? &st::historyBubbleTailInLeft
|
||||||
|
: (rounding.bottomRight == Corner::Tail)
|
||||||
|
? &st::historyBubbleTailInRight
|
||||||
|
: nullptr;
|
||||||
|
const auto shift = (rounding.bottomLeft == Corner::Tail)
|
||||||
|
? icon->width()
|
||||||
|
: 0;
|
||||||
|
const auto added = shift ? shift : icon ? icon->width() : 0;
|
||||||
|
auto corners = CornersMaskRef();
|
||||||
|
const auto set = [&](int index) {
|
||||||
|
corners.p[index] = (rounding[index] == Corner::Large)
|
||||||
|
? &large[index]
|
||||||
|
: (rounding[index] == Corner::Small)
|
||||||
|
? &small[index]
|
||||||
|
: nullptr;
|
||||||
|
};
|
||||||
|
set(kBottomLeft);
|
||||||
|
set(kBottomRight);
|
||||||
|
const auto drawer = [&](QPainter &p) {
|
||||||
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
|
const auto corner = [&](int index, bool right) {
|
||||||
|
if (const auto image = corners.p[index]) {
|
||||||
|
const auto width = image->width() / ratio;
|
||||||
|
const auto height = image->height() / ratio;
|
||||||
|
p.drawImage(
|
||||||
|
QRect(
|
||||||
|
shift + (right ? (linkWidth - width) : 0),
|
||||||
|
linkHeight - height,
|
||||||
|
width,
|
||||||
|
height),
|
||||||
|
*image);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
corner(kBottomLeft, false);
|
||||||
|
corner(kBottomRight, true);
|
||||||
|
if (icon) {
|
||||||
|
const auto left = shift ? 0 : linkWidth;
|
||||||
|
p.fillRect(
|
||||||
|
QRect{ left, 0, added, linkHeight },
|
||||||
|
Qt::transparent);
|
||||||
|
icon->paint(
|
||||||
|
p,
|
||||||
|
left,
|
||||||
|
linkHeight - icon->height(),
|
||||||
|
linkWidth + shift,
|
||||||
|
Qt::white);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
_comments->ripple = std::make_unique<RippleAnimation>(
|
||||||
|
st::defaultRippleAnimation,
|
||||||
|
RippleAnimation::MaskByDrawer(
|
||||||
|
QSize(linkWidth + added, linkHeight),
|
||||||
|
true,
|
||||||
|
drawer),
|
||||||
|
[=] { repaint(); });
|
||||||
|
_comments->rippleShift = shift;
|
||||||
|
}
|
||||||
|
|
||||||
bool Message::hasHeavyPart() const {
|
bool Message::hasHeavyPart() const {
|
||||||
return _comments
|
return _comments
|
||||||
|| (_fromNameStatus && _fromNameStatus->custom)
|
|| (_fromNameStatus && _fromNameStatus->custom)
|
||||||
|
|
|
@ -168,6 +168,7 @@ private:
|
||||||
TextSelection selection) const;
|
TextSelection selection) const;
|
||||||
|
|
||||||
void toggleCommentsButtonRipple(bool pressed);
|
void toggleCommentsButtonRipple(bool pressed);
|
||||||
|
void createCommentsRipple();
|
||||||
|
|
||||||
void paintCommentsButton(
|
void paintCommentsButton(
|
||||||
Painter &p,
|
Painter &p,
|
||||||
|
|
Loading…
Add table
Reference in a new issue