Skip to content

Commit

Permalink
new slide animations
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 17, 2015
1 parent a945095 commit e211268
Show file tree
Hide file tree
Showing 33 changed files with 710 additions and 461 deletions.
9 changes: 5 additions & 4 deletions Telegram/Resources/style.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,11 @@ versionColor: #777;

shadowColor: rgba(0, 0, 0, 24);

slideDuration: 4000;
slideDuration: 240;
slideShift: 0.3;
slideShadowLeft: sprite(348px, 70px, 48px, 1px);
slideShadowRight: sprite(348px, 71px, 48px, 1px);
slideFadeOut: 0.3;
slideShadow: sprite(348px, 71px, 48px, 1px);
slideFunction: transition(easeOutCirc);

btnDefIconed: iconedButton {
color: white;
Expand Down Expand Up @@ -605,7 +606,7 @@ introPointHideAlphaT: transition(easeOutCirc);
introStepSize: size(400px, 200px);
introSize: size(400px, 400px);
introSlideShift: 500px; // intro hiding animation
introSlideDuration: 4000;
introSlideDuration: 200;
introSlideDelta: 0; // between hide start and show start
introHideFunc: transition(easeInCirc);
introShowFunc: transition(easeOutCirc);
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void Application::cancelPhotoUpdate(const PeerId &peer) {

void Application::mtpPause() {
MTP::pause();
_mtpUnpauseTimer.start(1000);
_mtpUnpauseTimer.start(st::slideDuration * 2);
}

void Application::mtpUnpause() {
Expand Down
Binary file modified Telegram/SourceFiles/art/sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Telegram/SourceFiles/art/sprite_200x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/boxes/abstractbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ AbstractBox::AbstractBox(int32 w) : LayeredWidget()

void AbstractBox::prepare() {
showAll();
_cache = myGrab(this, rect());
_cache = myGrab(this);
hideAll();
}

Expand Down Expand Up @@ -197,7 +197,7 @@ void AbstractBox::onClose() {
void AbstractBox::startHide() {
_hiding = true;
if (_cache.isNull()) {
_cache = myGrab(this, rect());
_cache = myGrab(this);
hideAll();
}
a_opacity.start(0);
Expand Down
66 changes: 40 additions & 26 deletions Telegram/SourceFiles/dialogswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,7 @@ DialogsWidget::DialogsWidget(MainWidget *parent) : TWidget(parent)
, _cancelSearch(this, st::btnCancelSearch)
, _scroll(this, st::dlgScroll)
, _inner(&_scroll, parent)
, _a_show(animFunc(this, &DialogsWidget::animStep_show))
, _searchInPeer(0)
, _searchFull(false)
, _peopleFull(false)
Expand Down Expand Up @@ -1574,41 +1575,49 @@ void DialogsWidget::dialogsToUp() {
void DialogsWidget::animShow(const QPixmap &bgAnimCache) {
if (App::app()) App::app()->mtpPause();

_bgAnimCache = bgAnimCache;
_animCache = myGrab(this, rect());
bool back = true;
(back ? _cacheOver : _cacheUnder) = bgAnimCache;

_a_show.stop();

(back ? _cacheUnder : _cacheOver) = myGrab(this);

_scroll.hide();
_filter.hide();
_cancelSearch.hide();
_newGroup.hide();
a_coord = anim::ivalue(-st::introSlideShift, 0);
a_alpha = anim::fvalue(0, 1);
a_bgCoord = anim::ivalue(0, st::introSlideShift);
a_bgAlpha = anim::fvalue(1, 0);
anim::start(this);

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();

show();
}

bool DialogsWidget::animStep(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 DialogsWidget::animStep_show(float64 ms) {
float64 dt = ms / st::slideDuration;
bool res = true;
if (dt2 >= 1) {
if (dt >= 1) {
_a_show.stop();

res = false;
a_bgCoord.finish();
a_bgAlpha.finish();
a_coord.finish();
a_alpha.finish();
_bgAnimCache = _animCache = QPixmap();
a_coordUnder.finish();
a_coordOver.finish();
a_shadow.finish();

_cacheUnder = _cacheOver = QPixmap();

_scroll.show();
_filter.show();
onFilterUpdate(true);
activate();

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();
return res;
Expand Down Expand Up @@ -2063,7 +2072,7 @@ void DialogsWidget::onListScroll() {
}

void DialogsWidget::onFilterUpdate(bool force) {
if (animating() && !force) return;
if (_a_show.animating() && !force) return;

QString filterText = _filter.getLastText();
_inner.onFilterUpdate(filterText);
Expand Down Expand Up @@ -2190,11 +2199,16 @@ void DialogsWidget::paintEvent(QPaintEvent *e) {
if (r != rect()) {
p.setClipRect(r);
}
if (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;
}
QRect above(0, 0, width(), _scroll.y());
Expand Down
11 changes: 6 additions & 5 deletions Telegram/SourceFiles/dialogswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public slots:

};

class DialogsWidget : public TWidget, public Animated, public RPCSender {
class DialogsWidget : public TWidget, public RPCSender {
Q_OBJECT

public:
Expand Down Expand Up @@ -208,7 +208,7 @@ class DialogsWidget : public TWidget, public Animated, public RPCSender {
void dialogsToUp();

void animShow(const QPixmap &bgAnimCache);
bool animStep(float64 ms);
bool animStep_show(float64 ms);

void destroyData();

Expand Down Expand Up @@ -271,9 +271,10 @@ public slots:
ScrollArea _scroll;
DialogsInner _inner;

QPixmap _animCache, _bgAnimCache;
anim::ivalue a_coord, a_bgCoord;
anim::fvalue a_alpha, a_bgAlpha;
Animation _a_show;
QPixmap _cacheUnder, _cacheOver;
anim::ivalue a_coordUnder, a_coordOver;
anim::fvalue a_shadow;

PeerData *_searchInPeer;

Expand Down
6 changes: 3 additions & 3 deletions Telegram/SourceFiles/dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@ void MentionsInner::onParentGeometryChanged() {
}
}

MentionsDropdown::MentionsDropdown(QWidget *parent) : QWidget(parent),
MentionsDropdown::MentionsDropdown(QWidget *parent) : TWidget(parent),
_scroll(this, st::mentionScroll), _inner(this, &_rows, &_hrows, &_crows), _chat(0), _user(0), _channel(0), _hiding(false), a_opacity(0), _shadow(st::dropdownDef.shadow) {
_hideTimer.setSingleShot(true);
connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(hideStart()));
Expand Down Expand Up @@ -3138,7 +3138,7 @@ void MentionsDropdown::hideStart() {
if (!_hiding) {
if (_cache.isNull()) {
_scroll.show();
_cache = myGrab(this, rect());
_cache = myGrab(this);
}
_scroll.hide();
_hiding = true;
Expand All @@ -3161,7 +3161,7 @@ void MentionsDropdown::showStart() {
}
if (_cache.isNull()) {
_scroll.show();
_cache = myGrab(this, rect());
_cache = myGrab(this);
}
_scroll.hide();
_hiding = false;
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/dropdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public slots:
bool _overDelete;
};

class MentionsDropdown : public QWidget, public Animated {
class MentionsDropdown : public TWidget, public Animated {
Q_OBJECT

public:
Expand Down
12 changes: 11 additions & 1 deletion Telegram/SourceFiles/gui/flattextarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ _touchPress(false), _touchRightButton(false), _touchMove(false), _correcting(fal
if (App::wnd()) connect(this, SIGNAL(selectionChanged()), App::wnd(), SLOT(updateGlobalMenu()));

if (!v.isEmpty()) {
setPlainText(v);
setTextFast(v);
}
}

void FlatTextarea::setTextFast(const QString &text) {
setPlainText(text);
if (animating()) {
a_phLeft.finish();
a_phAlpha.finish();
anim::stop(this);
update();
}
}

Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/gui/flattextarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class FlatTextarea : public QTextEdit, public Animated {
QMimeData *createMimeDataFromSelection() const;
void setCtrlEnterSubmit(bool ctrlEnterSubmit);

void setTextFast(const QString &text);

public slots:

void onTouchTimer();
Expand Down
10 changes: 8 additions & 2 deletions Telegram/SourceFiles/gui/twidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ void myEnsureResized(QWidget *target) {
}
}

QPixmap myGrab(QWidget *target, const QRect &rect) {
QPixmap myGrab(TWidget *target, QRect rect) {
myEnsureResized(target);
qreal dpr = App::app()->devicePixelRatio();
if (rect.isNull()) rect = target->rect();

qreal dpr = App::app()->devicePixelRatio();
QPixmap result(rect.size() * dpr);
result.setDevicePixelRatio(dpr);
result.fill(Qt::transparent);

target->grabStart();
target->render(&result, QPoint(), QRegion(rect), QWidget::DrawChildren | QWidget::IgnoreMask);
target->grabFinish();

return result;
}
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/gui/twidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,17 @@ class TWidget : public QWidget {
bool event(QEvent *e) {
return QWidget::event(e);
}
virtual void grabStart() {
}
virtual void grabFinish() {
}

private:

};

void myEnsureResized(QWidget *target);
QPixmap myGrab(QWidget *target, const QRect &rect);
QPixmap myGrab(TWidget *target, QRect rect = QRect());

class PlainShadow : public TWidget {
public:
Expand Down
Loading

0 comments on commit e211268

Please sign in to comment.