Support new rounding in poll bottom button.
This commit is contained in:
		
							parent
							
								
									09ab83836f
								
							
						
					
					
						commit
						001c46f68a
					
				
					 4 changed files with 41 additions and 34 deletions
				
			
		|  | @ -1448,20 +1448,20 @@ void Message::toggleCommentsButtonRipple(bool pressed) { | |||
| 		if (!_comments->ripple) { | ||||
| 			createCommentsRipple(); | ||||
| 		} | ||||
| 		_comments->ripple->add(_comments->lastPoint); | ||||
| 		_comments->ripple->add(_comments->lastPoint | ||||
| 			+ QPoint(_comments->rippleShift, 0)); | ||||
| 	} else if (_comments->ripple) { | ||||
| 		_comments->ripple->lastStop(); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void Message::createCommentsRipple() { | ||||
| BottomRippleMask Message::bottomRippleMask(int buttonHeight) const { | ||||
| 	using namespace Ui; | ||||
| 	using namespace Images; | ||||
| 	using Radius = CachedCornerRadius; | ||||
| 	using Corner = BubbleCornerRounding; | ||||
| 	const auto g = countGeometry(); | ||||
| 	const auto linkWidth = g.width(); | ||||
| 	const auto linkHeight = st::historyCommentsButtonHeight; | ||||
| 	const auto buttonWidth = g.width(); | ||||
| 	const auto &large = CachedCornersMasks(Radius::BubbleLarge); | ||||
| 	const auto &small = CachedCornersMasks(Radius::BubbleSmall); | ||||
| 	const auto rounding = countBubbleRounding(); | ||||
|  | @ -1493,8 +1493,8 @@ void Message::createCommentsRipple() { | |||
| 				const auto height = image->height() / ratio; | ||||
| 				p.drawImage( | ||||
| 					QRect( | ||||
| 						shift + (right ? (linkWidth - width) : 0), | ||||
| 						linkHeight - height, | ||||
| 						shift + (right ? (buttonWidth - width) : 0), | ||||
| 						buttonHeight - height, | ||||
| 						width, | ||||
| 						height), | ||||
| 					*image); | ||||
|  | @ -1503,26 +1503,34 @@ void Message::createCommentsRipple() { | |||
| 		corner(kBottomLeft, false); | ||||
| 		corner(kBottomRight, true); | ||||
| 		if (icon) { | ||||
| 			const auto left = shift ? 0 : linkWidth; | ||||
| 			const auto left = shift ? 0 : buttonWidth; | ||||
| 			p.fillRect( | ||||
| 				QRect{ left, 0, added, linkHeight }, | ||||
| 				QRect{ left, 0, added, buttonHeight }, | ||||
| 				Qt::transparent); | ||||
| 			icon->paint( | ||||
| 				p, | ||||
| 				left, | ||||
| 				linkHeight - icon->height(), | ||||
| 				linkWidth + shift, | ||||
| 				buttonHeight - icon->height(), | ||||
| 				buttonWidth + shift, | ||||
| 				Qt::white); | ||||
| 		} | ||||
| 	}; | ||||
| 	_comments->ripple = std::make_unique<RippleAnimation>( | ||||
| 		st::defaultRippleAnimation, | ||||
| 	return { | ||||
| 		RippleAnimation::MaskByDrawer( | ||||
| 			QSize(linkWidth + added, linkHeight), | ||||
| 			QSize(buttonWidth + added, buttonHeight), | ||||
| 			true, | ||||
| 			drawer), | ||||
| 		shift, | ||||
| 	}; | ||||
| } | ||||
| 
 | ||||
| void Message::createCommentsRipple() { | ||||
| 	auto mask = bottomRippleMask(st::historyCommentsButtonHeight); | ||||
| 	_comments->ripple = std::make_unique<Ui::RippleAnimation>( | ||||
| 		st::defaultRippleAnimation, | ||||
| 		std::move(mask.image), | ||||
| 		[=] { repaint(); }); | ||||
| 	_comments->rippleShift = shift; | ||||
| 	_comments->rippleShift = mask.shift; | ||||
| } | ||||
| 
 | ||||
| bool Message::hasHeavyPart() const { | ||||
|  |  | |||
|  | @ -50,6 +50,11 @@ struct PsaTooltipState : public RuntimeComponent<PsaTooltipState, Element> { | |||
| 	mutable bool buttonVisible = true; | ||||
| }; | ||||
| 
 | ||||
| struct BottomRippleMask { | ||||
| 	QImage image; | ||||
| 	int shift = 0; | ||||
| }; | ||||
| 
 | ||||
| class Message final : public Element { | ||||
| public: | ||||
| 	Message( | ||||
|  | @ -148,6 +153,7 @@ public: | |||
| 		std::unique_ptr<Reactions::Animation>> override; | ||||
| 
 | ||||
| 	QRect innerGeometry() const override; | ||||
| 	[[nodiscard]] BottomRippleMask bottomRippleMask(int buttonHeight) const; | ||||
| 
 | ||||
| protected: | ||||
| 	void refreshDataIdHook() override; | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | |||
| #include "lang/lang_keys.h" | ||||
| #include "history/history.h" | ||||
| #include "history/history_item.h" | ||||
| #include "history/view/history_view_element.h" | ||||
| #include "history/view/history_view_message.h" | ||||
| #include "history/view/history_view_cursor_state.h" | ||||
| #include "calls/calls_instance.h" | ||||
| #include "ui/chat/message_bubble.h" | ||||
|  | @ -1568,30 +1568,20 @@ void Poll::toggleLinkRipple(bool pressed) { | |||
| 		const auto linkWidth = width(); | ||||
| 		const auto linkHeight = bottomButtonHeight(); | ||||
| 		if (!_linkRipple) { | ||||
| 			const auto drawMask = [&](QPainter &p) { | ||||
| 				// #TODO rounding
 | ||||
| 				const auto radius = st::bubbleRadiusSmall; | ||||
| 				p.drawRoundedRect( | ||||
| 					0, | ||||
| 					0, | ||||
| 					linkWidth, | ||||
| 					linkHeight, | ||||
| 					radius, | ||||
| 					radius); | ||||
| 				p.fillRect(0, 0, linkWidth, radius * 2, Qt::white); | ||||
| 			}; | ||||
| 			auto mask = isRoundedInBubbleBottom() | ||||
| 				? Ui::RippleAnimation::MaskByDrawer( | ||||
| 					QSize(linkWidth, linkHeight), | ||||
| 					false, | ||||
| 					drawMask) | ||||
| 				: Ui::RippleAnimation::RectMask({ linkWidth, linkHeight }); | ||||
| 				? static_cast<Message*>(_parent.get())->bottomRippleMask( | ||||
| 					bottomButtonHeight()) | ||||
| 				: BottomRippleMask{ | ||||
| 					Ui::RippleAnimation::RectMask({ linkWidth, linkHeight }), | ||||
| 				}; | ||||
| 			_linkRipple = std::make_unique<Ui::RippleAnimation>( | ||||
| 				st::defaultRippleAnimation, | ||||
| 				std::move(mask), | ||||
| 				std::move(mask.image), | ||||
| 				[=] { repaint(); }); | ||||
| 			_linkRippleShift = mask.shift; | ||||
| 		} | ||||
| 		_linkRipple->add(_lastLinkPoint - QPoint(0, height() - linkHeight)); | ||||
| 		_linkRipple->add(_lastLinkPoint | ||||
| 			+ QPoint(_linkRippleShift, linkHeight - height())); | ||||
| 	} else if (_linkRipple) { | ||||
| 		_linkRipple->lastStop(); | ||||
| 	} | ||||
|  |  | |||
|  | @ -23,6 +23,8 @@ class FireworksAnimation; | |||
| 
 | ||||
| namespace HistoryView { | ||||
| 
 | ||||
| class Message; | ||||
| 
 | ||||
| class Poll : public Media, public base::has_weak_ptr { | ||||
| public: | ||||
| 	Poll( | ||||
|  | @ -213,6 +215,7 @@ private: | |||
| 	ClickHandlerPtr _sendVotesLink; | ||||
| 	mutable ClickHandlerPtr _showSolutionLink; | ||||
| 	mutable std::unique_ptr<Ui::RippleAnimation> _linkRipple; | ||||
| 	mutable int _linkRippleShift = 0; | ||||
| 
 | ||||
| 	mutable std::unique_ptr<AnswersAnimation> _answersAnimation; | ||||
| 	mutable std::unique_ptr<SendingAnimation> _sendingAnimation; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston