Draw radial animation in a static method.
This commit is contained in:
		
							parent
							
								
									604f62599e
								
							
						
					
					
						commit
						21b976569a
					
				
					 2 changed files with 39 additions and 8 deletions
				
			
		|  | @ -144,7 +144,14 @@ void InfiniteRadialAnimation::draw( | ||||||
| 		QPainter &p, | 		QPainter &p, | ||||||
| 		QPoint position, | 		QPoint position, | ||||||
| 		int outerWidth) { | 		int outerWidth) { | ||||||
| 	draw(p, position, _st.size, outerWidth); | 	Draw( | ||||||
|  | 		p, | ||||||
|  | 		computeState(), | ||||||
|  | 		position, | ||||||
|  | 		_st.size, | ||||||
|  | 		outerWidth, | ||||||
|  | 		_st.color, | ||||||
|  | 		_st.thickness); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void InfiniteRadialAnimation::draw( | void InfiniteRadialAnimation::draw( | ||||||
|  | @ -152,8 +159,24 @@ void InfiniteRadialAnimation::draw( | ||||||
| 		QPoint position, | 		QPoint position, | ||||||
| 		QSize size, | 		QSize size, | ||||||
| 		int outerWidth) { | 		int outerWidth) { | ||||||
| 	const auto state = computeState(); | 	Draw( | ||||||
|  | 		p, | ||||||
|  | 		computeState(), | ||||||
|  | 		position, | ||||||
|  | 		size, | ||||||
|  | 		outerWidth, | ||||||
|  | 		_st.color, | ||||||
|  | 		_st.thickness); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
|  | void InfiniteRadialAnimation::Draw( | ||||||
|  | 		QPainter &p, | ||||||
|  | 		const RadialState &state, | ||||||
|  | 		QPoint position, | ||||||
|  | 		QSize size, | ||||||
|  | 		int outerWidth, | ||||||
|  | 		QPen pen, | ||||||
|  | 		int thickness) { | ||||||
| 	auto o = p.opacity(); | 	auto o = p.opacity(); | ||||||
| 	p.setOpacity(o * state.shown); | 	p.setOpacity(o * state.shown); | ||||||
| 
 | 
 | ||||||
|  | @ -166,10 +189,9 @@ void InfiniteRadialAnimation::draw( | ||||||
| 	const auto was = p.pen(); | 	const auto was = p.pen(); | ||||||
| 	const auto brush = p.brush(); | 	const auto brush = p.brush(); | ||||||
| 	if (anim::Disabled()) { | 	if (anim::Disabled()) { | ||||||
| 		anim::DrawStaticLoading(p, rect, _st.thickness, _st.color); | 		anim::DrawStaticLoading(p, rect, thickness, pen); | ||||||
| 	} else { | 	} else { | ||||||
| 		auto pen = _st.color->p; | 		pen.setWidth(thickness); | ||||||
| 		pen.setWidth(_st.thickness); |  | ||||||
| 		pen.setCapStyle(Qt::RoundCap); | 		pen.setCapStyle(Qt::RoundCap); | ||||||
| 		p.setPen(pen); | 		p.setPen(pen); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,10 +27,10 @@ public: | ||||||
| 	template <typename Callback> | 	template <typename Callback> | ||||||
| 	RadialAnimation(Callback &&callback); | 	RadialAnimation(Callback &&callback); | ||||||
| 
 | 
 | ||||||
| 	float64 opacity() const { | 	[[nodiscard]] float64 opacity() const { | ||||||
| 		return _opacity; | 		return _opacity; | ||||||
| 	} | 	} | ||||||
| 	bool animating() const { | 	[[nodiscard]] bool animating() const { | ||||||
| 		return _animation.animating(); | 		return _animation.animating(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -44,7 +44,7 @@ public: | ||||||
| 		int32 thickness, | 		int32 thickness, | ||||||
| 		style::color color) const; | 		style::color color) const; | ||||||
| 
 | 
 | ||||||
| 	RadialState computeState() const; | 	[[nodiscard]] RadialState computeState() const; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| 	crl::time _firstStart = 0; | 	crl::time _firstStart = 0; | ||||||
|  | @ -89,6 +89,15 @@ public: | ||||||
| 		QSize size, | 		QSize size, | ||||||
| 		int outerWidth); | 		int outerWidth); | ||||||
| 
 | 
 | ||||||
|  | 	static void Draw( | ||||||
|  | 		QPainter &p, | ||||||
|  | 		const RadialState &state, | ||||||
|  | 		QPoint position, | ||||||
|  | 		QSize size, | ||||||
|  | 		int outerWidth, | ||||||
|  | 		QPen pen, | ||||||
|  | 		int thickness); | ||||||
|  | 
 | ||||||
| 	[[nodiscard]] RadialState computeState(); | 	[[nodiscard]] RadialState computeState(); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston