2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-05 00:55:12 +00:00

animations refactored

This commit is contained in:
John Preston
2015-12-08 15:33:37 +03:00
parent f25fde09b7
commit 0b96dd5362
71 changed files with 1370 additions and 1584 deletions

View File

@@ -29,15 +29,15 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
BackgroundWidget::BackgroundWidget(QWidget *parent, LayeredWidget *w) : TWidget(parent)
, w(w)
, aBackground(0)
, aBackgroundFunc(anim::easeOutCirc)
, a_bg(0)
, _a_background(animation(this, &BackgroundWidget::step_background))
, hiding(false)
, shadow(st::boxShadow) {
w->setParent(this);
if (App::app()) App::app()->mtpPause();
setGeometry(0, 0, App::wnd()->width(), App::wnd()->height());
aBackground.start(1);
anim::start(this);
a_bg.start(1);
_a_background.start();
show();
connect(w, SIGNAL(closed()), this, SLOT(onInnerClose()));
connect(w, SIGNAL(resized()), this, SLOT(update()));
@@ -46,7 +46,7 @@ BackgroundWidget::BackgroundWidget(QWidget *parent, LayeredWidget *w) : TWidget(
}
void BackgroundWidget::showFast() {
animStep(st::layerSlideDuration + 1);
_a_background.step(getms() + st::layerSlideDuration + 1);
update();
}
@@ -58,10 +58,10 @@ void BackgroundWidget::paintEvent(QPaintEvent *e) {
if (!trivial) {
p.setClipRect(e->rect());
}
p.setOpacity(st::layerAlpha * aBackground.current());
p.setOpacity(st::layerAlpha * a_bg.current());
p.fillRect(rect(), st::layerBg->b);
p.setOpacity(aBackground.current());
p.setOpacity(a_bg.current());
shadow.paint(p, w->geometry(), st::boxShadowShift);
}
@@ -90,7 +90,7 @@ bool BackgroundWidget::onInnerClose() {
_hidden.pop_back();
w->show();
resizeEvent(0);
w->animStep(1);
w->showStep(1);
update();
return false;
}
@@ -101,8 +101,8 @@ void BackgroundWidget::startHide() {
hiding = true;
if (App::wnd()) App::wnd()->setInnerFocus();
aBackground.start(0);
anim::start(this);
a_bg.start(0);
_a_background.start();
w->startHide();
}
@@ -139,7 +139,7 @@ void BackgroundWidget::replaceInner(LayeredWidget *n) {
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*)));
w->show();
resizeEvent(0);
w->animStep(1);
w->showStep(1);
update();
}
@@ -150,28 +150,25 @@ void BackgroundWidget::showLayerLast(LayeredWidget *n) {
connect(n, SIGNAL(resized()), this, SLOT(update()));
connect(n, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*)));
n->parentResized();
n->animStep(1);
n->showStep(1);
n->hide();
update();
}
bool BackgroundWidget::animStep(float64 ms) {
void BackgroundWidget::step_background(float64 ms, bool timer) {
float64 dt = ms / (hiding ? st::layerHideDuration : st::layerSlideDuration);
w->animStep(dt);
bool res = true;
w->showStep(dt);
if (dt >= 1) {
aBackground.finish();
a_bg.finish();
if (hiding) {
App::wnd()->layerFinishedHide(this);
}
anim::stop(this);
res = false;
_a_background.stop();
if (App::app()) App::app()->mtpUnpause();
} else {
aBackground.update(dt, aBackgroundFunc);
a_bg.update(dt, anim::easeOutCirc);
}
update();
return res;
if (timer) update();
}
void BackgroundWidget::boxDestroyed(QObject *obj) {
@@ -196,7 +193,7 @@ BackgroundWidget::~BackgroundWidget() {
StickerPreviewWidget::StickerPreviewWidget(QWidget *parent) : TWidget(parent)
, a_shown(0, 0)
, _a_shown(animFunc(this, &StickerPreviewWidget::animStep_shown))
, _a_shown(animation(this, &StickerPreviewWidget::step_shown))
, _doc(0)
, _cacheStatus(CacheNotLoaded) {
setAttribute(Qt::WA_TransparentForMouseEvents);
@@ -222,17 +219,16 @@ void StickerPreviewWidget::resizeEvent(QResizeEvent *e) {
update();
}
bool StickerPreviewWidget::animStep_shown(float64 ms) {
void StickerPreviewWidget::step_shown(float64 ms, bool timer) {
float64 dt = ms / st::stickerPreviewDuration;
if (dt >= 1) {
a_shown.finish();
_a_shown.stop();
a_shown.finish();
if (a_shown.current() < 0.5) hide();
} else {
a_shown.update(dt, anim::linear);
}
update();
return true;
if (timer) update();
}
void StickerPreviewWidget::showPreview(DocumentData *sticker) {