| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Easy2D - 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
 | 
					
						
							|  |  |  |  | #include "Node.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | #include "Font.hpp"
 | 
					
						
							|  |  |  |  | #include "TextStyle.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace easy2d | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	// <20>ı<EFBFBD>
 | 
					
						
							|  |  |  |  | 	class Text | 
					
						
							|  |  |  |  | 		: public Node | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-11-12 20:46:54 +08:00
										 |  |  |  | 		E2D_DISABLE_COPY(Text); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 	public: | 
					
						
							|  |  |  |  | 		Text(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		explicit Text( | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 			const String& text		/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */ | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		explicit Text( | 
					
						
							|  |  |  |  | 			const String& text,		/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */ | 
					
						
							|  |  |  |  | 			const Font& font		/* <20><><EFBFBD><EFBFBD> */ | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		explicit Text( | 
					
						
							|  |  |  |  | 			const String& text,		/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */ | 
					
						
							|  |  |  |  | 			const TextStyle& style	/* <20>ı<EFBFBD><C4B1><EFBFBD>ʽ */ | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		explicit Text( | 
					
						
							|  |  |  |  | 			const String& text,		/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */ | 
					
						
							|  |  |  |  | 			const Font& font,		/* <20><><EFBFBD><EFBFBD> */ | 
					
						
							|  |  |  |  | 			const TextStyle& style	/* <20>ı<EFBFBD><C4B1><EFBFBD>ʽ */ | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		virtual ~Text(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD>ı<EFBFBD>
 | 
					
						
							|  |  |  |  | 		const String& GetText() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		const Font& GetFont() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ʽ
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 		const TextStyle& GetStyle() const; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		const String& GetFontFamily() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ֺ<EFBFBD>
 | 
					
						
							|  |  |  |  | 		float GetFontSize() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸֵ
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 		unsigned int GetFontWeight() const; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
 | 
					
						
							|  |  |  |  | 		const Color& GetColor() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
 | 
					
						
							|  |  |  |  | 		const Color& GetOutlineColor() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD>
 | 
					
						
							|  |  |  |  | 		float GetOutlineWidth() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ཻ<EFBFBD><E0BDBB>ʽ
 | 
					
						
							| 
									
										
										
										
											2018-11-12 02:10:35 +08:00
										 |  |  |  | 		StrokeStyle GetOutlineStroke() const; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><>ȡ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-11-16 16:16:16 +08:00
										 |  |  |  | 		int GetLineCount(); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 16:16:16 +08:00
										 |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1>Χ<EFBFBD><CEA7>
 | 
					
						
							|  |  |  |  | 		virtual Rect GetBounds() override; | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		// <20>Ƿ<EFBFBD><C7B7><EFBFBD>б<EFBFBD><D0B1>
 | 
					
						
							|  |  |  |  | 		bool IsItalic() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʾɾ<CABE><C9BE><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 		bool HasStrikethrough() const; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ<EFBFBD>»<EFBFBD><C2BB><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 		bool HasUnderline() const; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 		bool HasOutline() const; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
 | 
					
						
							|  |  |  |  | 		void SetText( | 
					
						
							|  |  |  |  | 			const String& text | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ʽ
 | 
					
						
							|  |  |  |  | 		void SetStyle( | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 			const TextStyle& style | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		void SetFont( | 
					
						
							|  |  |  |  | 			const Font& font | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		void SetFontFamily( | 
					
						
							|  |  |  |  | 			const String& family | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ֺţ<D6BA>Ĭ<EFBFBD><C4AC>ֵΪ 22<32><32>
 | 
					
						
							|  |  |  |  | 		void SetFontSize( | 
					
						
							|  |  |  |  | 			float size | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸֵ<CFB8><D6B5>Ĭ<EFBFBD><C4AC>ֵΪ Text::Font::Weight::Normal<61><6C>
 | 
					
						
							|  |  |  |  | 		void SetFontWeight( | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 			unsigned int weight | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Ĭ<EFBFBD><C4AC>ֵΪ Color::WHITE<54><45>
 | 
					
						
							|  |  |  |  | 		void SetColor( | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 			Color const& color | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>壨Ĭ<E5A3A8><C4AC>ֵΪ false<73><65>
 | 
					
						
							|  |  |  |  | 		void SetItalic( | 
					
						
							| 
									
										
										
										
											2018-11-11 16:32:12 +08:00
										 |  |  |  | 			bool val | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><EFBFBD><F2BFAABB>ر<EFBFBD><D8B1>ı<EFBFBD><C4B1>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>У<EFBFBD>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD>رգ<D8B1>
 | 
					
						
							|  |  |  |  | 		void SetWrapEnabled( | 
					
						
							|  |  |  |  | 			bool wrap | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>еĿ<D0B5><C4BF>ȣ<EFBFBD>Ĭ<EFBFBD><C4AC>Ϊ 0<><30>
 | 
					
						
							|  |  |  |  | 		void SetWrapWidth( | 
					
						
							|  |  |  |  | 			float wrap_width | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC>ࣨĬ<E0A3A8><C4AC>Ϊ 0<><30>
 | 
					
						
							|  |  |  |  | 		void SetLineSpacing( | 
					
						
							|  |  |  |  | 			float line_spacing | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 		// <20><><EFBFBD>ö<EFBFBD><C3B6>뷽ʽ<EBB7BD><CABD>Ĭ<EFBFBD><C4AC>Ϊ TextAlign::Left<66><74>
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		void SetAlignment( | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 			TextAlign align | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>»<EFBFBD><C2BB>ߣ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵΪ false<73><65>
 | 
					
						
							|  |  |  |  | 		void SetUnderline( | 
					
						
							|  |  |  |  | 			bool underline | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ߣ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵΪ false<73><65>
 | 
					
						
							|  |  |  |  | 		void SetStrikethrough( | 
					
						
							|  |  |  |  | 			bool strikethrough | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		void SetOutline( | 
					
						
							|  |  |  |  | 			bool outline | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
 | 
					
						
							|  |  |  |  | 		void SetOutlineColor( | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 			Color const& outline_color | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD>
 | 
					
						
							|  |  |  |  | 		void SetOutlineWidth( | 
					
						
							|  |  |  |  | 			float outline_width | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ཻ<EFBFBD><E0BDBB>ʽ
 | 
					
						
							|  |  |  |  | 		void SetOutlineStroke( | 
					
						
							| 
									
										
										
										
											2018-11-12 02:10:35 +08:00
										 |  |  |  | 			StrokeStyle outline_stroke | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 14:35:19 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		static void SetDefaultFont( | 
					
						
							|  |  |  |  | 			Font const& font | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
 | 
					
						
							|  |  |  |  | 		static void SetDefaultStyle( | 
					
						
							|  |  |  |  | 			TextStyle const& style | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 		// <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-11-16 16:16:16 +08:00
										 |  |  |  | 		virtual void OnDraw() override; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	protected: | 
					
						
							|  |  |  |  | 		virtual void Update(Duration const& dt) override; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		void UpdateLayout(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	protected: | 
					
						
							|  |  |  |  | 		String				text_; | 
					
						
							|  |  |  |  | 		Font				font_; | 
					
						
							|  |  |  |  | 		TextStyle			style_; | 
					
						
							|  |  |  |  | 		bool				dirty_layout_; | 
					
						
							|  |  |  |  | 		IDWriteTextFormat*	text_format_; | 
					
						
							|  |  |  |  | 		IDWriteTextLayout*	text_layout_; | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 	}; | 
					
						
							|  |  |  |  | } |