| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2019-10-11 21:55:29 +08:00
										 |  |  |  | #include <kiwano/renderer/win32/D2DDeviceResources.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace kiwano | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	struct GradientStop | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-09-29 22:23:13 +08:00
										 |  |  |  | 		float offset; | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 		Color color; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		GradientStop() : offset(0.f), color() {} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 22:23:13 +08:00
										 |  |  |  | 		GradientStop(float offset, Color color) : offset(offset), color(color) {} | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
 | 
					
						
							|  |  |  |  | 	// <20><>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
 | 
					
						
							|  |  |  |  | 	// Clamp  (<28><>ģʽ): <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>Ʊ߽<C6B1><DFBD><EFBFBD>ɫ
 | 
					
						
							|  |  |  |  | 	// Wrap   (<28><>ģʽ): <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	// Mirror (<28><><EFBFBD><EFBFBD>ģʽ): <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	enum class GradientExtendMode | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		Clamp, | 
					
						
							|  |  |  |  | 		Wrap, | 
					
						
							|  |  |  |  | 		Mirror | 
					
						
							|  |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><>ɫ<EFBFBD><C9AB>ʽ
 | 
					
						
							|  |  |  |  | 	struct SolidColorStyle | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		Color color; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		SolidColorStyle(Color const& color); | 
					
						
							|  |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ʽ
 | 
					
						
							|  |  |  |  | 	struct LinearGradientStyle | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		Point begin; | 
					
						
							|  |  |  |  | 		Point end; | 
					
						
							|  |  |  |  | 		Vector<GradientStop> stops; | 
					
						
							|  |  |  |  | 		GradientExtendMode extend_mode; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		LinearGradientStyle( | 
					
						
							|  |  |  |  | 			Point const& begin, | 
					
						
							|  |  |  |  | 			Point const& end, | 
					
						
							|  |  |  |  | 			Vector<GradientStop> const& stops, | 
					
						
							|  |  |  |  | 			GradientExtendMode extend_mode = GradientExtendMode::Clamp | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><F2BDA5B1><EFBFBD>ʽ
 | 
					
						
							|  |  |  |  | 	struct RadialGradientStyle | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		Point center; | 
					
						
							|  |  |  |  | 		Vec2 offset; | 
					
						
							|  |  |  |  | 		Vec2 radius; | 
					
						
							|  |  |  |  | 		Vector<GradientStop> stops; | 
					
						
							|  |  |  |  | 		GradientExtendMode extend_mode; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		RadialGradientStyle( | 
					
						
							|  |  |  |  | 			Point const& center, | 
					
						
							|  |  |  |  | 			Vec2 const& offset, | 
					
						
							|  |  |  |  | 			Vec2 const& radius, | 
					
						
							|  |  |  |  | 			Vector<GradientStop> const& stops, | 
					
						
							|  |  |  |  | 			GradientExtendMode extend_mode = GradientExtendMode::Clamp | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 	/**
 | 
					
						
							|  |  |  |  | 	* \~chinese | 
					
						
							|  |  |  |  | 	* @brief <EFBFBD><EFBFBD>ˢ | 
					
						
							|  |  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 	class KGE_API Brush | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 	public: | 
					
						
							|  |  |  |  | 		Brush(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		Brush(Color const& color); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		Brush(SolidColorStyle const& style); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		Brush(LinearGradientStyle const& style); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		Brush(RadialGradientStyle const& style); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		bool IsValid() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		void SetColor(Color const& color); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		void SetStyle(SolidColorStyle const& style); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		void SetStyle(LinearGradientStyle const& style); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		void SetStyle(RadialGradientStyle const& style); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 22:23:13 +08:00
										 |  |  |  | 		float GetOpacity() const; | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 22:23:13 +08:00
										 |  |  |  | 		void SetOpacity(float opacity); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	public: | 
					
						
							|  |  |  |  | 		enum class Type | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			Unknown, | 
					
						
							|  |  |  |  | 			SolidColor,			// <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			LinearGradient,		// <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			RadialGradient		// <20><><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		Type GetType() const { return type_; } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 		Brush(ComPtr<ID2D1Brush> brush); | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		void SetBrush(ComPtr<ID2D1Brush> const& brush); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		inline ComPtr<ID2D1Brush> const& GetBrush() const { return raw_; } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-23 18:05:08 +08:00
										 |  |  |  | 	private: | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 		Type type_; | 
					
						
							| 
									
										
										
										
											2019-09-29 22:23:13 +08:00
										 |  |  |  | 		float opacity_; | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | 		ComPtr<ID2D1Brush> raw_; | 
					
						
							|  |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 10:51:34 +08:00
										 |  |  |  | 	inline void Brush::SetColor(Color const& color) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SetStyle(SolidColorStyle{ color }); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-09 22:02:53 +08:00
										 |  |  |  | } |