Use slide animation from lib_ui.
This commit is contained in:
		
							parent
							
								
									250b7240f6
								
							
						
					
					
						commit
						fcb2950ce8
					
				
					 4 changed files with 1 additions and 111 deletions
				
			
		|  | @ -1,53 +0,0 @@ | ||||||
| /*
 |  | ||||||
| This file is part of Telegram Desktop, |  | ||||||
| the official desktop application for the Telegram messaging service. |  | ||||||
| 
 |  | ||||||
| For license and copyright information please follow this link: |  | ||||||
| https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 |  | ||||||
| */ |  | ||||||
| #include "ui/effects/slide_animation.h" |  | ||||||
| 
 |  | ||||||
| namespace Ui { |  | ||||||
| 
 |  | ||||||
| void SlideAnimation::setSnapshots(QPixmap leftSnapshot, QPixmap rightSnapshot) { |  | ||||||
| 	_leftSnapshot = std::move(leftSnapshot); |  | ||||||
| 	_rightSnapshot = std::move(rightSnapshot); |  | ||||||
| 	Assert(!_leftSnapshot.isNull()); |  | ||||||
| 	Assert(!_rightSnapshot.isNull()); |  | ||||||
| 	_leftSnapshot.setDevicePixelRatio(cRetinaFactor()); |  | ||||||
| 	_rightSnapshot.setDevicePixelRatio(cRetinaFactor()); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void SlideAnimation::paintFrame(Painter &p, int x, int y, int outerWidth) { |  | ||||||
| 	auto dt = _animation.value(1.); |  | ||||||
| 	if (!animating()) return; |  | ||||||
| 
 |  | ||||||
| 	auto easeOut = anim::easeOutCirc(1., dt); |  | ||||||
| 	auto easeIn = anim::easeInCirc(1., dt); |  | ||||||
| 	auto arrivingAlpha = easeIn; |  | ||||||
| 	auto departingAlpha = 1. - easeOut; |  | ||||||
| 	auto leftCoord = (_slideLeft ? anim::interpolate(-_leftSnapshotWidth, 0, easeOut) : anim::interpolate(0, -_leftSnapshotWidth, easeIn)); |  | ||||||
| 	auto leftAlpha = (_slideLeft ? arrivingAlpha : departingAlpha); |  | ||||||
| 	auto rightCoord = (_slideLeft ? anim::interpolate(0, _rightSnapshotWidth, easeIn) : anim::interpolate(_rightSnapshotWidth, 0, easeOut)); |  | ||||||
| 	auto rightAlpha = (_slideLeft ? departingAlpha : arrivingAlpha); |  | ||||||
| 
 |  | ||||||
| 	if (_overflowHidden) { |  | ||||||
| 		auto leftWidth = (_leftSnapshotWidth + leftCoord); |  | ||||||
| 		if (leftWidth > 0) { |  | ||||||
| 			p.setOpacity(leftAlpha); |  | ||||||
| 			p.drawPixmap(x, y, leftWidth, _leftSnapshotHeight, _leftSnapshot, (_leftSnapshot.width() - leftWidth * cIntRetinaFactor()), 0, leftWidth * cIntRetinaFactor(), _leftSnapshot.height()); |  | ||||||
| 		} |  | ||||||
| 		auto rightWidth = _rightSnapshotWidth - rightCoord; |  | ||||||
| 		if (rightWidth > 0) { |  | ||||||
| 			p.setOpacity(rightAlpha); |  | ||||||
| 			p.drawPixmap(x + rightCoord, y, _rightSnapshot, 0, 0, rightWidth * cIntRetinaFactor(), _rightSnapshot.height()); |  | ||||||
| 		} |  | ||||||
| 	} else { |  | ||||||
| 		p.setOpacity(leftAlpha); |  | ||||||
| 		p.drawPixmap(x + leftCoord, y, _leftSnapshot); |  | ||||||
| 		p.setOpacity(rightAlpha); |  | ||||||
| 		p.drawPixmap(x + rightCoord, y, _rightSnapshot); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| } // namespace Ui
 |  | ||||||
|  | @ -1,55 +0,0 @@ | ||||||
| /*
 |  | ||||||
| This file is part of Telegram Desktop, |  | ||||||
| the official desktop application for the Telegram messaging service. |  | ||||||
| 
 |  | ||||||
| For license and copyright information please follow this link: |  | ||||||
| https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 |  | ||||||
| */ |  | ||||||
| #pragma once |  | ||||||
| 
 |  | ||||||
| #include "ui/effects/animations.h" |  | ||||||
| 
 |  | ||||||
| namespace Ui { |  | ||||||
| 
 |  | ||||||
| class SlideAnimation { |  | ||||||
| public: |  | ||||||
| 	void setSnapshots(QPixmap leftSnapshot, QPixmap rightSnapshot); |  | ||||||
| 
 |  | ||||||
| 	void setOverflowHidden(bool hidden) { |  | ||||||
| 		_overflowHidden = hidden; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	template <typename Lambda> |  | ||||||
| 	void start(bool slideLeft, Lambda &&updateCallback, float64 duration); |  | ||||||
| 
 |  | ||||||
| 	void paintFrame(Painter &p, int x, int y, int outerWidth); |  | ||||||
| 
 |  | ||||||
| 	bool animating() const { |  | ||||||
| 		return _animation.animating(); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| private: |  | ||||||
| 	Ui::Animations::Simple _animation; |  | ||||||
| 	QPixmap _leftSnapshot; |  | ||||||
| 	QPixmap _rightSnapshot; |  | ||||||
| 	bool _slideLeft = false; |  | ||||||
| 	bool _overflowHidden = true; |  | ||||||
| 	int _leftSnapshotWidth = 0; |  | ||||||
| 	int _leftSnapshotHeight = 0; |  | ||||||
| 	int _rightSnapshotWidth = 0; |  | ||||||
| 
 |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| template <typename Lambda> |  | ||||||
| void SlideAnimation::start(bool slideLeft, Lambda &&updateCallback, float64 duration) { |  | ||||||
| 	_slideLeft = slideLeft; |  | ||||||
| 	if (_slideLeft) { |  | ||||||
| 		std::swap(_leftSnapshot, _rightSnapshot); |  | ||||||
| 	} |  | ||||||
| 	_leftSnapshotWidth = _leftSnapshot.width() / cIntRetinaFactor(); |  | ||||||
| 	_leftSnapshotHeight = _leftSnapshot.height() / cIntRetinaFactor(); |  | ||||||
| 	_rightSnapshotWidth = _rightSnapshot.width() / cIntRetinaFactor(); |  | ||||||
| 	_animation.start(std::forward<Lambda>(updateCallback), 0., 1., duration); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| } // namespace Ui
 |  | ||||||
|  | @ -728,8 +728,6 @@ | ||||||
| <(src_loc)/ui/effects/round_checkbox.h | <(src_loc)/ui/effects/round_checkbox.h | ||||||
| <(src_loc)/ui/effects/send_action_animations.cpp | <(src_loc)/ui/effects/send_action_animations.cpp | ||||||
| <(src_loc)/ui/effects/send_action_animations.h | <(src_loc)/ui/effects/send_action_animations.h | ||||||
| <(src_loc)/ui/effects/slide_animation.cpp |  | ||||||
| <(src_loc)/ui/effects/slide_animation.h |  | ||||||
| <(src_loc)/ui/image/image.cpp | <(src_loc)/ui/image/image.cpp | ||||||
| <(src_loc)/ui/image/image.h | <(src_loc)/ui/image/image.h | ||||||
| <(src_loc)/ui/image/image_location.cpp | <(src_loc)/ui/image/image_location.cpp | ||||||
|  |  | ||||||
|  | @ -1 +1 @@ | ||||||
| Subproject commit 00393b7b3ba113a216d3704d47e0ca1cb97d0e6e | Subproject commit f7c3e22cc9d51e4bce0fe82e9eaa10cedc7bf5d5 | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston