mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
animations refactored
This commit is contained in:
@@ -36,7 +36,7 @@ void BlueTitleShadow::paintEvent(QPaintEvent *e) {
|
||||
|
||||
BlueTitleClose::BlueTitleClose(QWidget *parent) : Button(parent)
|
||||
, a_iconFg(st::boxBlueCloseBg->c)
|
||||
, _a_over(animFunc(this, &BlueTitleClose::animStep_over)) {
|
||||
, _a_over(animation(this, &BlueTitleClose::step_over)) {
|
||||
resize(st::boxTitleHeight, st::boxTitleHeight);
|
||||
setCursor(style::cur_pointer);
|
||||
connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource)));
|
||||
@@ -49,18 +49,15 @@ void BlueTitleClose::onStateChange(int oldState, ButtonStateChangeSource source)
|
||||
}
|
||||
}
|
||||
|
||||
bool BlueTitleClose::animStep_over(float64 ms) {
|
||||
void BlueTitleClose::step_over(float64 ms, bool timer) {
|
||||
float64 dt = ms / st::boxBlueCloseDuration;
|
||||
bool res = true;
|
||||
if (dt >= 1) {
|
||||
res = false;
|
||||
_a_over.stop();
|
||||
a_iconFg.finish();
|
||||
} else {
|
||||
a_iconFg.update(dt, anim::linear);
|
||||
}
|
||||
update((st::boxTitleHeight - st::boxBlueCloseIcon.pxWidth()) / 2, (st::boxTitleHeight - st::boxBlueCloseIcon.pxHeight()) / 2, st::boxBlueCloseIcon.pxWidth(), st::boxBlueCloseIcon.pxHeight());
|
||||
return res;
|
||||
|
||||
if (timer) update((st::boxTitleHeight - st::boxBlueCloseIcon.pxWidth()) / 2, (st::boxTitleHeight - st::boxBlueCloseIcon.pxHeight()) / 2, st::boxBlueCloseIcon.pxWidth(), st::boxBlueCloseIcon.pxHeight());
|
||||
}
|
||||
|
||||
void BlueTitleClose::paintEvent(QPaintEvent *e) {
|
||||
@@ -156,7 +153,7 @@ void AbstractBox::paintEvent(QPaintEvent *e) {
|
||||
if (paint(p)) return;
|
||||
}
|
||||
|
||||
void AbstractBox::animStep(float64 ms) {
|
||||
void AbstractBox::showStep(float64 ms) {
|
||||
if (ms >= 1) {
|
||||
a_opacity.finish();
|
||||
_cache = QPixmap();
|
||||
|
@@ -41,7 +41,7 @@ public slots:
|
||||
void onStateChange(int oldState, ButtonStateChangeSource source);
|
||||
|
||||
private:
|
||||
bool animStep_over(float64 ms);
|
||||
void step_over(float64 ms, bool timer);
|
||||
anim::cvalue a_iconFg;
|
||||
Animation _a_over;
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
AbstractBox(int32 w = st::boxWideWidth);
|
||||
void parentResized();
|
||||
void animStep(float64 ms);
|
||||
void showStep(float64 ms);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
@@ -342,7 +342,7 @@ void NewGroupBox::onNext() {
|
||||
GroupInfoBox::GroupInfoBox(CreatingGroupType creating, bool fromTypeChoose) : AbstractBox(),
|
||||
_creating(creating),
|
||||
a_photoOver(0, 0),
|
||||
_a_photoOver(animFunc(this, &GroupInfoBox::animStep_photoOver)),
|
||||
_a_photoOver(animation(this, &GroupInfoBox::step_photoOver)),
|
||||
_photoOver(false),
|
||||
_title(this, st::defaultInputField, lang(_creating == CreatingGroupChannel ? lng_dlg_new_channel_name : lng_dlg_new_group_name)),
|
||||
_description(this, st::newGroupDescription, lang(lng_create_group_description)),
|
||||
@@ -464,17 +464,15 @@ void GroupInfoBox::leaveEvent(QEvent *e) {
|
||||
updateSelected(QCursor::pos());
|
||||
}
|
||||
|
||||
bool GroupInfoBox::animStep_photoOver(float64 ms) {
|
||||
void GroupInfoBox::step_photoOver(float64 ms, bool timer) {
|
||||
float64 dt = ms / st::setPhotoDuration;
|
||||
bool res = true;
|
||||
if (dt >= 1) {
|
||||
res = false;
|
||||
_a_photoOver.stop();
|
||||
a_photoOver.finish();
|
||||
} else {
|
||||
a_photoOver.update(dt, anim::linear);
|
||||
}
|
||||
update(photoRect());
|
||||
return res;
|
||||
if (timer) update(photoRect());
|
||||
}
|
||||
|
||||
void GroupInfoBox::onNameSubmit() {
|
||||
@@ -604,23 +602,25 @@ void GroupInfoBox::onPhotoReady(const QImage &img) {
|
||||
_photoSmall.setDevicePixelRatio(cRetinaFactor());
|
||||
}
|
||||
|
||||
SetupChannelBox::SetupChannelBox(ChannelData *channel, bool existing) : AbstractBox(),
|
||||
_channel(channel),
|
||||
_existing(existing),
|
||||
_public(this, qsl("channel_privacy"), 0, lang(lng_create_public_channel_title), true),
|
||||
_private(this, qsl("channel_privacy"), 1, lang(lng_create_private_channel_title)),
|
||||
_comments(this, lang(lng_create_channel_comments), false),
|
||||
_aboutPublicWidth(width() - st::boxPadding.left() - st::boxButtonPadding.right() - st::newGroupPadding.left() - st::defaultRadiobutton.textPosition.x()),
|
||||
_aboutPublic(st::normalFont, lang(lng_create_public_channel_about), _defaultOptions, _aboutPublicWidth),
|
||||
_aboutPrivate(st::normalFont, lang(lng_create_private_channel_about), _defaultOptions, _aboutPublicWidth),
|
||||
_aboutComments(st::normalFont, lang(lng_create_channel_comments_about), _defaultOptions, _aboutPublicWidth),
|
||||
_link(this, st::defaultInputField, QString(), channel->username, true),
|
||||
_linkOver(false),
|
||||
_save(this, lang(lng_settings_save), st::defaultBoxButton),
|
||||
_skip(this, lang(existing ? lng_cancel : lng_create_group_skip), st::cancelBoxButton),
|
||||
_tooMuchUsernames(false),
|
||||
_saveRequestId(0), _checkRequestId(0),
|
||||
a_goodOpacity(0, 0), _a_goodFade(animFunc(this, &SetupChannelBox::animStep_goodFade)) {
|
||||
SetupChannelBox::SetupChannelBox(ChannelData *channel, bool existing) : AbstractBox()
|
||||
, _channel(channel)
|
||||
, _existing(existing)
|
||||
, _public(this, qsl("channel_privacy"), 0, lang(lng_create_public_channel_title), true)
|
||||
, _private(this, qsl("channel_privacy"), 1, lang(lng_create_private_channel_title))
|
||||
, _comments(this, lang(lng_create_channel_comments), false)
|
||||
, _aboutPublicWidth(width() - st::boxPadding.left() - st::boxButtonPadding.right() - st::newGroupPadding.left() - st::defaultRadiobutton.textPosition.x())
|
||||
, _aboutPublic(st::normalFont, lang(lng_create_public_channel_about), _defaultOptions, _aboutPublicWidth)
|
||||
, _aboutPrivate(st::normalFont, lang(lng_create_private_channel_about), _defaultOptions, _aboutPublicWidth)
|
||||
, _aboutComments(st::normalFont, lang(lng_create_channel_comments_about), _defaultOptions, _aboutPublicWidth)
|
||||
, _link(this, st::defaultInputField, QString(), channel->username, true)
|
||||
, _linkOver(false)
|
||||
, _save(this, lang(lng_settings_save), st::defaultBoxButton)
|
||||
, _skip(this, lang(existing ? lng_cancel : lng_create_group_skip), st::cancelBoxButton)
|
||||
, _tooMuchUsernames(false)
|
||||
, _saveRequestId(0)
|
||||
, _checkRequestId(0)
|
||||
, a_goodOpacity(0, 0)
|
||||
, _a_goodFade(animation(this, &SetupChannelBox::step_goodFade)) {
|
||||
setMouseTracking(true);
|
||||
|
||||
_checkRequestId = MTP::send(MTPchannels_CheckUsername(_channel->inputChannel, MTP_string("preston")), RPCDoneHandlerPtr(), rpcFail(&SetupChannelBox::onFirstCheckFail));
|
||||
@@ -772,17 +772,15 @@ void SetupChannelBox::updateSelected(const QPoint &cursorGlobalPosition) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SetupChannelBox::animStep_goodFade(float64 ms) {
|
||||
void SetupChannelBox::step_goodFade(float64 ms, bool timer) {
|
||||
float dt = ms / st::newGroupLinkFadeDuration;
|
||||
bool res = true;
|
||||
if (dt >= 1) {
|
||||
res = false;
|
||||
_a_goodFade.stop();
|
||||
a_goodOpacity.finish();
|
||||
} else {
|
||||
a_goodOpacity.update(dt, anim::linear);
|
||||
}
|
||||
update();
|
||||
return res;
|
||||
if (timer) update();
|
||||
}
|
||||
|
||||
void SetupChannelBox::closePressed() {
|
||||
|
@@ -113,8 +113,6 @@ public:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
|
||||
bool animStep_photoOver(float64 ms);
|
||||
|
||||
void setInnerFocus() {
|
||||
_title.setFocus();
|
||||
}
|
||||
@@ -136,6 +134,8 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
void step_photoOver(float64 ms, bool timer);
|
||||
|
||||
QRect photoRect() const;
|
||||
|
||||
void updateMaxHeight();
|
||||
@@ -202,7 +202,7 @@ protected:
|
||||
private:
|
||||
|
||||
void updateSelected(const QPoint &cursorGlobalPosition);
|
||||
bool animStep_goodFade(float64 ms);
|
||||
void step_goodFade(float64 ms, bool timer);
|
||||
|
||||
void onUpdateDone(const MTPBool &result);
|
||||
bool onUpdateFail(const RPCError &error);
|
||||
|
@@ -187,11 +187,13 @@ void ConfirmLinkBox::onOpenLink() {
|
||||
Ui::hideLayer();
|
||||
}
|
||||
|
||||
MaxInviteBox::MaxInviteBox(const QString &link) : AbstractBox(st::boxWidth),
|
||||
_close(this, lang(lng_box_ok), st::defaultBoxButton),
|
||||
_text(st::boxTextFont, lng_participant_invite_sorry(lt_count, cMaxGroupCount()), _confirmBoxTextOptions, st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right()),
|
||||
_link(link), _linkOver(false),
|
||||
a_goodOpacity(0, 0), a_good(animFunc(this, &MaxInviteBox::goodAnimStep)) {
|
||||
MaxInviteBox::MaxInviteBox(const QString &link) : AbstractBox(st::boxWidth)
|
||||
, _close(this, lang(lng_box_ok), st::defaultBoxButton)
|
||||
, _text(st::boxTextFont, lng_participant_invite_sorry(lt_count, cMaxGroupCount()), _confirmBoxTextOptions, st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right())
|
||||
, _link(link)
|
||||
, _linkOver(false)
|
||||
, a_goodOpacity(0, 0)
|
||||
, _a_good(animation(this, &MaxInviteBox::step_good)) {
|
||||
setMouseTracking(true);
|
||||
|
||||
_textWidth = st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right();
|
||||
@@ -213,7 +215,7 @@ void MaxInviteBox::mousePressEvent(QMouseEvent *e) {
|
||||
App::app()->clipboard()->setText(_link);
|
||||
_goodTextLink = lang(lng_create_channel_link_copied);
|
||||
a_goodOpacity = anim::fvalue(1, 0);
|
||||
a_good.start();
|
||||
_a_good.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,17 +234,15 @@ void MaxInviteBox::updateSelected(const QPoint &cursorGlobalPosition) {
|
||||
}
|
||||
}
|
||||
|
||||
bool MaxInviteBox::goodAnimStep(float64 ms) {
|
||||
void MaxInviteBox::step_good(float64 ms, bool timer) {
|
||||
float dt = ms / st::newGroupLinkFadeDuration;
|
||||
bool res = true;
|
||||
if (dt >= 1) {
|
||||
res = false;
|
||||
_a_good.stop();
|
||||
a_goodOpacity.finish();
|
||||
} else {
|
||||
a_goodOpacity.update(dt, anim::linear);
|
||||
}
|
||||
update();
|
||||
return res;
|
||||
if (timer) update();
|
||||
}
|
||||
|
||||
void MaxInviteBox::hideAll() {
|
||||
|
@@ -108,8 +108,7 @@ public:
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void leaveEvent(QEvent *e);
|
||||
void updateLink();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void hideAll();
|
||||
@@ -118,7 +117,7 @@ protected:
|
||||
private:
|
||||
|
||||
void updateSelected(const QPoint &cursorGlobalPosition);
|
||||
bool goodAnimStep(float64 ms);
|
||||
void step_good(float64 ms, bool timer);
|
||||
|
||||
BoxButton _close;
|
||||
Text _text;
|
||||
@@ -132,5 +131,5 @@ private:
|
||||
|
||||
QString _goodTextLink;
|
||||
anim::fvalue a_goodOpacity;
|
||||
Animation a_good;
|
||||
Animation _a_good;
|
||||
};
|
||||
|
@@ -333,7 +333,7 @@ StickersInner::StickersInner() : TWidget()
|
||||
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
||||
, _aboveShadowFadeStart(0)
|
||||
, _aboveShadowFadeOpacity(0, 0)
|
||||
, _a_shifting(animFunc(this, &StickersInner::animStep_shifting))
|
||||
, _a_shifting(animation(this, &StickersInner::step_shifting))
|
||||
, _itemsTop(st::membersPadding.top())
|
||||
, _saving(false)
|
||||
, _removeSel(-1)
|
||||
@@ -355,7 +355,7 @@ void StickersInner::paintEvent(QPaintEvent *e) {
|
||||
QRect r(e->rect());
|
||||
Painter p(this);
|
||||
|
||||
updateAnimatedValues();
|
||||
_a_shifting.step();
|
||||
|
||||
p.fillRect(r, st::white);
|
||||
p.setClipRect(r);
|
||||
@@ -489,7 +489,7 @@ void StickersInner::onUpdateSelected() {
|
||||
}
|
||||
_rows.at(_dragging)->yadd = anim::ivalue(local.y() - _dragStart.y(), local.y() - _dragStart.y());
|
||||
_animStartTimes[_dragging] = 0;
|
||||
updateAnimatedRegions();
|
||||
_a_shifting.step(getms(), true);
|
||||
|
||||
emit checkDraggingScroll(local.y());
|
||||
} else {
|
||||
@@ -538,33 +538,14 @@ void StickersInner::mouseReleaseEvent(QMouseEvent *e) {
|
||||
}
|
||||
}
|
||||
|
||||
void StickersInner::updateAnimatedRegions() {
|
||||
int32 updateMin = -1, updateMax = 0;
|
||||
for (int32 i = 0, l = _animStartTimes.size(); i < l; ++i) {
|
||||
if (_animStartTimes.at(i)) {
|
||||
if (updateMin < 0) updateMin = i;
|
||||
updateMax = i;
|
||||
}
|
||||
}
|
||||
if (_aboveShadowFadeStart) {
|
||||
if (updateMin < 0 || updateMin > _above) updateMin = _above;
|
||||
if (updateMax < _above) updateMin = _above;
|
||||
}
|
||||
if (_dragging >= 0) {
|
||||
if (updateMin < 0 || updateMin > _dragging) updateMin = _dragging;
|
||||
if (updateMax < _dragging) updateMax = _dragging;
|
||||
}
|
||||
if (updateMin >= 0) {
|
||||
update(0, _itemsTop + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3));
|
||||
}
|
||||
}
|
||||
|
||||
bool StickersInner::updateAnimatedValues() {
|
||||
void StickersInner::step_shifting(uint64 ms, bool timer) {
|
||||
bool animating = false;
|
||||
uint64 ms = getms();
|
||||
int32 updateMin = -1, updateMax = 0;
|
||||
for (int32 i = 0, l = _animStartTimes.size(); i < l; ++i) {
|
||||
uint64 start = _animStartTimes.at(i);
|
||||
if (start) {
|
||||
if (updateMin < 0) updateMin = i;
|
||||
updateMax = i;
|
||||
if (start + st::stickersRowDuration > ms && ms >= start) {
|
||||
_rows.at(i)->yadd.update((ms - start) / st::stickersRowDuration, anim::sineInOut);
|
||||
animating = true;
|
||||
@@ -575,6 +556,8 @@ bool StickersInner::updateAnimatedValues() {
|
||||
}
|
||||
}
|
||||
if (_aboveShadowFadeStart) {
|
||||
if (updateMin < 0 || updateMin > _above) updateMin = _above;
|
||||
if (updateMax < _above) updateMin = _above;
|
||||
if (_aboveShadowFadeStart + st::stickersRowDuration > ms && ms > _aboveShadowFadeStart) {
|
||||
_aboveShadowFadeOpacity.update((ms - _aboveShadowFadeStart) / st::stickersRowDuration, anim::sineInOut);
|
||||
animating = true;
|
||||
@@ -583,17 +566,19 @@ bool StickersInner::updateAnimatedValues() {
|
||||
_aboveShadowFadeStart = 0;
|
||||
}
|
||||
}
|
||||
return animating;
|
||||
}
|
||||
|
||||
bool StickersInner::animStep_shifting(float64) {
|
||||
updateAnimatedRegions();
|
||||
|
||||
bool animating = updateAnimatedValues();
|
||||
if (timer) {
|
||||
if (_dragging >= 0) {
|
||||
if (updateMin < 0 || updateMin > _dragging) updateMin = _dragging;
|
||||
if (updateMax < _dragging) updateMax = _dragging;
|
||||
}
|
||||
if (updateMin >= 0) {
|
||||
update(0, _itemsTop + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3));
|
||||
}
|
||||
}
|
||||
if (!animating) {
|
||||
_above = _dragging;
|
||||
_a_shifting.stop();
|
||||
}
|
||||
return animating;
|
||||
}
|
||||
|
||||
void StickersInner::clear() {
|
||||
|
@@ -144,13 +144,11 @@ public slots:
|
||||
|
||||
private:
|
||||
|
||||
bool animStep_shifting(float64 ms);
|
||||
void step_shifting(uint64 ms, bool timer);
|
||||
void paintRow(Painter &p, int32 index);
|
||||
void clear();
|
||||
void setRemoveSel(int32 removeSel);
|
||||
float64 aboveShadowOpacity() const;
|
||||
void updateAnimatedRegions();
|
||||
bool updateAnimatedValues();
|
||||
|
||||
int32 _rowHeight;
|
||||
struct StickerSetRow {
|
||||
|
Reference in New Issue
Block a user