Allow querying slide animation state.
This commit is contained in:
parent
f7c3e22cc9
commit
7ed6610511
2 changed files with 33 additions and 16 deletions
|
|
@ -23,29 +23,23 @@ void SlideAnimation::setSnapshots(
|
|||
}
|
||||
|
||||
void SlideAnimation::paintFrame(QPainter &p, int x, int y, int outerWidth) {
|
||||
const auto dt = _animation.value(1.);
|
||||
if (!animating()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto pixelRatio = style::DevicePixelRatio();
|
||||
const auto easeOut = anim::easeOutCirc(1., dt);
|
||||
const auto easeIn = anim::easeInCirc(1., dt);
|
||||
const auto arrivingAlpha = easeIn;
|
||||
const auto departingAlpha = 1. - easeOut;
|
||||
const auto state = this->state();
|
||||
const auto leftCoord = _slideLeft
|
||||
? anim::interpolate(-_leftSnapshotWidth, 0, easeOut)
|
||||
: anim::interpolate(0, -_leftSnapshotWidth, easeIn);
|
||||
const auto leftAlpha = (_slideLeft ? arrivingAlpha : departingAlpha);
|
||||
? anim::interpolate(-_leftSnapshotWidth, 0, state.leftProgress)
|
||||
: anim::interpolate(0, -_leftSnapshotWidth, state.leftProgress);
|
||||
const auto rightCoord = _slideLeft
|
||||
? anim::interpolate(0, _rightSnapshotWidth, easeIn)
|
||||
: anim::interpolate(_rightSnapshotWidth, 0, easeOut);
|
||||
const auto rightAlpha = (_slideLeft ? departingAlpha : arrivingAlpha);
|
||||
? anim::interpolate(0, _rightSnapshotWidth, state.rightProgress)
|
||||
: anim::interpolate(_rightSnapshotWidth, 0, state.rightProgress);
|
||||
|
||||
if (_overflowHidden) {
|
||||
const auto leftWidth = (_leftSnapshotWidth + leftCoord);
|
||||
if (leftWidth > 0) {
|
||||
p.setOpacity(leftAlpha);
|
||||
p.setOpacity(state.leftAlpha);
|
||||
p.drawPixmap(
|
||||
x,
|
||||
y,
|
||||
|
|
@ -59,7 +53,7 @@ void SlideAnimation::paintFrame(QPainter &p, int x, int y, int outerWidth) {
|
|||
}
|
||||
const auto rightWidth = _rightSnapshotWidth - rightCoord;
|
||||
if (rightWidth > 0) {
|
||||
p.setOpacity(rightAlpha);
|
||||
p.setOpacity(state.rightAlpha);
|
||||
p.drawPixmap(
|
||||
x + rightCoord,
|
||||
y,
|
||||
|
|
@ -70,11 +64,26 @@ void SlideAnimation::paintFrame(QPainter &p, int x, int y, int outerWidth) {
|
|||
_rightSnapshot.height());
|
||||
}
|
||||
} else {
|
||||
p.setOpacity(leftAlpha);
|
||||
p.setOpacity(state.leftAlpha);
|
||||
p.drawPixmap(x + leftCoord, y, _leftSnapshot);
|
||||
p.setOpacity(rightAlpha);
|
||||
p.setOpacity(state.rightAlpha);
|
||||
p.drawPixmap(x + rightCoord, y, _rightSnapshot);
|
||||
}
|
||||
}
|
||||
|
||||
SlideAnimation::State SlideAnimation::state() const {
|
||||
const auto dt = _animation.value(1.);
|
||||
const auto easeOut = anim::easeOutCirc(1., dt);
|
||||
const auto easeIn = anim::easeInCirc(1., dt);
|
||||
const auto arrivingAlpha = easeIn;
|
||||
const auto departingAlpha = 1. - easeOut;
|
||||
|
||||
auto result = State();
|
||||
result.leftProgress = _slideLeft ? easeOut : easeIn;
|
||||
result.leftAlpha = _slideLeft ? arrivingAlpha : departingAlpha;
|
||||
result.rightProgress = _slideLeft ? easeIn : easeOut;
|
||||
result.rightAlpha = _slideLeft ? departingAlpha : arrivingAlpha;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
|||
|
|
@ -12,6 +12,13 @@ namespace Ui {
|
|||
|
||||
class SlideAnimation {
|
||||
public:
|
||||
struct State {
|
||||
float64 leftProgress = 0.;
|
||||
float64 leftAlpha = 0.;
|
||||
float64 rightProgress = 0.;
|
||||
float64 rightAlpha = 0.;
|
||||
};
|
||||
|
||||
void setSnapshots(QPixmap leftSnapshot, QPixmap rightSnapshot);
|
||||
|
||||
void setOverflowHidden(bool hidden) {
|
||||
|
|
@ -23,7 +30,8 @@ public:
|
|||
|
||||
void paintFrame(QPainter &p, int x, int y, int outerWidth);
|
||||
|
||||
bool animating() const {
|
||||
[[nodiscard]] State state() const;
|
||||
[[nodiscard]] bool animating() const {
|
||||
return _animation.animating();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue