mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added support of left edge to corner tail of bubble in premium box.
This commit is contained in:
parent
127bafa254
commit
cda4bca190
1 changed files with 46 additions and 7 deletions
|
@ -198,6 +198,7 @@ public:
|
||||||
|
|
||||||
void setCounter(int value);
|
void setCounter(int value);
|
||||||
void setTailEdge(EdgeProgress edge);
|
void setTailEdge(EdgeProgress edge);
|
||||||
|
void setFlipHorizontal(bool value);
|
||||||
void paintBubble(QPainter &p, const QRect &r, const QBrush &brush);
|
void paintBubble(QPainter &p, const QRect &r, const QBrush &brush);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<> widthChanges() const;
|
[[nodiscard]] rpl::producer<> widthChanges() const;
|
||||||
|
@ -219,6 +220,7 @@ private:
|
||||||
|
|
||||||
int _counter = -1;
|
int _counter = -1;
|
||||||
EdgeProgress _tailEdge = 0.;
|
EdgeProgress _tailEdge = 0.;
|
||||||
|
bool _flipHorizontal = false;
|
||||||
|
|
||||||
rpl::event_stream<> _widthChanges;
|
rpl::event_stream<> _widthChanges;
|
||||||
|
|
||||||
|
@ -291,6 +293,10 @@ void Bubble::setTailEdge(EdgeProgress edge) {
|
||||||
_tailEdge = std::clamp(edge, 0., 1.);
|
_tailEdge = std::clamp(edge, 0., 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bubble::setFlipHorizontal(bool value) {
|
||||||
|
_flipHorizontal = value;
|
||||||
|
}
|
||||||
|
|
||||||
void Bubble::paintBubble(QPainter &p, const QRect &r, const QBrush &brush) {
|
void Bubble::paintBubble(QPainter &p, const QRect &r, const QBrush &brush) {
|
||||||
if (_counter < 0) {
|
if (_counter < 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -346,7 +352,17 @@ void Bubble::paintBubble(QPainter &p, const QRect &r, const QBrush &brush) {
|
||||||
Qt::RoundCap,
|
Qt::RoundCap,
|
||||||
Qt::RoundJoin));
|
Qt::RoundJoin));
|
||||||
p.setBrush(brush);
|
p.setBrush(brush);
|
||||||
p.drawPath(pathTail + pathBubble);
|
if (_flipHorizontal) {
|
||||||
|
auto m = QTransform();
|
||||||
|
const auto center = bubbleRect.center();
|
||||||
|
m.translate(center.x(), center.y());
|
||||||
|
m.scale(-1., 1.);
|
||||||
|
m.translate(-center.x(), -center.y());
|
||||||
|
m.translate(-bubbleRect.left() + 1., 0);
|
||||||
|
p.drawPath(m.map(pathTail + pathBubble));
|
||||||
|
} else {
|
||||||
|
p.drawPath(pathTail + pathBubble);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p.setPen(st::activeButtonFg);
|
p.setPen(st::activeButtonFg);
|
||||||
p.setFont(_font);
|
p.setFont(_font);
|
||||||
|
@ -455,19 +471,40 @@ BubbleWidget::BubbleWidget(
|
||||||
- st::boxRowPadding.right()
|
- st::boxRowPadding.right()
|
||||||
- _maxBubbleWidth;
|
- _maxBubbleWidth;
|
||||||
};
|
};
|
||||||
const auto checkBubbleEdges = [&]() -> Bubble::EdgeProgress {
|
struct LeftEdge final {
|
||||||
|
float64 goodPointRatio = 0.;
|
||||||
|
float64 bubbleLeftEdge = 0.;
|
||||||
|
};
|
||||||
|
const auto leftEdge = [&]() -> LeftEdge {
|
||||||
|
const auto finish = computeLeft(moveEndPoint, 1.);
|
||||||
|
const auto &padding = st::boxRowPadding;
|
||||||
|
if (finish <= padding.left()) {
|
||||||
|
const auto halfWidth = (_maxBubbleWidth / 2);
|
||||||
|
const auto goodPointRatio = float64(halfWidth)
|
||||||
|
/ (parent->width() - padding.left() - padding.right());
|
||||||
|
const auto bubbleLeftEdge = (padding.left() - finish)
|
||||||
|
/ (_maxBubbleWidth / 2.);
|
||||||
|
return { goodPointRatio, bubbleLeftEdge };
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}();
|
||||||
|
const auto checkBubbleRightEdge = [&]() -> Bubble::EdgeProgress {
|
||||||
const auto finish = computeLeft(moveEndPoint, 1.);
|
const auto finish = computeLeft(moveEndPoint, 1.);
|
||||||
const auto edge = computeEdge();
|
const auto edge = computeEdge();
|
||||||
return (finish >= edge)
|
return (finish >= edge)
|
||||||
? (finish - edge) / (_maxBubbleWidth / 2.)
|
? (finish - edge) / (_maxBubbleWidth / 2.)
|
||||||
: 0.;
|
: 0.;
|
||||||
};
|
};
|
||||||
const auto bubbleEdge = checkBubbleEdges();
|
const auto bubbleRightEdge = checkBubbleRightEdge();
|
||||||
_ignoreDeflection = bubbleEdge;
|
_ignoreDeflection = bubbleRightEdge || leftEdge.goodPointRatio;
|
||||||
if (_ignoreDeflection) {
|
if (_ignoreDeflection) {
|
||||||
_stepBeforeDeflection = 1.;
|
_stepBeforeDeflection = 1.;
|
||||||
_stepAfterDeflection = 1.;
|
_stepAfterDeflection = 1.;
|
||||||
}
|
}
|
||||||
|
const auto resultMoveEndPoint = leftEdge.goodPointRatio
|
||||||
|
? leftEdge.goodPointRatio
|
||||||
|
: moveEndPoint;
|
||||||
|
_bubble.setFlipHorizontal(leftEdge.bubbleLeftEdge);
|
||||||
|
|
||||||
_appearanceAnimation.start([=](float64 value) {
|
_appearanceAnimation.start([=](float64 value) {
|
||||||
const auto moveProgress = std::clamp(
|
const auto moveProgress = std::clamp(
|
||||||
|
@ -479,8 +516,8 @@ BubbleWidget::BubbleWidget(
|
||||||
0.,
|
0.,
|
||||||
1.);
|
1.);
|
||||||
moveToLeft(
|
moveToLeft(
|
||||||
computeLeft(moveEndPoint, moveProgress)
|
computeLeft(resultMoveEndPoint, moveProgress)
|
||||||
- (_maxBubbleWidth / 2.) * bubbleEdge,
|
- (_maxBubbleWidth / 2.) * bubbleRightEdge,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
const auto counter = int(0 + counterProgress * _currentCounter);
|
const auto counter = int(0 + counterProgress * _currentCounter);
|
||||||
|
@ -488,7 +525,9 @@ BubbleWidget::BubbleWidget(
|
||||||
_bubble.setCounter(counter);
|
_bubble.setCounter(counter);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const auto edgeProgress = value * bubbleEdge;
|
const auto edgeProgress = (leftEdge.bubbleLeftEdge
|
||||||
|
? leftEdge.bubbleLeftEdge
|
||||||
|
: bubbleRightEdge) * value;
|
||||||
_bubble.setTailEdge(edgeProgress);
|
_bubble.setTailEdge(edgeProgress);
|
||||||
update();
|
update();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue