2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

new slide animations

This commit is contained in:
John Preston
2015-10-17 16:52:26 +02:00
parent a9450956c3
commit e211268158
33 changed files with 717 additions and 468 deletions

View File

@@ -2381,12 +2381,13 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
, _confirmImageId(0)
, _confirmWithText(false)
, _titlePeerTextWidth(0)
, _showAnim(animFunc(this, &HistoryWidget::showStep))
, _a_show(animFunc(this, &HistoryWidget::animStep_show))
, _scrollDelta(0)
, _saveDraftStart(0)
, _saveDraftText(false)
, _sideShadow(this, st::shadowColor)
, _topShadow(this, st::shadowColor) {
, _topShadow(this, st::shadowColor)
, _inGrab(false) {
_scroll.setFocusPolicy(Qt::NoFocus);
setAcceptDrops(true);
@@ -2844,7 +2845,7 @@ void HistoryWidget::setKbWasHidden() {
if (_kbWasHidden || (!_keyboard.hasMarkup() && !_keyboard.forceReply())) return;
_kbWasHidden = true;
if (!_showAnim.animating()) {
if (!_a_show.animating()) {
_kbScroll.hide();
_attachEmoji.show();
_kbHide.hide();
@@ -3186,7 +3187,7 @@ void HistoryWidget::updateReportSpamStatus() {
}
void HistoryWidget::updateControlsVisibility() {
if (!_history || _showAnim.animating()) {
if (!_history || _a_show.animating()) {
_reportSpamPanel.hide();
_scroll.hide();
_kbScroll.hide();
@@ -3595,7 +3596,7 @@ void HistoryWidget::windowShown() {
bool HistoryWidget::isActive() const {
if (!_history) return true;
if (_firstLoadRequest || _showAnim.animating()) return false;
if (_firstLoadRequest || _a_show.animating()) return false;
if (_history->loadedAtBottom()) return true;
if (_history->showFrom && !_history->showFrom->detached() && _history->unreadBar) return true;
return false;
@@ -3772,7 +3773,7 @@ void HistoryWidget::onHistoryToEnd() {
void HistoryWidget::onCollapseComments() {
MsgId switchAt = SwitchAtTopMsgId;
bool collapseCommentsVisible = !_showAnim.animating() && _history && !_firstLoadRequest && _history->isChannel() && !_history->asChannelHistory()->onlyImportant();
bool collapseCommentsVisible = !_a_show.animating() && _history && !_firstLoadRequest && _history->isChannel() && !_history->asChannelHistory()->onlyImportant();
if (collapseCommentsVisible) {
if (HistoryItem *collapse = _history->asChannelHistory()->collapse()) {
if (!collapse->detached()) {
@@ -3993,12 +3994,13 @@ HistoryItem *HistoryWidget::atTopImportantMsg(int32 &bottomUnderScrollTop) const
void HistoryWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back) {
if (App::app()) App::app()->mtpPause();
_bgAnimCache = bgAnimCache;
_bgAnimTopBarCache = bgAnimTopBarCache;
_animCache = myGrab(this, rect());
(back ? _cacheOver : _cacheUnder) = bgAnimCache;
(back ? _cacheTopBarOver : _cacheTopBarUnder) = bgAnimTopBarCache;
(back ? _cacheUnder : _cacheOver) = myGrab(this);
App::main()->topBar()->stopAnim();
_animTopBarCache = myGrab(App::main()->topBar(), QRect(0, 0, width(), st::topBarHeight));
(back ? _cacheTopBarUnder : _cacheTopBarOver) = myGrab(App::main()->topBar());
App::main()->topBar()->startAnim();
_scroll.hide();
_kbScroll.hide();
_reportSpamPanel.hide();
@@ -4019,43 +4021,38 @@ void HistoryWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTo
_botStart.hide();
_joinChannel.hide();
_muteUnmute.hide();
a_coord = back ? anim::ivalue(-st::introSlideShift, 0) : anim::ivalue(st::introSlideShift, 0);
a_alpha = anim::fvalue(0, 1);
a_bgCoord = back ? anim::ivalue(0, st::introSlideShift) : anim::ivalue(0, -st::introSlideShift);
a_bgAlpha = anim::fvalue(1, 0);
_sideShadow.hide();
_topShadow.hide();
_showAnim.start();
a_coordUnder = back ? anim::ivalue(-qFloor(st::slideShift * width()), 0) : anim::ivalue(0, -qFloor(st::slideShift * width()));
a_coordOver = back ? anim::ivalue(0, width()) : anim::ivalue(width(), 0);
a_shadow = back ? anim::fvalue(1, 0) : anim::fvalue(0, 1);
_a_show.start();
App::main()->topBar()->update();
activate();
}
bool HistoryWidget::showStep(float64 ms) {
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;
bool HistoryWidget::animStep_show(float64 ms) {
float64 dt = ms / st::slideDuration;
bool res = true;
if (dt2 >= 1) {
_showAnim.stop();
_sideShadow.show();
if (dt >= 1) {
_a_show.stop();
_sideShadow.setVisible(cWideMode());
_topShadow.show();
res = false;
a_bgCoord.finish();
a_bgAlpha.finish();
a_coord.finish();
a_alpha.finish();
_bgAnimCache = _animCache = _animTopBarCache = _bgAnimTopBarCache = QPixmap();
a_coordUnder.finish();
a_coordOver.finish();
a_shadow.finish();
_cacheUnder = _cacheOver = _cacheTopBarUnder = _cacheTopBarOver = QPixmap();
App::main()->topBar()->stopAnim();
doneShow();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);
a_coord.update(dt2, st::introShowFunc);
a_alpha.update(dt2, st::introAlphaShowFunc);
a_coordUnder.update(dt, st::slideFunction);
a_coordOver.update(dt, st::slideFunction);
a_shadow.update(dt, st::slideFunction);
}
update();
App::main()->topBar()->update();
@@ -4074,10 +4071,14 @@ void HistoryWidget::doneShow() {
}
}
void HistoryWidget::updateWideMode() {
_sideShadow.setVisible(cWideMode());
}
void HistoryWidget::animStop() {
if (!_showAnim.animating()) return;
_showAnim.stop();
_sideShadow.show();
if (!_a_show.animating()) return;
_a_show.stop();
_sideShadow.setVisible(cWideMode());
_topShadow.show();
}
@@ -4616,11 +4617,11 @@ void HistoryWidget::selectMessage() {
}
void HistoryWidget::paintTopBar(QPainter &p, float64 over, int32 decreaseWidth) {
if (_showAnim.animating()) {
p.setOpacity(a_bgAlpha.current());
p.drawPixmap(a_bgCoord.current(), 0, _bgAnimTopBarCache);
p.setOpacity(a_alpha.current());
p.drawPixmap(a_coord.current(), 0, _animTopBarCache);
if (_a_show.animating()) {
p.drawPixmap(a_coordUnder.current(), 0, _cacheTopBarUnder);
p.drawPixmap(a_coordOver.current(), 0, _cacheTopBarOver);
p.setOpacity(a_shadow.current());
p.drawPixmap(QRect(a_coordOver.current() - st::slideShadow.pxWidth(), 0, st::slideShadow.pxWidth(), st::topBarHeight), App::sprite(), st::slideShadow);
return;
}
@@ -4757,7 +4758,7 @@ void HistoryWidget::onFieldFocused() {
}
void HistoryWidget::checkMentionDropdown() {
if (!_history || _showAnim.animating()) return;
if (!_history || _a_show.animating()) return;
QString start;
_field.getMentionHashtagBotCommandStart(start);
@@ -5275,8 +5276,8 @@ void HistoryWidget::resizeEvent(QResizeEvent *e) {
break;
}
_topShadow.resize(width() - (cWideMode() ? st::lineWidth : 0), st::lineWidth);
_topShadow.moveToLeft(cWideMode() ? st::lineWidth : 0, 0);
_topShadow.resize(width() - ((cWideMode() && !_inGrab) ? st::lineWidth : 0), st::lineWidth);
_topShadow.moveToLeft((cWideMode() && !_inGrab) ? st::lineWidth : 0, 0);
_sideShadow.resize(st::lineWidth, height());
_sideShadow.moveToLeft(0, 0);
}
@@ -5481,7 +5482,7 @@ void HistoryWidget::updateBotKeyboard() {
if (hasMarkup || forceReply) {
if (_keyboard.singleUse() && _keyboard.hasMarkup() && _keyboard.forMsgId() == FullMsgId(_channel, _history->lastKeyboardId) && _history->lastKeyboardUsed) _kbWasHidden = true;
if (!isBotStart() && !isBlocked() && (wasVisible || _replyTo || (!_field.hasSendText() && !_kbWasHidden))) {
if (!_showAnim.animating()) {
if (!_a_show.animating()) {
if (hasMarkup) {
_kbScroll.show();
_attachEmoji.hide();
@@ -5504,7 +5505,7 @@ void HistoryWidget::updateBotKeyboard() {
_replyForwardPreviewCancel.show();
}
} else {
if (!_showAnim.animating()) {
if (!_a_show.animating()) {
_kbScroll.hide();
_attachEmoji.show();
_kbHide.hide();
@@ -5538,7 +5539,7 @@ void HistoryWidget::updateBotKeyboard() {
}
void HistoryWidget::updateToEndVisibility() {
bool toEndVisible = !_showAnim.animating() && _history && !_firstLoadRequest && (!_history->loadedAtBottom() || _replyReturn || _scroll.scrollTop() + st::wndMinHeight < _scroll.scrollTopMax());
bool toEndVisible = !_a_show.animating() && _history && !_firstLoadRequest && (!_history->loadedAtBottom() || _replyReturn || _scroll.scrollTop() + st::wndMinHeight < _scroll.scrollTopMax());
if (toEndVisible && _toHistoryEnd.isHidden()) {
_toHistoryEnd.show();
} else if (!toEndVisible && !_toHistoryEnd.isHidden()) {
@@ -5548,7 +5549,7 @@ void HistoryWidget::updateToEndVisibility() {
void HistoryWidget::updateCollapseCommentsVisibility() {
int32 collapseCommentsLeft = (width() - _collapseComments.width()) / 2, collapseCommentsTop = st::msgServiceMargin.top();
bool collapseCommentsVisible = !_showAnim.animating() && _history && !_firstLoadRequest && _history->isChannel() && !_history->asChannelHistory()->onlyImportant();
bool collapseCommentsVisible = !_a_show.animating() && _history && !_firstLoadRequest && _history->isChannel() && !_history->asChannelHistory()->onlyImportant();
if (collapseCommentsVisible) {
if (HistoryItem *collapse = _history->asChannelHistory()->collapse()) {
if (!collapse->detached()) {
@@ -5706,7 +5707,7 @@ void HistoryWidget::onStickerSend(DocumentData *sticker) {
void HistoryWidget::setFieldText(const QString &text) {
_synthedTextUpdate = true;
_field.setPlainText(text);
_field.setTextFast(text);
_synthedTextUpdate = false;
_previewCancelled = false;
@@ -5970,7 +5971,7 @@ void HistoryWidget::peerUpdated(PeerData *data) {
App::api()->requestFullPeer(data);
}
}
if (!_showAnim.animating()) {
if (!_a_show.animating()) {
bool resize = (_unblock.isHidden() == isBlocked() || (!isBlocked() && _joinChannel.isHidden() == isJoinChannel()));
bool newCanSendMessages = canSendMessages(_peer);
if (newCanSendMessages != _canSendMessages) {
@@ -6281,11 +6282,16 @@ void HistoryWidget::paintEvent(QPaintEvent *e) {
if (r != rect()) {
p.setClipRect(r);
}
if (_showAnim.animating()) {
p.setOpacity(a_bgAlpha.current());
p.drawPixmap(a_bgCoord.current(), 0, _bgAnimCache);
p.setOpacity(a_alpha.current());
p.drawPixmap(a_coord.current(), 0, _animCache);
if (_a_show.animating()) {
if (a_coordOver.current() > 0) {
p.drawPixmap(QRect(0, 0, a_coordOver.current(), height()), _cacheUnder, QRect(-a_coordUnder.current(), 0, a_coordOver.current(), height()));
p.setOpacity(a_shadow.current() * st::slideFadeOut);
p.fillRect(0, 0, a_coordOver.current(), height(), st::black->b);
p.setOpacity(1);
}
p.drawPixmap(a_coordOver.current(), 0, _cacheOver);
p.setOpacity(a_shadow.current());
p.drawPixmap(QRect(a_coordOver.current() - st::slideShadow.pxWidth(), 0, st::slideShadow.pxWidth(), height()), App::sprite(), st::slideShadow);
return;
}