mirror of
https://github.com/Qz3rK/tdesktop.git
synced 2026-07-03 14:15:08 +02:00
Add new animations engine.
This commit is contained in:
@@ -542,19 +542,18 @@ void LeftOutlineButton::paintEvent(QPaintEvent *e) {
|
||||
|
||||
CrossButton::CrossButton(QWidget *parent, const style::CrossButton &st) : RippleButton(parent, st.ripple)
|
||||
, _st(st)
|
||||
, _a_loading(animation(this, &CrossButton::step_loading)) {
|
||||
, _a_loading([=](crl::time duration) { return loadingCallback(duration); }) {
|
||||
resize(_st.width, _st.height);
|
||||
setCursor(style::cur_pointer);
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
void CrossButton::step_loading(crl::time ms, bool timer) {
|
||||
if (stopLoadingAnimation(ms)) {
|
||||
_a_loading.stop();
|
||||
update();
|
||||
} else if (timer && !anim::Disabled()) {
|
||||
bool CrossButton::loadingCallback(crl::time duration) {
|
||||
const auto result = !stopLoadingAnimation(duration);
|
||||
if (!result || !anim::Disabled()) {
|
||||
update();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CrossButton::toggle(bool visible, anim::type animated) {
|
||||
@@ -565,7 +564,7 @@ void CrossButton::toggle(bool visible, anim::type animated) {
|
||||
setVisible(true);
|
||||
}
|
||||
_a_show.start(
|
||||
[this] { animationCallback(); },
|
||||
[=] { animationCallback(); },
|
||||
_shown ? 0. : 1.,
|
||||
_shown ? 1. : 0.,
|
||||
_st.duration);
|
||||
@@ -588,14 +587,15 @@ void CrossButton::paintEvent(QPaintEvent *e) {
|
||||
|
||||
auto ms = crl::now();
|
||||
auto over = isOver();
|
||||
auto shown = _a_show.current(ms, _shown ? 1. : 0.);
|
||||
auto shown = _a_show.value(_shown ? 1. : 0.);
|
||||
p.setOpacity(shown);
|
||||
|
||||
paintRipple(p, _st.crossPosition.x(), _st.crossPosition.y(), ms);
|
||||
|
||||
auto loading = 0.;
|
||||
if (_a_loading.animating()) {
|
||||
if (stopLoadingAnimation(ms)) {
|
||||
const auto duration = (ms - _loadingStartMs);
|
||||
if (stopLoadingAnimation(duration)) {
|
||||
_a_loading.stop();
|
||||
} else if (anim::Disabled()) {
|
||||
CrossAnimation::paintStaticLoading(
|
||||
@@ -608,7 +608,7 @@ void CrossButton::paintEvent(QPaintEvent *e) {
|
||||
shown);
|
||||
return;
|
||||
} else {
|
||||
loading = ((ms - _loadingStartMs) % _st.loadingPeriod)
|
||||
loading = (duration % _st.loadingPeriod)
|
||||
/ float64(_st.loadingPeriod);
|
||||
}
|
||||
}
|
||||
@@ -623,12 +623,13 @@ void CrossButton::paintEvent(QPaintEvent *e) {
|
||||
loading);
|
||||
}
|
||||
|
||||
bool CrossButton::stopLoadingAnimation(crl::time ms) {
|
||||
bool CrossButton::stopLoadingAnimation(crl::time duration) {
|
||||
if (!_loadingStopMs) {
|
||||
return false;
|
||||
}
|
||||
auto stopPeriod = (_loadingStopMs - _loadingStartMs) / _st.loadingPeriod;
|
||||
auto currentPeriod = (ms - _loadingStartMs) / _st.loadingPeriod;
|
||||
const auto stopPeriod = (_loadingStopMs - _loadingStartMs)
|
||||
/ _st.loadingPeriod;
|
||||
const auto currentPeriod = duration / _st.loadingPeriod;
|
||||
if (currentPeriod != stopPeriod) {
|
||||
Assert(currentPeriod > stopPeriod);
|
||||
return true;
|
||||
|
||||
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#pragma once
|
||||
|
||||
#include "ui/abstract_button.h"
|
||||
#include "ui/effects/animations.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -216,7 +217,7 @@ public:
|
||||
return toggle(false, animated);
|
||||
}
|
||||
void finishAnimating() {
|
||||
_a_show.finish();
|
||||
_a_show.stop();
|
||||
animationCallback();
|
||||
}
|
||||
|
||||
@@ -234,18 +235,18 @@ protected:
|
||||
QPoint prepareRippleStartPosition() const override;
|
||||
|
||||
private:
|
||||
void step_loading(crl::time ms, bool timer);
|
||||
bool stopLoadingAnimation(crl::time ms);
|
||||
bool loadingCallback(crl::time duration);
|
||||
bool stopLoadingAnimation(crl::time duration);
|
||||
void animationCallback();
|
||||
|
||||
const style::CrossButton &_st;
|
||||
|
||||
bool _shown = false;
|
||||
Animation _a_show;
|
||||
Ui::Animations::Simple _a_show;
|
||||
|
||||
crl::time _loadingStartMs = 0;
|
||||
crl::time _loadingStopMs = 0;
|
||||
BasicAnimation _a_loading;
|
||||
Ui::Animations::Basic _a_loading;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -972,8 +972,7 @@ void FlatInput::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
|
||||
auto ms = crl::now();
|
||||
auto placeholderFocused = _a_placeholderFocused.current(ms, _focused ? 1. : 0.);
|
||||
|
||||
auto placeholderFocused = _a_placeholderFocused.value(_focused ? 1. : 0.);
|
||||
auto pen = anim::pen(_st.borderColor, _st.borderActive, placeholderFocused);
|
||||
pen.setWidth(_st.borderWidth);
|
||||
p.setPen(pen);
|
||||
@@ -987,7 +986,7 @@ void FlatInput::paintEvent(QPaintEvent *e) {
|
||||
_st.icon.paint(p, 0, 0, width());
|
||||
}
|
||||
|
||||
auto placeholderOpacity = _a_placeholderVisible.current(ms, _placeholderVisible ? 1. : 0.);
|
||||
auto placeholderOpacity = _a_placeholderVisible.value(_placeholderVisible ? 1. : 0.);
|
||||
if (placeholderOpacity > 0.) {
|
||||
p.setOpacity(placeholderOpacity);
|
||||
|
||||
@@ -1007,7 +1006,11 @@ void FlatInput::paintEvent(QPaintEvent *e) {
|
||||
void FlatInput::focusInEvent(QFocusEvent *e) {
|
||||
if (!_focused) {
|
||||
_focused = true;
|
||||
_a_placeholderFocused.start([this] { update(); }, 0., 1., _st.phDuration);
|
||||
_a_placeholderFocused.start(
|
||||
[=] { update(); },
|
||||
0.,
|
||||
1.,
|
||||
_st.phDuration);
|
||||
update();
|
||||
}
|
||||
QLineEdit::focusInEvent(e);
|
||||
@@ -1017,7 +1020,11 @@ void FlatInput::focusInEvent(QFocusEvent *e) {
|
||||
void FlatInput::focusOutEvent(QFocusEvent *e) {
|
||||
if (_focused) {
|
||||
_focused = false;
|
||||
_a_placeholderFocused.start([this] { update(); }, 1., 0., _st.phDuration);
|
||||
_a_placeholderFocused.start(
|
||||
[=] { update(); },
|
||||
1.,
|
||||
0.,
|
||||
_st.phDuration);
|
||||
update();
|
||||
}
|
||||
QLineEdit::focusOutEvent(e);
|
||||
@@ -1069,7 +1076,11 @@ void FlatInput::updatePlaceholder() {
|
||||
auto placeholderVisible = !hasText;
|
||||
if (_placeholderVisible != placeholderVisible) {
|
||||
_placeholderVisible = placeholderVisible;
|
||||
_a_placeholderVisible.start([this] { update(); }, _placeholderVisible ? 0. : 1., _placeholderVisible ? 1. : 0., _st.phDuration);
|
||||
_a_placeholderVisible.start(
|
||||
[=] { update(); },
|
||||
_placeholderVisible ? 0. : 1.,
|
||||
_placeholderVisible ? 1. : 0.,
|
||||
_st.phDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#pragma once
|
||||
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/effects/animations.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
class UserData;
|
||||
@@ -110,8 +111,8 @@ private:
|
||||
|
||||
bool _focused = false;
|
||||
bool _placeholderVisible = true;
|
||||
Animation _a_placeholderFocused;
|
||||
Animation _a_placeholderVisible;
|
||||
Animations::Simple _a_placeholderFocused;
|
||||
Animations::Simple _a_placeholderVisible;
|
||||
bool _lastPreEditTextNotEmpty = false;
|
||||
|
||||
const style::FlatInput &_st;
|
||||
|
||||
Reference in New Issue
Block a user