2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +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

@@ -52,27 +52,27 @@ namespace {
}
}
IntroWidget::IntroWidget(Window *window) : TWidget(window),
_langChangeTo(0),
_a_stage(animFunc(this, &IntroWidget::animStep_stage)),
_cacheHideIndex(0),
_cacheShowIndex(0),
_a_show(animFunc(this, &IntroWidget::animStep_show)),
wnd(window),
steps(new IntroSteps(this)),
phone(0),
code(0),
signup(0),
pwdcheck(0),
current(0),
moving(0),
_callTimeout(60),
_registered(false),
_hasRecovery(false),
_codeByTelegram(false),
_back(this, st::setClose),
_backFrom(0), _backTo(0) {
setGeometry(QRect(0, st::titleHeight, wnd->width(), wnd->height() - st::titleHeight));
IntroWidget::IntroWidget(Window *window) : TWidget(window)
, _langChangeTo(0)
, _a_stage(animation(this, &IntroWidget::step_stage))
, _cacheHideIndex(0)
, _cacheShowIndex(0)
, _a_show(animation(this, &IntroWidget::step_show))
, steps(new IntroSteps(this))
, phone(0)
, code(0)
, signup(0)
, pwdcheck(0)
, current(0)
, moving(0)
, _callTimeout(60)
, _registered(false)
, _hasRecovery(false)
, _codeByTelegram(false)
, _back(this, st::setClose)
, _backFrom(0)
, _backTo(0) {
setGeometry(QRect(0, st::titleHeight, App::wnd()->width(), App::wnd()->height() - st::titleHeight));
connect(&_back, SIGNAL(clicked()), this, SLOT(onIntroBack()));
_back.hide();
@@ -162,7 +162,7 @@ void IntroWidget::prepareMove() {
_backTo = stages[current + moving]->hasBack() ? 1 : 0;
_backFrom = stages[current]->hasBack() ? 1 : 0;
animStep_stage(0);
_a_stage.step();
if (_backFrom > 0 || _backTo > 0) {
_back.show();
} else {
@@ -227,13 +227,11 @@ void IntroWidget::animShow(const QPixmap &bgAnimCache, bool back) {
show();
}
bool IntroWidget::animStep_show(float64 ms) {
void IntroWidget::step_show(float64 ms, bool timer) {
float64 dt = ms / st::slideDuration;
bool res = true;
if (dt >= 1) {
_a_show.stop();
res = false;
a_coordUnder.finish();
a_coordOver.finish();
a_shadow.finish();
@@ -253,21 +251,19 @@ bool IntroWidget::animStep_show(float64 ms) {
a_coordOver.update(dt, st::slideFunction);
a_shadow.update(dt, st::slideFunction);
}
update();
return res;
if (timer) update();
}
void IntroWidget::animStop_show() {
void IntroWidget::stop_show() {
_a_show.stop();
}
bool IntroWidget::animStep_stage(float64 ms) {
bool res = true;
void IntroWidget::step_stage(float64 ms, bool timer) {
float64 fullDuration = st::introSlideDelta + st::introSlideDuration, dt = ms / fullDuration;
float64 dt1 = (ms > st::introSlideDuration) ? 1 : (ms / st::introSlideDuration), dt2 = (ms > st::introSlideDelta) ? (ms - st::introSlideDelta) / (st::introSlideDuration) : 0;
if (dt >= 1) {
res = false;
_a_stage.stop();
a_coordShow.finish();
a_opacityShow.finish();
@@ -292,8 +288,7 @@ bool IntroWidget::animStep_stage(float64 ms) {
_back.setOpacity(1);
}
}
update();
return res;
if (timer) update();
}
void IntroWidget::paintEvent(QPaintEvent *e) {
@@ -414,7 +409,7 @@ void IntroWidget::mousePressEvent(QMouseEvent *e) {
}
void IntroWidget::finish(const MTPUser &user, const QImage &photo) {
wnd->setupMain(true, &user);
App::wnd()->setupMain(true, &user);
if (!photo.isNull()) {
App::app()->uploadProfilePhoto(photo, MTP::authedId());
}

View File

@@ -44,10 +44,10 @@ public:
void updateWideMode();
void animShow(const QPixmap &bgAnimCache, bool back = false);
bool animStep_show(float64 ms);
void animStop_show();
void step_show(float64 ms, bool timer);
void stop_show();
bool animStep_stage(float64 ms);
void step_stage(float64 ms, bool timer);
QRect innerRect() const;
QString currentCountry() const;
@@ -108,7 +108,6 @@ private:
anim::ivalue a_coordUnder, a_coordOver;
anim::fvalue a_shadow;
Window *wnd;
IntroSteps *steps;
IntroPhone *phone;
IntroCode *code;

View File

@@ -72,12 +72,15 @@ void CodeInput::correctValue(const QString &was, QString &now) {
if (strict) emit codeEntered();
}
IntroCode::IntroCode(IntroWidget *parent) : IntroStage(parent), errorAlpha(0),
next(this, lang(lng_intro_next), st::btnIntroNext),
_desc(st::introTextSize.width()),
_noTelegramCode(this, lang(lng_code_no_telegram), st::introLink),
_noTelegramCodeRequestId(0),
code(this, st::inpIntroCode, lang(lng_code_ph)), waitTillCall(intro()->getCallTimeout()) {
IntroCode::IntroCode(IntroWidget *parent) : IntroStage(parent)
, a_errorAlpha(0)
, _a_error(animation(this, &IntroCode::step_error))
, next(this, lang(lng_intro_next), st::btnIntroNext)
, _desc(st::introTextSize.width())
, _noTelegramCode(this, lang(lng_code_no_telegram), st::introLink)
, _noTelegramCodeRequestId(0)
, code(this, st::inpIntroCode, lang(lng_code_ph))
, waitTillCall(intro()->getCallTimeout()) {
setVisible(false);
setGeometry(parent->innerRect());
@@ -132,8 +135,8 @@ void IntroCode::paintEvent(QPaintEvent *e) {
}
p.drawText(QRect(textRect.left(), code.y() + code.height() + st::introCallSkip, st::introTextSize.width(), st::introErrHeight), callText, style::al_center);
}
if (animating() || error.length()) {
p.setOpacity(errorAlpha.current());
if (_a_error.animating() || error.length()) {
p.setOpacity(a_errorAlpha.current());
p.setFont(st::introErrFont->f);
p.setPen(st::introErrColor->p);
p.drawText(QRect(textRect.left(), next.y() + next.height() + st::introErrTop, st::introTextSize.width(), st::introErrHeight), error, style::al_center);
@@ -151,32 +154,30 @@ void IntroCode::resizeEvent(QResizeEvent *e) {
void IntroCode::showError(const QString &err) {
if (!err.isEmpty()) code.notaBene();
if (!animating() && err == error) return;
if (!_a_error.animating() && err == error) return;
if (err.length()) {
error = err;
errorAlpha.start(1);
a_errorAlpha.start(1);
} else {
errorAlpha.start(0);
a_errorAlpha.start(0);
}
anim::start(this);
_a_error.start();
}
bool IntroCode::animStep(float64 ms) {
void IntroCode::step_error(float64 ms, bool timer) {
float64 dt = ms / st::introErrDuration;
bool res = true;
if (dt >= 1) {
res = false;
errorAlpha.finish();
if (!errorAlpha.current()) {
_a_error.stop();
a_errorAlpha.finish();
if (!a_errorAlpha.current()) {
error = "";
}
} else {
errorAlpha.update(dt, st::introErrFunc);
a_errorAlpha.update(dt, st::introErrFunc);
}
update();
return res;
if (timer) update();
}
void IntroCode::activate() {
@@ -185,7 +186,7 @@ void IntroCode::activate() {
callTimer.start(1000);
}
error = "";
errorAlpha = anim::fvalue(0);
a_errorAlpha = anim::fvalue(0);
sentCode = QString();
show();
code.setDisabled(false);

View File

@@ -42,7 +42,7 @@ protected:
};
class IntroCode : public IntroStage, public Animated, public RPCSender {
class IntroCode : public IntroStage, public RPCSender {
Q_OBJECT
public:
@@ -52,7 +52,7 @@ public:
void paintEvent(QPaintEvent *e);
void resizeEvent(QResizeEvent *e);
bool animStep(float64 ms);
void step_error(float64 ms, bool timer);
void activate();
void prepareShow();
@@ -86,7 +86,8 @@ private:
void stopCheck();
QString error;
anim::fvalue errorAlpha;
anim::fvalue a_errorAlpha;
Animation _a_error;
FlatButton next;

View File

@@ -45,13 +45,16 @@ namespace {
};
}
IntroPhone::IntroPhone(IntroWidget *parent) : IntroStage(parent),
errorAlpha(0), changed(false),
next(this, lang(lng_intro_next), st::btnIntroNext),
country(this, st::introCountry),
phone(this, st::inpIntroPhone), code(this, st::inpIntroCountryCode),
_signup(this, lng_phone_notreg(lt_signup_start, textcmdStartLink(1), lt_signup_end, textcmdStopLink()), st::introErrLabel, st::introErrLabelTextStyle),
_showSignup(false) {
IntroPhone::IntroPhone(IntroWidget *parent) : IntroStage(parent)
, a_errorAlpha(0)
, _a_error(animation(this, &IntroPhone::step_error))
, changed(false)
, next(this, lang(lng_intro_next), st::btnIntroNext)
, country(this, st::introCountry)
, phone(this, st::inpIntroPhone)
, code(this, st::inpIntroCountryCode)
, _signup(this, lng_phone_notreg(lt_signup_start, textcmdStartLink(1), lt_signup_end, textcmdStopLink()), st::introErrLabel, st::introErrLabelTextStyle)
, _showSignup(false) {
setVisible(false);
setGeometry(parent->innerRect());
@@ -92,9 +95,9 @@ void IntroPhone::paintEvent(QPaintEvent *e) {
p.setFont(st::introFont->f);
p.drawText(textRect, lang(lng_phone_desc), style::al_bottom);
}
if (animating() || error.length()) {
if (_a_error.animating() || error.length()) {
int32 errorY = _showSignup ? ((phone.y() + phone.height() + next.y() - st::introErrFont->height) / 2) : (next.y() + next.height() + st::introErrTop);
p.setOpacity(errorAlpha.current());
p.setOpacity(a_errorAlpha.current());
p.setFont(st::introErrFont->f);
p.setPen(st::introErrColor->p);
p.drawText(QRect(textRect.x(), errorY, textRect.width(), st::introErrFont->height), error, style::al_top);
@@ -123,36 +126,34 @@ void IntroPhone::showError(const QString &err, bool signUp) {
_showSignup = signUp;
}
if (!animating() && err == error) return;
if (!_a_error.animating() && err == error) return;
if (err.length()) {
error = err;
errorAlpha.start(1);
a_errorAlpha.start(1);
} else {
errorAlpha.start(0);
a_errorAlpha.start(0);
}
_signup.hide();
anim::start(this);
_a_error.start();
}
bool IntroPhone::animStep(float64 ms) {
void IntroPhone::step_error(float64 ms, bool timer) {
float64 dt = ms / st::introErrDuration;
bool res = true;
if (dt >= 1) {
res = false;
errorAlpha.finish();
if (!errorAlpha.current()) {
_a_error.stop();
a_errorAlpha.finish();
if (!a_errorAlpha.current()) {
error = "";
_signup.hide();
} else if (!error.isEmpty() && _showSignup) {
_signup.show();
}
} else {
errorAlpha.update(dt, st::introErrFunc);
a_errorAlpha.update(dt, st::introErrFunc);
}
update();
return res;
if (timer) update();
}
void IntroPhone::countryChanged() {
@@ -293,7 +294,7 @@ void IntroPhone::selectCountry(const QString &c) {
void IntroPhone::activate() {
error = "";
errorAlpha = anim::fvalue(0);
a_errorAlpha = anim::fvalue(0);
show();
enableAll(true);
}

View File

@@ -25,7 +25,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "gui/countryinput.h"
#include "intro.h"
class IntroPhone : public IntroStage, public Animated, public RPCSender {
class IntroPhone : public IntroStage, public RPCSender {
Q_OBJECT
public:
@@ -35,7 +35,7 @@ public:
void paintEvent(QPaintEvent *e);
void resizeEvent(QResizeEvent *e);
bool animStep(float64 ms);
void step_error(float64 ms, bool timer);
void selectCountry(const QString &country);
@@ -67,7 +67,8 @@ private:
void showError(const QString &err, bool signUp = false);
QString error;
anim::fvalue errorAlpha;
anim::fvalue a_errorAlpha;
Animation _a_error;
bool changed;
FlatButton next;

View File

@@ -30,18 +30,19 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "intro/intropwdcheck.h"
#include "intro/intro.h"
IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStage(parent),
errorAlpha(0),
_next(this, lang(lng_intro_submit), st::btnIntroNext),
_salt(parent->getPwdSalt()),
_hasRecovery(parent->getHasRecovery()),
_hint(parent->getPwdHint()),
_pwdField(this, st::inpIntroPassword, lang(lng_signin_password)),
_codeField(this, st::inpIntroPassword, lang(lng_signin_code)),
_toRecover(this, lang(lng_signin_recover)),
_toPassword(this, lang(lng_signin_try_password)),
_reset(this, lang(lng_signin_reset_account), st::btnRedLink),
sentRequest(0) {
IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStage(parent)
, a_errorAlpha(0)
, _a_error(animation(this, &IntroPwdCheck::step_error))
, _next(this, lang(lng_intro_submit), st::btnIntroNext)
, _salt(parent->getPwdSalt())
, _hasRecovery(parent->getHasRecovery())
, _hint(parent->getPwdHint())
, _pwdField(this, st::inpIntroPassword, lang(lng_signin_password))
, _codeField(this, st::inpIntroPassword, lang(lng_signin_code))
, _toRecover(this, lang(lng_signin_recover))
, _toPassword(this, lang(lng_signin_try_password))
, _reset(this, lang(lng_signin_reset_account), st::btnRedLink)
, sentRequest(0) {
setVisible(false);
setGeometry(parent->innerRect());
@@ -86,8 +87,8 @@ void IntroPwdCheck::paintEvent(QPaintEvent *e) {
} else if (!_hint.isEmpty()) {
_hintText.drawElided(p, _pwdField.x(), _pwdField.y() + _pwdField.height() + st::introFinishSkip, _pwdField.width(), 1, style::al_top);
}
if (animating() || error.length()) {
p.setOpacity(errorAlpha.current());
if (_a_error.animating() || error.length()) {
p.setOpacity(a_errorAlpha.current());
QRect errRect((width() - st::introErrWidth) / 2, (_pwdField.y() + _pwdField.height() + st::introFinishSkip + st::introFont->height + _next.y() - st::introErrHeight) / 2, st::introErrWidth, st::introErrHeight);
p.setFont(st::introErrFont->f);
@@ -111,32 +112,30 @@ void IntroPwdCheck::resizeEvent(QResizeEvent *e) {
}
void IntroPwdCheck::showError(const QString &err) {
if (!animating() && err == error) return;
if (!_a_error.animating() && err == error) return;
if (err.length()) {
error = err;
errorAlpha.start(1);
a_errorAlpha.start(1);
} else {
errorAlpha.start(0);
a_errorAlpha.start(0);
}
anim::start(this);
_a_error.start();
}
bool IntroPwdCheck::animStep(float64 ms) {
void IntroPwdCheck::step_error(float64 ms, bool timer) {
float64 dt = ms / st::introErrDuration;
bool res = true;
if (dt >= 1) {
res = false;
errorAlpha.finish();
if (!errorAlpha.current()) {
_a_error.stop();
a_errorAlpha.finish();
if (!a_errorAlpha.current()) {
error = "";
}
} else {
errorAlpha.update(dt, st::introErrFunc);
a_errorAlpha.update(dt, st::introErrFunc);
}
update();
return res;
if (timer) update();
}
void IntroPwdCheck::activate() {

View File

@@ -25,7 +25,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "gui/flatinput.h"
#include "intro.h"
class IntroPwdCheck : public IntroStage, public Animated, public RPCSender {
class IntroPwdCheck : public IntroStage, public RPCSender {
Q_OBJECT
public:
@@ -35,7 +35,7 @@ public:
void paintEvent(QPaintEvent *e);
void resizeEvent(QResizeEvent *e);
bool animStep(float64 ms);
void step_error(float64 ms, bool timer);
void activate();
void deactivate();
@@ -69,7 +69,8 @@ private:
bool deleteFail(const RPCError &error);
QString error;
anim::fvalue errorAlpha;
anim::fvalue a_errorAlpha;
Animation _a_error;
FlatButton _next;

View File

@@ -30,12 +30,15 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "intro/introsignup.h"
#include "intro/intro.h"
IntroSignup::IntroSignup(IntroWidget *parent) : IntroStage(parent),
errorAlpha(0), a_photo(0),
next(this, lang(lng_intro_finish), st::btnIntroNext),
first(this, st::inpIntroName, lang(lng_signup_firstname)),
last(this, st::inpIntroName, lang(lng_signup_lastname)),
_invertOrder(langFirstNameGoesSecond()) {
IntroSignup::IntroSignup(IntroWidget *parent) : IntroStage(parent)
, a_errorAlpha(0)
, a_photoOver(0)
, _a_error(animation(this, &IntroSignup::step_error))
, _a_photo(animation(this, &IntroSignup::step_photo))
, next(this, lang(lng_intro_finish), st::btnIntroNext)
, first(this, st::inpIntroName, lang(lng_signup_firstname))
, last(this, st::inpIntroName, lang(lng_signup_lastname))
, _invertOrder(langFirstNameGoesSecond()) {
setVisible(false);
setGeometry(parent->innerRect());
@@ -54,9 +57,8 @@ void IntroSignup::mouseMoveEvent(QMouseEvent *e) {
if (photoOver != _photoOver) {
_photoOver = photoOver;
if (_photoSmall.isNull()) {
a_photo.start(_photoOver ? 1 : 0);
errorAlpha.restart();
anim::start(this);
a_photoOver.start(_photoOver ? 1 : 0);
_a_photo.start();
}
}
@@ -107,8 +109,8 @@ void IntroSignup::paintEvent(QPaintEvent *e) {
p.setFont(st::introFont->f);
p.drawText(textRect, lang(lng_signup_desc), style::al_bottom);
}
if (animating() || error.length()) {
p.setOpacity(errorAlpha.current());
if (_a_error.animating() || error.length()) {
p.setOpacity(a_errorAlpha.current());
QRect errRect;
if (_invertOrder) {
@@ -124,17 +126,17 @@ void IntroSignup::paintEvent(QPaintEvent *e) {
}
if (_photoSmall.isNull()) {
if (a_photo.current() < 1) {
if (a_photoOver.current() < 1) {
QRect pix(st::setPhotoImg);
pix.moveTo(pix.x() + (pix.width() - st::introPhotoSize) / 2, pix.y() + (pix.height() - st::introPhotoSize) / 2);
pix.setSize(QSize(st::introPhotoSize, st::introPhotoSize));
p.drawPixmap(QPoint(_phLeft, _phTop), App::sprite(), pix);
}
if (a_photo.current() > 0) {
if (a_photoOver.current() > 0) {
QRect pix(st::setOverPhotoImg);
pix.moveTo(pix.x() + (pix.width() - st::introPhotoSize) / 2, pix.y() + (pix.height() - st::introPhotoSize) / 2);
pix.setSize(QSize(st::introPhotoSize, st::introPhotoSize));
p.setOpacity(a_photo.current());
p.setOpacity(a_photoOver.current());
p.drawPixmap(QPoint(_phLeft, _phTop), App::sprite(), pix);
p.setOpacity(1);
}
@@ -160,35 +162,42 @@ void IntroSignup::resizeEvent(QResizeEvent *e) {
}
void IntroSignup::showError(const QString &err) {
if (!animating() && err == error) return;
if (!_a_error.animating() && err == error) return;
if (err.length()) {
error = err;
errorAlpha.start(1);
a_errorAlpha.start(1);
} else {
errorAlpha.start(0);
a_errorAlpha.start(0);
}
a_photo.restart();
anim::start(this);
_a_error.start();
}
bool IntroSignup::animStep(float64 ms) {
void IntroSignup::step_error(float64 ms, bool timer) {
float64 dt = ms / st::introErrDuration;
bool res = true;
if (dt >= 1) {
res = false;
errorAlpha.finish();
if (!errorAlpha.current()) {
_a_error.stop();
a_errorAlpha.finish();
if (!a_errorAlpha.current()) {
error = "";
}
a_photo.finish();
} else {
errorAlpha.update(dt, st::introErrFunc);
a_photo.update(dt, anim::linear);
a_errorAlpha.update(dt, st::introErrFunc);
}
update();
return res;
if (timer) update();
}
void IntroSignup::step_photo(float64 ms, bool timer) {
float64 dt = ms / st::introErrDuration;
if (dt >= 1) {
_a_photo.stop();
a_photoOver.finish();
} else {
a_photoOver.update(dt, anim::linear);
}
if (timer) update();
}
void IntroSignup::activate() {

View File

@@ -25,7 +25,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "gui/flatinput.h"
#include "intro.h"
class IntroSignup : public IntroStage, public Animated, public RPCSender {
class IntroSignup : public IntroStage, public RPCSender {
Q_OBJECT
public:
@@ -37,7 +37,8 @@ public:
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
bool animStep(float64 ms);
void step_error(float64 ms, bool timer);
void step_photo(float64 ms, bool timer);
void activate();
void deactivate();
@@ -60,7 +61,9 @@ private:
void stopCheck();
QString error;
anim::fvalue errorAlpha, a_photo;
anim::fvalue a_errorAlpha, a_photoOver;
Animation _a_error;
Animation _a_photo;
FlatButton next;