Refactoring : UI Components
This commit is contained in:
		
							parent
							
								
									745bd994a8
								
							
						
					
					
						commit
						65ba8e96d2
					
				|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::Animate::Animate()  | ||||
| 	: frame_index_(0) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::JumpBy::JumpBy(float duration, const Point & vec, float height, int jumps) | ||||
| 	: FiniteTimeAction(duration) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::JumpTo::JumpTo(float duration, const Point & pos, float height, int jumps) | ||||
| 	: JumpBy(duration, Point(), height, jumps) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::MoveBy::MoveBy(float duration, Point vector) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::MoveTo::MoveTo(float duration, Point pos) | ||||
| 	: MoveBy(duration, Point()) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::OpacityBy::OpacityBy(float duration, float opacity) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::OpacityTo::OpacityTo(float duration, float opacity) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::RotateBy::RotateBy(float duration, float rotation) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::RotateTo::RotateTo(float duration, float rotation) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::ScaleBy::ScaleBy(float duration, float scale) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2daction.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::ScaleTo::ScaleTo(float duration, float scale) | ||||
| 	: ScaleBy(duration, 0, 0) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| #include "..\e2dmanager.h" | ||||
| 
 | ||||
| using namespace e2d; | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dtransition.h" | ||||
| #include "..\e2dmanager.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| #include <thread> | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| #include "..\e2dmanager.h" | ||||
| #pragma comment(lib, "dinput8.lib") | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dmanager.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::Renderer*		e2d::Renderer::instance_ = nullptr; | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dmanager.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include <imm.h> | ||||
| #pragma comment (lib ,"imm32.lib") | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dimpl.h" | ||||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dmanager.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::Collider::Collider(Node * parent) | ||||
| 	: visible_(true) | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| static const UINT sc_redShift = 16; | ||||
| static const UINT sc_greenShift = 8; | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| using namespace std::chrono; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| e2d::Font::Font() | ||||
| 	: family("") | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| e2d::Function::Function() | ||||
| 	: func_(nullptr) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dtool.h" | ||||
| 
 | ||||
| std::map<size_t, ID2D1Bitmap*> e2d::Image::bitmap_cache_; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include <cmath> | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| e2d::Rect::Rect(void) | ||||
| 	: origin() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| e2d::Ref::Ref() | ||||
| 	: ref_count_(0) | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::Resource::Resource(size_t resource_name, const String & resource_type) | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| e2d::Size::Size() | ||||
| { | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include <iomanip> | ||||
| #include <cwctype> | ||||
| #include <comutil.h> | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| using namespace std::chrono; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dimpl.h" | ||||
| #include "..\e2dcommon.h" | ||||
| #include "..\e2dutil.h" | ||||
| 
 | ||||
| e2d::VoiceCallback::VoiceCallback() | ||||
| { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\e2dmanager.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dtool.h" | ||||
| #include "..\e2dmodule.h" | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dmodule.h" | ||||
| 
 | ||||
| e2d::Canvas::Canvas(float width, float height) | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2devent.h" | ||||
| #include "..\e2dmanager.h" | ||||
| #include "..\e2daction.h" | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dmanager.h" | ||||
| 
 | ||||
| e2d::Scene::Scene() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dmodule.h" | ||||
| 
 | ||||
| e2d::Sprite::Sprite() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dmodule.h" | ||||
| 
 | ||||
| //-------------------------------------------------------
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::Data::Data(const String & key, const String & field) | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| #include "..\e2dmodule.h" | ||||
| #include <shobjidl.h>  | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| #include "..\e2dmodule.h" | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| #include "..\e2dmodule.h" | ||||
| #include <shlobj.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::Player * e2d::Player::instance_ = nullptr; | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| 
 | ||||
| std::default_random_engine &e2d::Random::GetEngine() | ||||
| { | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::Task::Task(const Function & func, const String & name) | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\e2dutil.h" | ||||
| #include "..\e2dtool.h" | ||||
| 
 | ||||
| 
 | ||||
| e2d::Timer * e2d::Timer::GetInstance() | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dtransition.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dmodule.h" | ||||
| 
 | ||||
| e2d::BoxTransition::BoxTransition(Scene* scene, float duration) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dtransition.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::EmergeTransition::EmergeTransition(Scene* scene, float duration) | ||||
| 	: Transition(scene, duration) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dtransition.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::FadeTransition::FadeTransition(Scene* scene, float duration) | ||||
| 	: Transition(scene, duration) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\e2dtransition.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| #include "..\e2dmodule.h" | ||||
| 
 | ||||
| e2d::MoveTransition::MoveTransition(Scene* scene, float duration, Direction direction) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\e2dmodule.h" | ||||
| #include "..\e2dtransition.h" | ||||
| #include "..\e2dcomponent.h" | ||||
| #include "..\e2dnode.h" | ||||
| 
 | ||||
| e2d::Transition::Transition(Scene* scene, float duration) | ||||
| 	: done_(false) | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #pragma once | ||||
| #include "e2dcommon.h" | ||||
| #include "e2dutil.h" | ||||
| #include "e2dmodule.h" | ||||
| 
 | ||||
| namespace e2d | ||||
|  |  | |||
							
								
								
									
										851
									
								
								core/e2dcommon.h
								
								
								
								
							
							
						
						
									
										851
									
								
								core/e2dcommon.h
								
								
								
								
							|  | @ -1,851 +0,0 @@ | |||
| #pragma once | ||||
| #include "e2dmacros.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| 
 | ||||
| // 方向
 | ||||
| enum class Direction : int | ||||
| { | ||||
| 	Up,			/* 上 */ | ||||
| 	Down,		/* 下 */ | ||||
| 	Left,		/* 左 */ | ||||
| 	Right		/* 右 */ | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 线条相交样式
 | ||||
| enum class Stroke : int | ||||
| { | ||||
| 	Miter = 0,	/* 斜切 */ | ||||
| 	Bevel = 1,	/* 斜角 */ | ||||
| 	Round = 2	/* 圆角 */ | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class Size; | ||||
| 
 | ||||
| // 坐标
 | ||||
| class Point | ||||
| { | ||||
| public: | ||||
| 	float x;	// X 坐标
 | ||||
| 	float y;	// Y 坐标
 | ||||
| 
 | ||||
| public: | ||||
| 	Point(); | ||||
| 
 | ||||
| 	Point( | ||||
| 		float x, | ||||
| 		float y | ||||
| 	); | ||||
| 
 | ||||
| 	Point( | ||||
| 		const Point& other | ||||
| 	); | ||||
| 
 | ||||
| 	Point operator + (const Point & other) const; | ||||
| 	Point operator - (const Point & other) const; | ||||
| 	Point operator * (float value) const; | ||||
| 	Point operator / (float value) const; | ||||
| 	Point operator - () const; | ||||
| 	bool operator== (const Point& other) const; | ||||
| 
 | ||||
| 	E2D_OP_EXPLICIT operator e2d::Size() const; | ||||
| 
 | ||||
| 	// 判断两点间距离
 | ||||
| 	static float Distance( | ||||
| 		const Point& p1, | ||||
| 		const Point& p2 | ||||
| 	); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 大小
 | ||||
| class Size | ||||
| { | ||||
| public: | ||||
| 	float width;	// 宽度
 | ||||
| 	float height;	// 高度
 | ||||
| 
 | ||||
| public: | ||||
| 	Size(); | ||||
| 
 | ||||
| 	Size( | ||||
| 		float width, | ||||
| 		float height | ||||
| 	); | ||||
| 
 | ||||
| 	Size( | ||||
| 		const Size& other | ||||
| 	); | ||||
| 
 | ||||
| 	Size operator + (const Size & other) const; | ||||
| 	Size operator - (const Size & other) const; | ||||
| 	Size operator * (float value) const; | ||||
| 	Size operator / (float value) const; | ||||
| 	Size operator - () const; | ||||
| 	bool operator== (const Size& other) const; | ||||
| 
 | ||||
| 	E2D_OP_EXPLICIT operator e2d::Point() const; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 矩形
 | ||||
| class Rect | ||||
| { | ||||
| public: | ||||
| 	Point origin;	// 原点坐标
 | ||||
| 	Size  size;		// 宽度和高度
 | ||||
| 
 | ||||
| public: | ||||
| 	Rect(); | ||||
| 	 | ||||
| 	Rect( | ||||
| 		float x, | ||||
| 		float y, | ||||
| 		float width, | ||||
| 		float height | ||||
| 	); | ||||
| 	 | ||||
| 	Rect( | ||||
| 		const Point& pos, | ||||
| 		const Size& size | ||||
| 	); | ||||
| 	 | ||||
| 	Rect( | ||||
| 		const Rect& other | ||||
| 	); | ||||
| 	 | ||||
| 	Rect& operator= (const Rect& other); | ||||
| 
 | ||||
| 	bool operator== (const Rect& rect) const; | ||||
| 	 | ||||
| 	// 判断点是否在矩形内
 | ||||
| 	bool ContainsPoint( | ||||
| 		const Point& point | ||||
| 	) const; | ||||
| 	 | ||||
| 	// 判断两矩形是否相交
 | ||||
| 	bool Intersects( | ||||
| 		const Rect& rect | ||||
| 	) const; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 字符串
 | ||||
| class String | ||||
| { | ||||
| public: | ||||
| 	String(); | ||||
| 
 | ||||
| 	String( | ||||
| 		const String & | ||||
| 	); | ||||
| 
 | ||||
| 	String( | ||||
| 		const char * | ||||
| 	); | ||||
| 
 | ||||
| 	String( | ||||
| 		const wchar_t * | ||||
| 	); | ||||
| 
 | ||||
| 	String( | ||||
| 		String && | ||||
| 	); | ||||
| 
 | ||||
| 	~String(); | ||||
| 
 | ||||
| 	// 获取字符串长度
 | ||||
| 	int GetLength() const; | ||||
| 
 | ||||
| 	// 获取该字符串的 Hash 值
 | ||||
| 	size_t GetHash() const; | ||||
| 
 | ||||
| 	// 判断字符串是否为空
 | ||||
| 	bool IsEmpty() const; | ||||
| 
 | ||||
| 	// 获取指定位置字符
 | ||||
| 	const wchar_t& At( | ||||
| 		size_t index | ||||
| 	) const; | ||||
| 
 | ||||
| 	// 比较字符串
 | ||||
| 	int Compare( | ||||
| 		const String & str | ||||
| 	) const; | ||||
| 
 | ||||
| 	// 截取字符串
 | ||||
| 	String Subtract( | ||||
| 		int offset,		/* 偏移量 */ | ||||
| 		int count = -1	/* 截取字符数量 */ | ||||
| 	) const; | ||||
| 
 | ||||
| 	// 插入字符串
 | ||||
| 	void Insert( | ||||
| 		const String & str, | ||||
| 		int pos | ||||
| 	); | ||||
| 
 | ||||
| 	// 替换字符串中的指定内容
 | ||||
| 	void Replace( | ||||
| 		const String & from,	/* 需替换内容 */ | ||||
| 		const String & to		/* 替换成内容 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 删除字符串中的指定内容
 | ||||
| 	void Erase( | ||||
| 		int offset,		/* 偏移量 */ | ||||
| 		int count		/* 删除字符数量 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 搜索字符串
 | ||||
| 	int Find( | ||||
| 		const String & str,	/* 查找内容 */ | ||||
| 		int offset = 0		/* 偏移量 */ | ||||
| 	) const; | ||||
| 
 | ||||
| 	// 清空字符串
 | ||||
| 	void Clear(); | ||||
| 
 | ||||
| 	// 获取大写字符串
 | ||||
| 	String ToUpper() const; | ||||
| 
 | ||||
| 	// 获取小写字符串
 | ||||
| 	String ToLower() const; | ||||
| 
 | ||||
| 	// 将字符串转化为 int 型
 | ||||
| 	int ToInt() const; | ||||
| 
 | ||||
| 	// 将字符串转化为 float 型
 | ||||
| 	float ToFloat() const; | ||||
| 
 | ||||
| 	// 将字符串转化为 double 型
 | ||||
| 	double ToDouble() const; | ||||
| 
 | ||||
| 	// 将字符串转化为 bool 型
 | ||||
| 	bool ToBool() const; | ||||
| 
 | ||||
| 	// 数字类型转字符串
 | ||||
| 	static String Parse(int value); | ||||
| 	static String Parse(unsigned int value); | ||||
| 	static String Parse(float value); | ||||
| 	static String Parse(double value); | ||||
| 
 | ||||
| 	// 格式化字符串
 | ||||
| 	static String Format(const char * format, ...); | ||||
| 	static String Format(const wchar_t * format, ...); | ||||
| 
 | ||||
| 	// 赋值运算符
 | ||||
| 	String& operator= (const String &); | ||||
| 	String& operator= (const char *); | ||||
| 	String& operator= (const wchar_t *); | ||||
| 
 | ||||
| 	// 运算符
 | ||||
| 	String& operator+= (const String &); | ||||
| 	String& operator+= (const char *); | ||||
| 	String& operator+= (const wchar_t *); | ||||
| 	String operator+ (const String &) const; | ||||
| 	String operator+ (const char *) const; | ||||
| 	String operator+ (const wchar_t *) const; | ||||
| 
 | ||||
| 	// 友元运算符
 | ||||
| 	friend String operator+ (const char *, const String &); | ||||
| 	friend String operator+ (const wchar_t*, const String &); | ||||
| 
 | ||||
| 	// 类型转换操作符
 | ||||
| 	E2D_OP_EXPLICIT operator const wchar_t* () const; | ||||
| 	E2D_OP_EXPLICIT operator wchar_t* () const; | ||||
| 	E2D_OP_EXPLICIT operator std::wstring () const; | ||||
| 	E2D_OP_EXPLICIT operator std::string () const; | ||||
| 
 | ||||
| 	// 比较运算符
 | ||||
| 	bool operator== (const String &) const; | ||||
| 	bool operator== (const char *) const; | ||||
| 	bool operator== (const wchar_t *) const; | ||||
| 	bool operator!= (const String &) const; | ||||
| 	bool operator!= (const char *) const; | ||||
| 	bool operator!= (const wchar_t *) const; | ||||
| 	bool operator> (const String &) const; | ||||
| 	bool operator>= (const String &) const; | ||||
| 	bool operator< (const String &) const; | ||||
| 	bool operator<= (const String &) const; | ||||
| 
 | ||||
| 	// << 运算符(后接字符串)
 | ||||
| 	String& operator<< (const String &); | ||||
| 	String& operator<< (const char *); | ||||
| 	String& operator<< (char *); | ||||
| 	String& operator<< (const wchar_t *); | ||||
| 	String& operator<< (wchar_t *); | ||||
| 	String& operator<< (int value); | ||||
| 	String& operator<< (unsigned int value); | ||||
| 	String& operator<< (float value); | ||||
| 	String& operator<< (double value); | ||||
| 
 | ||||
| 	// 其他运算符
 | ||||
| 	wchar_t& operator[] (size_t); | ||||
| 
 | ||||
| 	friend std::ostream& operator<< (std::ostream &, const String &); | ||||
| 	friend std::wostream& operator<< (std::wostream &, const String &); | ||||
| 
 | ||||
| 	friend std::istream& operator>> (std::istream &, String &); | ||||
| 	friend std::wistream& operator>> (std::wistream &, String &); | ||||
| 
 | ||||
| private: | ||||
| 	std::wstring string_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 颜色
 | ||||
| class Color | ||||
| { | ||||
| public: | ||||
| 	Color(); | ||||
| 
 | ||||
| 	Color( | ||||
| 		float r, | ||||
| 		float g, | ||||
| 		float b | ||||
| 	); | ||||
| 
 | ||||
| 	Color( | ||||
| 		float r, | ||||
| 		float g, | ||||
| 		float b, | ||||
| 		float alpha | ||||
| 	); | ||||
| 
 | ||||
| 	Color( | ||||
| 		UINT rgb | ||||
| 	); | ||||
| 
 | ||||
| 	Color( | ||||
| 		UINT rgb, | ||||
| 		float alpha | ||||
| 	); | ||||
| 
 | ||||
| 	Color( | ||||
| 		const D2D1_COLOR_F& color | ||||
| 	); | ||||
| 
 | ||||
| 	E2D_OP_EXPLICIT operator D2D1_COLOR_F() const; | ||||
| 
 | ||||
| public: | ||||
| 	enum Value : UINT | ||||
| 	{ | ||||
| 		Black = 0x000000, | ||||
| 		Blue = 0x0000FF, | ||||
| 		BlueViolet = 0x8A2BE2, | ||||
| 		Brown = 0xA52A2A, | ||||
| 		Chocolate = 0xD2691E, | ||||
| 		DarkBlue = 0x00008B, | ||||
| 		DarkGray = 0xA9A9A9, | ||||
| 		DarkGreen = 0x006400, | ||||
| 		DarkOrange = 0xFF8C00, | ||||
| 		DarkRed = 0x8B0000, | ||||
| 		DarkViolet = 0x9400D3, | ||||
| 		ForestGreen = 0x228B22, | ||||
| 		Gold = 0xFFD700, | ||||
| 		Gray = 0x808080, | ||||
| 		Green = 0x008000, | ||||
| 		GreenYellow = 0xADFF2F, | ||||
| 		LightBlue = 0xADD8E6, | ||||
| 		LightCyan = 0xE0FFFF, | ||||
| 		LightGreen = 0x90EE90, | ||||
| 		LightGray = 0xD3D3D3, | ||||
| 		LightPink = 0xFFB6C1, | ||||
| 		LightSeaGreen = 0x20B2AA, | ||||
| 		LightSkyBlue = 0x87CEFA, | ||||
| 		LightYellow = 0xFFFFE0, | ||||
| 		Orange = 0xFFA500, | ||||
| 		OrangeRed = 0xFF4500, | ||||
| 		Pink = 0xFFC0CB, | ||||
| 		Purple = 0x800080, | ||||
| 		Red = 0xFF0000, | ||||
| 		Silver = 0xC0C0C0, | ||||
| 		SkyBlue = 0x87CEEB, | ||||
| 		Snow = 0xFFFAFA, | ||||
| 		Violet = 0xEE82EE, | ||||
| 		Wheat = 0xF5DEB3, | ||||
| 		White = 0xFFFFFF, | ||||
| 		WhiteSmoke = 0xF5F5F5, | ||||
| 		Wood = 0xDEB887, | ||||
| 		Yellow = 0xFFFF00, | ||||
| 		Yellow_Green = 0x9ACD32 | ||||
| 	}; | ||||
| 
 | ||||
| public: | ||||
| 	float r; | ||||
| 	float g; | ||||
| 	float b; | ||||
| 	float a; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 键盘键值
 | ||||
| enum class KeyCode : int | ||||
| { | ||||
| 	Unknown = 0, | ||||
| 	Up = 0xC8, | ||||
| 	Left = 0xCB, | ||||
| 	Right = 0xCD, | ||||
| 	Down = 0xD0, | ||||
| 	Enter = 0x1C, | ||||
| 	Space = 0x39, | ||||
| 	Esc = 0x01, | ||||
| 	Q = 0x10, | ||||
| 	W = 0x11, | ||||
| 	E = 0x12, | ||||
| 	R = 0x13, | ||||
| 	T = 0x14, | ||||
| 	Y = 0x15, | ||||
| 	U = 0x16, | ||||
| 	I = 0x17, | ||||
| 	O = 0x18, | ||||
| 	P = 0x19, | ||||
| 	A = 0x1E, | ||||
| 	S = 0x1F, | ||||
| 	D = 0x20, | ||||
| 	F = 0x21, | ||||
| 	G = 0x22, | ||||
| 	H = 0x23, | ||||
| 	J = 0x24, | ||||
| 	K = 0x25, | ||||
| 	L = 0x26, | ||||
| 	Z = 0x2C, | ||||
| 	X = 0x2D, | ||||
| 	C = 0x2E, | ||||
| 	V = 0x2F, | ||||
| 	B = 0x30, | ||||
| 	N = 0x31, | ||||
| 	M = 0x32, | ||||
| 	Num1 = 0x02, | ||||
| 	Num2 = 0x03, | ||||
| 	Num3 = 0x04, | ||||
| 	Num4 = 0x05, | ||||
| 	Num5 = 0x06, | ||||
| 	Num6 = 0x07, | ||||
| 	Num7 = 0x08, | ||||
| 	Num8 = 0x09, | ||||
| 	Num9 = 0x0A, | ||||
| 	Num0 = 0x0B, | ||||
| 	Numpad7 = 0x47, | ||||
| 	Numpad8 = 0x48, | ||||
| 	Numpad9 = 0x49, | ||||
| 	Numpad4 = 0x4B, | ||||
| 	Numpad5 = 0x4C, | ||||
| 	Numpad6 = 0x4D, | ||||
| 	Numpad1 = 0x4F, | ||||
| 	Numpad2 = 0x50, | ||||
| 	Numpad3 = 0x51, | ||||
| 	Numpad0 = 0x52, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标键值
 | ||||
| enum class MouseCode : int | ||||
| { | ||||
| 	Left,		/* 鼠标左键 */ | ||||
| 	Right,		/* 鼠标右键 */ | ||||
| 	Middle		/* 鼠标中键 */ | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 函数对象
 | ||||
| class Function | ||||
| { | ||||
| public: | ||||
| 	Function(); | ||||
| 
 | ||||
| 	Function( | ||||
| 		std::nullptr_t | ||||
| 	); | ||||
| 
 | ||||
| 	Function( | ||||
| 		std::function<void()> func | ||||
| 	); | ||||
| 
 | ||||
| 	template<typename Func> | ||||
| 	Function(Func func) : func_(func) {} | ||||
| 
 | ||||
| 	template<typename Func, typename Object> | ||||
| 	Function( | ||||
| 		Func&& func,	/* 对象的成员函数 */ | ||||
| 		Object&& obj	/* 对象指针 */ | ||||
| 	) | ||||
| 	{ | ||||
| 		func_ = std::bind(func, obj); | ||||
| 	} | ||||
| 
 | ||||
| 	void operator() (void) const; | ||||
| 
 | ||||
| 	E2D_OP_EXPLICIT operator bool() const; | ||||
| 
 | ||||
| protected: | ||||
| 	std::function<void()> func_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 时间段
 | ||||
| class Duration | ||||
| { | ||||
| public: | ||||
| 	Duration(); | ||||
| 
 | ||||
| 	explicit Duration( | ||||
| 		float seconds | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取毫秒数
 | ||||
| 	int Milliseconds() const; | ||||
| 
 | ||||
| 	// 获取秒数
 | ||||
| 	float Seconds() const; | ||||
| 
 | ||||
| 	bool operator== (const Duration &) const; | ||||
| 	bool operator!= (const Duration &) const; | ||||
| 	bool operator> (const Duration &) const; | ||||
| 	bool operator>= (const Duration &) const; | ||||
| 	bool operator< (const Duration &) const; | ||||
| 	bool operator<= (const Duration &) const; | ||||
| 
 | ||||
| 	Duration operator + (Duration const &) const; | ||||
| 	Duration operator - (Duration const &) const; | ||||
| 
 | ||||
| 	Duration& operator += (Duration const &); | ||||
| 	Duration& operator -= (Duration const &); | ||||
| 
 | ||||
| protected: | ||||
| 	std::chrono::milliseconds duration_ms_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 时间点
 | ||||
| class Time | ||||
| { | ||||
| public: | ||||
| 	Time(); | ||||
| 
 | ||||
| 	// 获取时间戳
 | ||||
| 	time_t GetTimeStamp() const; | ||||
| 
 | ||||
| 	// 是否是
 | ||||
| 	bool IsZero() const; | ||||
| 
 | ||||
| 	Time operator + (Duration const &) const; | ||||
| 	Time operator - (Duration const &) const; | ||||
| 
 | ||||
| 	Time& operator += (Duration const &); | ||||
| 	Time& operator -= (Duration const &); | ||||
| 	 | ||||
| 	Duration operator - (Time const &) const; | ||||
| 
 | ||||
| 	// 获取当前时间
 | ||||
| 	static Time Now(); | ||||
| 
 | ||||
| protected: | ||||
| 	std::chrono::steady_clock::time_point time_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 字体
 | ||||
| class Font | ||||
| { | ||||
| public: | ||||
| 	String	family;			// 字体族
 | ||||
| 	float	size;			// 字号
 | ||||
| 	UINT	weight;			// 粗细值
 | ||||
| 	bool	italic;			// 是否斜体
 | ||||
| 
 | ||||
| public: | ||||
| 	// 字体粗细值
 | ||||
| 	enum Weight : UINT | ||||
| 	{ | ||||
| 		Thin = 100, | ||||
| 		ExtraLight = 200, | ||||
| 		Light = 300, | ||||
| 		Normal = 400, | ||||
| 		Medium = 500, | ||||
| 		Bold = 700, | ||||
| 		ExtraBold = 800, | ||||
| 		Black = 900, | ||||
| 		ExtraBlack = 950 | ||||
| 	}; | ||||
| 
 | ||||
| public: | ||||
| 	Font(); | ||||
| 
 | ||||
| 	explicit Font( | ||||
| 		const String& family, | ||||
| 		float size = 22, | ||||
| 		UINT weight = Font::Weight::Normal, | ||||
| 		bool italic = false | ||||
| 	); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class Node; | ||||
| 
 | ||||
| // 碰撞体
 | ||||
| class Collider | ||||
| { | ||||
| public: | ||||
| 	// 碰撞体形状
 | ||||
| 	enum class Shape | ||||
| 	{ | ||||
| 		None,		/* 无 */ | ||||
| 		Rect,		/* 矩形 */ | ||||
| 		Circle,		/* 圆形 */ | ||||
| 		Ellipse		/* 椭圆形 */ | ||||
| 	}; | ||||
| 
 | ||||
| 	// 碰撞体交集关系
 | ||||
| 	enum class Relation : int | ||||
| 	{ | ||||
| 		Unknown = 0,		/* 关系不确定 */ | ||||
| 		Disjoin = 1,		/* 没有交集 */ | ||||
| 		IsContained = 2,	/* 完全被包含 */ | ||||
| 		Contains = 3,		/* 完全包含 */ | ||||
| 		Overlap = 4			/* 部分重叠 */ | ||||
| 	}; | ||||
| 
 | ||||
| public: | ||||
| 	explicit Collider( | ||||
| 		Node * parent | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Collider(); | ||||
| 
 | ||||
| 	// 设置碰撞体形状
 | ||||
| 	void SetShape( | ||||
| 		Shape shape | ||||
| 	); | ||||
| 
 | ||||
| 	// 是否触发碰撞事件
 | ||||
| 	void SetCollisionNotify( | ||||
| 		bool notify | ||||
| 	); | ||||
| 
 | ||||
| 	// 启用或关闭该碰撞体
 | ||||
| 	void SetEnabled( | ||||
| 		bool enabled | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置碰撞体的可见性
 | ||||
| 	void SetVisible( | ||||
| 		bool visible | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置绘制颜色
 | ||||
| 	void SetBorderColor( | ||||
| 		const Color& color | ||||
| 	); | ||||
| 
 | ||||
| 	// 判断两碰撞体的交集关系
 | ||||
| 	Relation GetRelationWith( | ||||
| 		Collider * collider | ||||
| 	) const; | ||||
| 
 | ||||
| 	// 是否启用碰撞体
 | ||||
| 	bool IsEnabled() const; | ||||
| 
 | ||||
| 	// 是否可见
 | ||||
| 	bool IsVisible() const; | ||||
| 
 | ||||
| 	// 是否触发碰撞事件
 | ||||
| 	bool IsCollisionNotify() const; | ||||
| 
 | ||||
| 	// 获取绘制颜色
 | ||||
| 	const Color& GetBorderColor() const; | ||||
| 
 | ||||
| 	// 获取形状
 | ||||
| 	Shape GetShape() const; | ||||
| 
 | ||||
| 	// 获取绑定节点
 | ||||
| 	Node* GetNode() const; | ||||
| 
 | ||||
| 	// 获取 ID2D1Geometry* 对象
 | ||||
| 	ID2D1Geometry* GetGeometry() const; | ||||
| 
 | ||||
| 	// 重新生成
 | ||||
| 	void Recreate(); | ||||
| 
 | ||||
| 	// 渲染碰撞体
 | ||||
| 	void Draw(); | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Collider); | ||||
| 
 | ||||
| protected: | ||||
| 	bool	enabled_; | ||||
| 	bool	visible_; | ||||
| 	bool	notify_; | ||||
| 	Color	border_color_; | ||||
| 	Node *	parent_node_; | ||||
| 	Shape	shape_; | ||||
| 	ID2D1Geometry* geometry_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 资源
 | ||||
| class Resource | ||||
| { | ||||
| public: | ||||
| 	Resource( | ||||
| 		size_t resource_name,			/* 资源名称 */ | ||||
| 		const String& resource_type		/* 资源类型 */ | ||||
| 	); | ||||
| 
 | ||||
| public: | ||||
| 	size_t	name; | ||||
| 	String	type; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 引用计数对象
 | ||||
| class Ref | ||||
| { | ||||
| public: | ||||
| 	Ref(); | ||||
| 
 | ||||
| 	virtual ~Ref(); | ||||
| 
 | ||||
| 	// 增加引用计数
 | ||||
| 	void Retain(); | ||||
| 
 | ||||
| 	// 减少引用计数
 | ||||
| 	void Release(); | ||||
| 
 | ||||
| 	// 获取引用计数
 | ||||
| 	int GetRefCount() const; | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Ref); | ||||
| 
 | ||||
| private: | ||||
| 	int ref_count_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 图片
 | ||||
| class Image : | ||||
| 	public Ref | ||||
| { | ||||
| public: | ||||
| 	Image(); | ||||
| 
 | ||||
| 	explicit Image( | ||||
| 		const Resource& res | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Image( | ||||
| 		const Resource& res, | ||||
| 		const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Image( | ||||
| 		const String& file_name | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Image( | ||||
| 		const String& file_name, | ||||
| 		const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Image(); | ||||
| 
 | ||||
| 	// 加载图片资源
 | ||||
| 	bool Open( | ||||
| 		const Resource& res | ||||
| 	); | ||||
| 
 | ||||
| 	// 加载图片资源
 | ||||
| 	bool Open( | ||||
| 		const String& file_name | ||||
| 	); | ||||
| 
 | ||||
| 	// 将图片裁剪为矩形
 | ||||
| 	void Crop( | ||||
| 		const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取宽度
 | ||||
| 	virtual float GetWidth() const; | ||||
| 
 | ||||
| 	// 获取高度
 | ||||
| 	virtual float GetHeight() const; | ||||
| 
 | ||||
| 	// 获取大小
 | ||||
| 	virtual Size GetSize() const; | ||||
| 
 | ||||
| 	// 获取源图片宽度
 | ||||
| 	virtual float GetSourceWidth() const; | ||||
| 
 | ||||
| 	// 获取源图片高度
 | ||||
| 	virtual float GetSourceHeight() const; | ||||
| 
 | ||||
| 	// 获取源图片大小
 | ||||
| 	virtual Size GetSourceSize() const; | ||||
| 	 | ||||
| 	// 获取裁剪位置 X 坐标
 | ||||
| 	virtual float GetCropX() const; | ||||
| 
 | ||||
| 	// 获取裁剪位置 Y 坐标
 | ||||
| 	virtual float GetCropY() const; | ||||
| 
 | ||||
| 	// 获取裁剪位置
 | ||||
| 	virtual Point GetCropPos() const; | ||||
| 
 | ||||
| 	// 获取 ID2D1Bitmap 对象
 | ||||
| 	ID2D1Bitmap * GetBitmap(); | ||||
| 
 | ||||
| 	// 预加载图片资源
 | ||||
| 	static bool Preload( | ||||
| 		const String& file_name | ||||
| 	); | ||||
| 
 | ||||
| 	// 预加载图片资源
 | ||||
| 	static bool Preload( | ||||
| 		const Resource& res | ||||
| 	); | ||||
| 
 | ||||
| 	// 清空缓存
 | ||||
| 	static void ClearCache(); | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Image); | ||||
| 
 | ||||
| 	// 设置 Bitmap
 | ||||
| 	void SetBitmap( | ||||
| 		ID2D1Bitmap * bitmap | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	Rect crop_rect_; | ||||
| 	ID2D1Bitmap * bitmap_; | ||||
| 
 | ||||
| 	static std::map<size_t, ID2D1Bitmap*> bitmap_cache_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 	struct autorelease_t { }; | ||||
| 
 | ||||
| 	extern autorelease_t const autorelease; | ||||
| } | ||||
| 
 | ||||
| void* operator new( | ||||
| 	size_t size, | ||||
| 	e2d::autorelease_t const& | ||||
| 	) E2D_NOEXCEPT; | ||||
| 
 | ||||
| void operator delete( | ||||
| 	void* block, | ||||
| 	e2d::autorelease_t const& | ||||
| 	) E2D_NOEXCEPT; | ||||
|  | @ -1,820 +1,10 @@ | |||
| #pragma once | ||||
| #include "e2dcommon.h" | ||||
| #include "e2devent.h" | ||||
| #include "e2dnode.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| 
 | ||||
| class Action; | ||||
| class Scene; | ||||
| 
 | ||||
| 
 | ||||
| // 绘图接口
 | ||||
| class Drawable | ||||
| { | ||||
| public: | ||||
| 	// 渲染图形
 | ||||
| 	virtual void Draw() const = 0; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 更新接口
 | ||||
| class Updatable | ||||
| { | ||||
| public: | ||||
| 	// 渲染图形
 | ||||
| 	virtual void Update() = 0; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 按键消息处理接口
 | ||||
| class KeyEventHandler | ||||
| { | ||||
| public: | ||||
| 	// 处理按键消息
 | ||||
| 	virtual void Handle(KeyEvent e) = 0; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标消息处理接口
 | ||||
| class MouseEventHandler | ||||
| { | ||||
| public: | ||||
| 	// 处理鼠标消息
 | ||||
| 	virtual void Handle(MouseEvent e) = 0; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 碰撞消息处理接口
 | ||||
| class CollisionHandler | ||||
| { | ||||
| public: | ||||
| 	// 处理碰撞消息
 | ||||
| 	virtual void Handle(Collision collision) = 0; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 节点
 | ||||
| class Node : | ||||
| 	public Ref | ||||
| { | ||||
| 	friend class Collider; | ||||
| 
 | ||||
| public: | ||||
| 	// 节点属性
 | ||||
| 	struct Property | ||||
| 	{ | ||||
| 		Point pos;			// 坐标
 | ||||
| 		Size size;			// 大小
 | ||||
| 		Point anchor;		// 锚点坐标
 | ||||
| 		Point scale;		// 缩放
 | ||||
| 		Point skew;			// 倾斜角度
 | ||||
| 		float rotation;		// 旋转角度
 | ||||
| 
 | ||||
| 		Property operator+ (Property const & prop) const; | ||||
| 		Property operator- (Property const & prop) const; | ||||
| 
 | ||||
| 		static const Property Origin; | ||||
| 	}; | ||||
| 
 | ||||
| public: | ||||
| 	typedef std::vector<Node*> Nodes; | ||||
| 	typedef std::vector<Action*> Actions; | ||||
| 
 | ||||
| 	Node(); | ||||
| 
 | ||||
| 	virtual ~Node(); | ||||
| 
 | ||||
| 	// 获取节点显示状态
 | ||||
| 	bool IsVisible() const; | ||||
| 
 | ||||
| 	// 获取节点名称
 | ||||
| 	const String& GetName() const; | ||||
| 
 | ||||
| 	// 获取节点名称的 Hash 值
 | ||||
| 	size_t GetHashName() const; | ||||
| 
 | ||||
| 	// 获取节点绘图顺序
 | ||||
| 	int GetOrder() const; | ||||
| 
 | ||||
| 	// 获取节点横坐标
 | ||||
| 	float GetPosX() const; | ||||
| 
 | ||||
| 	// 获取节点纵坐标
 | ||||
| 	float GetPosY() const; | ||||
| 
 | ||||
| 	// 获取节点坐标
 | ||||
| 	Point GetPos() const; | ||||
| 
 | ||||
| 	// 获取节点宽度
 | ||||
| 	float GetWidth() const; | ||||
| 
 | ||||
| 	// 获取节点高度
 | ||||
| 	float GetHeight() const; | ||||
| 
 | ||||
| 	// 获取节点宽度(不考虑缩放)
 | ||||
| 	float GetRealWidth() const; | ||||
| 
 | ||||
| 	// 获取节点高度(不考虑缩放)
 | ||||
| 	float GetRealHeight() const; | ||||
| 
 | ||||
| 	// 获取节点大小(不考虑缩放)
 | ||||
| 	Size GetRealSize() const; | ||||
| 
 | ||||
| 	// 获取节点的锚点
 | ||||
| 	float GetAnchorX() const; | ||||
| 
 | ||||
| 	// 获取节点的锚点
 | ||||
| 	float GetAnchorY() const; | ||||
| 
 | ||||
| 	// 获取节点大小
 | ||||
| 	Size GetSize() const; | ||||
| 
 | ||||
| 	// 获取节点横向缩放比例
 | ||||
| 	float GetScaleX() const; | ||||
| 
 | ||||
| 	// 获取节点纵向缩放比例
 | ||||
| 	float GetScaleY() const; | ||||
| 
 | ||||
| 	// 获取节点横向倾斜角度
 | ||||
| 	float GetSkewX() const; | ||||
| 
 | ||||
| 	// 获取节点纵向倾斜角度
 | ||||
| 	float GetSkewY() const; | ||||
| 
 | ||||
| 	// 获取节点旋转角度
 | ||||
| 	float GetRotation() const; | ||||
| 
 | ||||
| 	// 获取节点透明度
 | ||||
| 	float GetOpacity() const; | ||||
| 
 | ||||
| 	// 获取节点属性
 | ||||
| 	Property GetProperty() const; | ||||
| 
 | ||||
| 	// 获取差别属性
 | ||||
| 	Property GetExtrapolate() const; | ||||
| 
 | ||||
| 	// 获取节点碰撞体
 | ||||
| 	Collider * GetCollider(); | ||||
| 
 | ||||
| 	// 获取父节点
 | ||||
| 	Node * GetParent() const; | ||||
| 
 | ||||
| 	// 获取节点所在场景
 | ||||
| 	Scene * GetParentScene() const; | ||||
| 
 | ||||
| 	// 设置节点是否显示
 | ||||
| 	void SetVisible( | ||||
| 		bool value | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点名称
 | ||||
| 	void SetName( | ||||
| 		const String& name | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点横坐标
 | ||||
| 	virtual void SetPosX( | ||||
| 		float x | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点纵坐标
 | ||||
| 	virtual void SetPosY( | ||||
| 		float y | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点坐标
 | ||||
| 	virtual void SetPos( | ||||
| 		const Point & point | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点坐标
 | ||||
| 	virtual void SetPos( | ||||
| 		float x, | ||||
| 		float y | ||||
| 	); | ||||
| 
 | ||||
| 	// 节点坐标固定
 | ||||
| 	virtual void SetPosFixed( | ||||
| 		bool fixed | ||||
| 	); | ||||
| 
 | ||||
| 	// 移动节点
 | ||||
| 	virtual void Move( | ||||
| 		float x, | ||||
| 		float y | ||||
| 	); | ||||
| 
 | ||||
| 	// 移动节点
 | ||||
| 	virtual void Move( | ||||
| 		const Point & v | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点绘图顺序
 | ||||
| 	// 默认为 0
 | ||||
| 	virtual void SetOrder( | ||||
| 		int order | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置横向缩放比例
 | ||||
| 	// 默认为 1.0
 | ||||
| 	virtual void SetScaleX( | ||||
| 		float scale_x | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置纵向缩放比例
 | ||||
| 	// 默认为 1.0
 | ||||
| 	virtual void SetScaleY( | ||||
| 		float scale_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置缩放比例
 | ||||
| 	// 默认为 (1.0, 1.0)
 | ||||
| 	virtual void SetScale( | ||||
| 		float scale_x, | ||||
| 		float scale_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置缩放比例
 | ||||
| 	// 默认为 1.0
 | ||||
| 	virtual void SetScale( | ||||
| 		float scale | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置横向倾斜角度
 | ||||
| 	// 默认为 0
 | ||||
| 	virtual void SetSkewX( | ||||
| 		float skew_x | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置纵向倾斜角度
 | ||||
| 	// 默认为 0
 | ||||
| 	virtual void SetSkewY( | ||||
| 		float skew_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置倾斜角度
 | ||||
| 	// 默认为 (0, 0)
 | ||||
| 	virtual void SetSkew( | ||||
| 		float skew_x, | ||||
| 		float skew_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置旋转角度
 | ||||
| 	// 默认为 0
 | ||||
| 	virtual void SetRotation( | ||||
| 		float rotation | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置透明度
 | ||||
| 	// 默认为 1.0, 范围 [0, 1]
 | ||||
| 	virtual void SetOpacity( | ||||
| 		float opacity | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置锚点的横向位置
 | ||||
| 	// 默认为 0, 范围 [0, 1]
 | ||||
| 	virtual void SetAnchorX( | ||||
| 		float anchor_x | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置锚点的纵向位置
 | ||||
| 	// 默认为 0, 范围 [0, 1]
 | ||||
| 	virtual void SetAnchorY( | ||||
| 		float anchor_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置锚点位置
 | ||||
| 	// 默认为 (0, 0), 范围 [0, 1]
 | ||||
| 	virtual void SetAnchor( | ||||
| 		float anchor_x, | ||||
| 		float anchor_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 修改节点宽度
 | ||||
| 	virtual void SetWidth( | ||||
| 		float width | ||||
| 	); | ||||
| 
 | ||||
| 	// 修改节点高度
 | ||||
| 	virtual void SetHeight( | ||||
| 		float height | ||||
| 	); | ||||
| 
 | ||||
| 	// 修改节点大小
 | ||||
| 	virtual void SetSize( | ||||
| 		float width, | ||||
| 		float height | ||||
| 	); | ||||
| 
 | ||||
| 	// 修改节点大小
 | ||||
| 	virtual void SetSize( | ||||
| 		Size size | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点属性
 | ||||
| 	virtual void SetProperty( | ||||
| 		Property prop | ||||
| 	); | ||||
| 
 | ||||
| 	// 启用或关闭渲染区域裁剪
 | ||||
| 	virtual void SetClipEnabled( | ||||
| 		bool enabled | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点边缘颜色
 | ||||
| 	virtual void SetBorderColor( | ||||
| 		const Color& color | ||||
| 	); | ||||
| 
 | ||||
| 	// 判断点是否在节点内
 | ||||
| 	bool ContainsPoint( | ||||
| 		const Point& point | ||||
| 	); | ||||
| 
 | ||||
| 	// 判断两物体是否相交
 | ||||
| 	bool Intersects( | ||||
| 		Node * node | ||||
| 	); | ||||
| 
 | ||||
| 	// 添加子节点
 | ||||
| 	void AddChild( | ||||
| 		Node * child, | ||||
| 		int order = 0		/* 渲染顺序 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 添加多个子节点
 | ||||
| 	void AddChild( | ||||
| 		const Nodes& nodes,	/* 节点数组 */ | ||||
| 		int order = 0		/* 渲染顺序 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取所有名称相同的子节点
 | ||||
| 	Nodes GetChildren( | ||||
| 		const String& name | ||||
| 	) const; | ||||
| 
 | ||||
| 	// 获取名称相同的子节点
 | ||||
| 	Node* GetChild( | ||||
| 		const String& name | ||||
| 	) const; | ||||
| 
 | ||||
| 	// 获取所有子节点
 | ||||
| 	const Nodes& GetAllChildren() const; | ||||
| 
 | ||||
| 	// 获取子节点数量
 | ||||
| 	int GetChildrenCount() const; | ||||
| 
 | ||||
| 	// 移除子节点
 | ||||
| 	bool RemoveChild( | ||||
| 		Node * child | ||||
| 	); | ||||
| 
 | ||||
| 	// 移除所有名称相同的子节点
 | ||||
| 	void RemoveChildren( | ||||
| 		const String& child_name | ||||
| 	); | ||||
| 
 | ||||
| 	// 移除所有节点
 | ||||
| 	void RemoveAllChildren(); | ||||
| 
 | ||||
| 	// 从父节点移除
 | ||||
| 	void RemoveFromParent(); | ||||
| 
 | ||||
| 	// 执行动作
 | ||||
| 	void RunAction( | ||||
| 		Action * action | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续动作
 | ||||
| 	void ResumeAction( | ||||
| 		const String& name | ||||
| 	); | ||||
| 
 | ||||
| 	// 暂停动作
 | ||||
| 	void PauseAction( | ||||
| 		const String& name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止动作
 | ||||
| 	void StopAction( | ||||
| 		const String& name | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续所有暂停动作
 | ||||
| 	void ResumeAllActions(); | ||||
| 
 | ||||
| 	// 暂停所有动作
 | ||||
| 	void PauseAllActions(); | ||||
| 
 | ||||
| 	// 停止所有动作
 | ||||
| 	void StopAllActions(); | ||||
| 
 | ||||
| 	// 获取所有动作
 | ||||
| 	const Actions& GetAllActions() const; | ||||
| 
 | ||||
| 	// 刷新动作进度
 | ||||
| 	void UpdateActionsTime(); | ||||
| 
 | ||||
| 	// 分发鼠标消息
 | ||||
| 	virtual bool Dispatch( | ||||
| 		const MouseEvent& e, | ||||
| 		bool handled | ||||
| 	); | ||||
| 
 | ||||
| 	// 分发按键消息
 | ||||
| 	virtual bool Dispatch( | ||||
| 		const KeyEvent& e, | ||||
| 		bool handled | ||||
| 	); | ||||
| 
 | ||||
| 	// 遍历节点
 | ||||
| 	virtual void Visit(); | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Node); | ||||
| 
 | ||||
| 	// 渲染节点边缘
 | ||||
| 	void DrawBorder(); | ||||
| 
 | ||||
| 	// 渲染碰撞体轮廓
 | ||||
| 	void DrawCollider(); | ||||
| 
 | ||||
| 	// 设置节点所在场景
 | ||||
| 	void SetParentScene( | ||||
| 		Scene * scene | ||||
| 	); | ||||
| 
 | ||||
| 	// 子节点排序
 | ||||
| 	void SortChildren(); | ||||
| 
 | ||||
| 	// 更新转换矩阵
 | ||||
| 	void UpdateTransform(); | ||||
| 
 | ||||
| 	// 更新节点透明度
 | ||||
| 	void UpdateOpacity(); | ||||
| 
 | ||||
| 	// 更新动作
 | ||||
| 	void UpdateActions(); | ||||
| 
 | ||||
| protected: | ||||
| 	String		name_; | ||||
| 	size_t		hash_name_; | ||||
| 	Point		pos_; | ||||
| 	Size		size_; | ||||
| 	Point		scale_; | ||||
| 	Point		anchor_; | ||||
| 	Point		skew_; | ||||
| 	float		rotation_; | ||||
| 	float		display_opacity_; | ||||
| 	float		real_opacity_; | ||||
| 	int			order_; | ||||
| 	bool		visible_; | ||||
| 	bool		clip_enabled_; | ||||
| 	bool		need_sort_; | ||||
| 	bool		need_transform_; | ||||
| 	bool		fixed_position_; | ||||
| 	Collider	collider_; | ||||
| 	Scene *		parent_scene_; | ||||
| 	Node *		parent_; | ||||
| 	Property	extrapolate_; | ||||
| 	Color		border_color_; | ||||
| 	Actions		actions_; | ||||
| 	Nodes		children_; | ||||
| 	ID2D1Geometry*		border_; | ||||
| 	D2D1::Matrix3x2F	initial_matrix_; | ||||
| 	D2D1::Matrix3x2F	final_matrix_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 场景
 | ||||
| class Scene : | ||||
| 	public Node | ||||
| { | ||||
| public: | ||||
| 	Scene(); | ||||
| 
 | ||||
| 	virtual ~Scene(); | ||||
| 
 | ||||
| 	// 进入场景
 | ||||
| 	virtual void OnEnter() {} | ||||
| 
 | ||||
| 	// 退出场景
 | ||||
| 	virtual void OnExit() {} | ||||
| 
 | ||||
| 	// 关闭窗口
 | ||||
| 	// 说明:返回 false 将阻止窗口关闭
 | ||||
| 	virtual bool OnCloseWindow() { return true; } | ||||
| 
 | ||||
| 	// 显示或隐藏节点边缘
 | ||||
| 	// 默认:隐藏
 | ||||
| 	void ShowBorder( | ||||
| 		bool visible | ||||
| 	); | ||||
| 
 | ||||
| 	// 显示或隐藏碰撞体
 | ||||
| 	// 默认:隐藏
 | ||||
| 	void ShowCollider( | ||||
| 		bool visible | ||||
| 	); | ||||
| 
 | ||||
| 	// 遍历节点
 | ||||
| 	virtual void Visit() override; | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Scene); | ||||
| 
 | ||||
| protected: | ||||
| 	bool border_visible_; | ||||
| 	bool collider_visible_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 精灵
 | ||||
| class Sprite : | ||||
| 	public Node, | ||||
| 	public Drawable | ||||
| { | ||||
| public: | ||||
| 	Sprite(); | ||||
| 
 | ||||
| 	explicit Sprite( | ||||
| 		Image * image | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Sprite( | ||||
| 		const Resource& res | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Sprite( | ||||
| 		const Resource& res, | ||||
| 		const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Sprite( | ||||
| 		const String& file_name | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Sprite( | ||||
| 		const String& file_name, | ||||
| 		const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Sprite(); | ||||
| 
 | ||||
| 	// 加载图片文件
 | ||||
| 	bool Open( | ||||
| 		const Resource& res | ||||
| 	); | ||||
| 
 | ||||
| 	// 加载图片文件
 | ||||
| 	bool Open( | ||||
| 		const String& file_name | ||||
| 	); | ||||
| 	 | ||||
| 	// 加载图片
 | ||||
| 	bool Open( | ||||
| 		Image * image | ||||
| 	); | ||||
| 
 | ||||
| 	// 将图片裁剪为矩形
 | ||||
| 	void Crop( | ||||
| 		const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取 Image 对象
 | ||||
| 	Image * GetImage() const; | ||||
| 
 | ||||
| 	// 渲染精灵
 | ||||
| 	virtual void Draw() const override; | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Sprite); | ||||
| 
 | ||||
| protected: | ||||
| 	Image * image_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 文本
 | ||||
| class Text : | ||||
| 	public Node, | ||||
| 	public Drawable | ||||
| { | ||||
| public: | ||||
| 	// 文本对齐方式
 | ||||
| 	enum class Align | ||||
| 	{ | ||||
| 		Left,		/* 左对齐 */ | ||||
| 		Right,		/* 右对齐 */ | ||||
| 		Center		/* 居中对齐 */ | ||||
| 	}; | ||||
| 
 | ||||
| 	// 文本样式
 | ||||
| 	class Style | ||||
| 	{ | ||||
| 	public: | ||||
| 		Color		color;				// 颜色
 | ||||
| 		Align		alignment;			// 对齐方式
 | ||||
| 		bool		wrap;				// 打开自动换行
 | ||||
| 		float		wrap_width;			// 自动换行宽度
 | ||||
| 		float		line_spacing;		// 行间距
 | ||||
| 		bool		underline;			// 下划线
 | ||||
| 		bool		strikethrough;		// 删除线
 | ||||
| 		bool		outline;			// 显示描边
 | ||||
| 		Color		outline_color;		// 描边颜色
 | ||||
| 		float		outline_width;		// 描边线宽
 | ||||
| 		Stroke		outline_stroke;		// 描边线相交样式
 | ||||
| 
 | ||||
| 	public: | ||||
| 		Style(); | ||||
| 
 | ||||
| 		Style( | ||||
| 			Color color, | ||||
| 			Align alignment = Align::Left, | ||||
| 			bool wrap = false, | ||||
| 			float wrap_width = 0.f, | ||||
| 			float line_spacing = 0.f, | ||||
| 			bool underline = false, | ||||
| 			bool strikethrough = false, | ||||
| 			bool outline = true, | ||||
| 			Color outline_color = Color(Color::Black, 0.5), | ||||
| 			float outline_width = 1.f, | ||||
| 			Stroke outline_stroke = Stroke::Round | ||||
| 		); | ||||
| 	}; | ||||
| 
 | ||||
| public: | ||||
| 	Text(); | ||||
| 
 | ||||
| 	explicit Text( | ||||
| 		const String& text,						/* 文字内容 */ | ||||
| 		const Font& font = Font(),				/* 字体 */ | ||||
| 		const Style& style = Style()			/* 文本样式 */ | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Text(); | ||||
| 
 | ||||
| 	// 获取文本
 | ||||
| 	const String& GetText() const; | ||||
| 
 | ||||
| 	// 获取字体
 | ||||
| 	const Font& GetFont() const; | ||||
| 
 | ||||
| 	// 获取文本样式
 | ||||
| 	const Style& GetStyle() const; | ||||
| 
 | ||||
| 	// 获取字体族
 | ||||
| 	const String& GetFontFamily() const; | ||||
| 
 | ||||
| 	// 获取当前字号
 | ||||
| 	float GetFontSize() const; | ||||
| 
 | ||||
| 	// 获取当前字体粗细值
 | ||||
| 	UINT GetFontWeight() const; | ||||
| 
 | ||||
| 	// 获取文字颜色
 | ||||
| 	const Color& GetColor() const; | ||||
| 
 | ||||
| 	// 获取描边颜色
 | ||||
| 	const Color& GetOutlineColor() const; | ||||
| 
 | ||||
| 	// 获取描边线宽
 | ||||
| 	float GetOutlineWidth() const; | ||||
| 
 | ||||
| 	// 获取描边线相交样式
 | ||||
| 	Stroke GetOutlineStroke() const; | ||||
| 
 | ||||
| 	// 获取文本显示行数
 | ||||
| 	int GetLineCount() const; | ||||
| 
 | ||||
| 	// 是否是斜体
 | ||||
| 	bool IsItalic() const; | ||||
| 
 | ||||
| 	// 是否显示删除线
 | ||||
| 	bool strikethrough() const; | ||||
| 
 | ||||
| 	// 是否显示下划线
 | ||||
| 	bool underline() const; | ||||
| 
 | ||||
| 	// 是否显示描边
 | ||||
| 	bool outline() const; | ||||
| 
 | ||||
| 	// 设置文本
 | ||||
| 	void SetText( | ||||
| 		const String& text | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置文本样式
 | ||||
| 	void SetStyle( | ||||
| 		const Style& style | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置字体
 | ||||
| 	void SetFont( | ||||
| 		const Font& font | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置字体族
 | ||||
| 	void SetFontFamily( | ||||
| 		const String& family | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置字号(默认值为 22)
 | ||||
| 	void SetFontSize( | ||||
| 		float size | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置字体粗细值(默认值为 Text::Font::Weight::Normal)
 | ||||
| 	void SetFontWeight( | ||||
| 		UINT weight | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置文字颜色(默认值为 Color::WHITE)
 | ||||
| 	void SetColor( | ||||
| 		Color color | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置文字斜体(默认值为 false)
 | ||||
| 	void SetItalic( | ||||
| 		bool value | ||||
| 	); | ||||
| 
 | ||||
| 	// 打开或关闭文本自动换行(默认为关闭)
 | ||||
| 	void SetWrapEnabled( | ||||
| 		bool wrap | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置文本自动换行的宽度(默认为 0)
 | ||||
| 	void SetWrapWidth( | ||||
| 		float wrap_width | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置行间距(默认为 0)
 | ||||
| 	void SetLineSpacing( | ||||
| 		float line_spacing | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置对齐方式(默认为 Align::Left)
 | ||||
| 	void SetAlignment( | ||||
| 		Align align | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置下划线(默认值为 false)
 | ||||
| 	void SetUnderline( | ||||
| 		bool underline | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置删除线(默认值为 false)
 | ||||
| 	void SetStrikethrough( | ||||
| 		bool strikethrough | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置是否显示描边
 | ||||
| 	void SetOutline( | ||||
| 		bool outline | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置描边颜色
 | ||||
| 	void SetOutlineColor( | ||||
| 		Color outline_color | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置描边线宽
 | ||||
| 	void SetOutlineWidth( | ||||
| 		float outline_width | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置描边线相交样式
 | ||||
| 	void SetOutlineStroke( | ||||
| 		Stroke outline_stroke | ||||
| 	); | ||||
| 
 | ||||
| 	// 渲染文字
 | ||||
| 	virtual void Draw() const override; | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Text); | ||||
| 
 | ||||
| 	// 重新排版文字
 | ||||
| 	void Reset(); | ||||
| 
 | ||||
| 	// 创建文字格式化
 | ||||
| 	void CreateFormat(); | ||||
| 
 | ||||
| 	// 创建文字布局
 | ||||
| 	void CreateLayout(); | ||||
| 
 | ||||
| protected: | ||||
| 	String	text_; | ||||
| 	Font	font_; | ||||
| 	Style	style_; | ||||
| 	IDWriteTextFormat * text_format_; | ||||
| 	IDWriteTextLayout * text_layout_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| 	class Button : | ||||
| 		public Node | ||||
| 	{ | ||||
|  | @ -1044,6 +234,7 @@ protected: | |||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 꽉데
 | ||||
| 	class Menu : | ||||
| 		public Node | ||||
| 	{ | ||||
|  | @ -1087,117 +278,4 @@ protected: | |||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| // 画布
 | ||||
| class Canvas : | ||||
| 	public Node, | ||||
| 	public Drawable | ||||
| { | ||||
| public: | ||||
| 	Canvas( | ||||
| 		float width, | ||||
| 		float height | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Canvas(); | ||||
| 
 | ||||
| 	// 设置线条颜色
 | ||||
| 	void SetLineColor( | ||||
| 		const Color& color | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置填充颜色
 | ||||
| 	void SetFillColor( | ||||
| 		const Color& color | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置线条宽度
 | ||||
| 	void SetStrokeWidth( | ||||
| 		float width | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置线条相交样式
 | ||||
| 	void SetStrokeStyle( | ||||
| 		Stroke strokeStyle | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取线条颜色
 | ||||
| 	Color GetLineColor() const; | ||||
| 
 | ||||
| 	// 获取填充颜色
 | ||||
| 	Color GetFillColor() const; | ||||
| 
 | ||||
| 	// 获取线条宽度
 | ||||
| 	float GetStrokeWidth() const; | ||||
| 
 | ||||
| 	// 获取线条相交样式
 | ||||
| 	Stroke GetStrokeStyle() const; | ||||
| 
 | ||||
| 	// 画直线
 | ||||
| 	void DrawLine( | ||||
| 		const Point& begin, | ||||
| 		const Point& end | ||||
| 	); | ||||
| 
 | ||||
| 	// 画圆形边框
 | ||||
| 	void DrawCircle( | ||||
| 		const Point& center, | ||||
| 		float radius | ||||
| 	); | ||||
| 
 | ||||
| 	// 画椭圆形边框
 | ||||
| 	void DrawEllipse( | ||||
| 		const Point& center, | ||||
| 		float radius_x, | ||||
| 		float radius_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 画矩形边框
 | ||||
| 	void DrawRect( | ||||
| 		const Rect& rect | ||||
| 	); | ||||
| 
 | ||||
| 	// 画圆角矩形边框
 | ||||
| 	void DrawRoundedRect( | ||||
| 		const Rect& rect, | ||||
| 		float radius_x, | ||||
| 		float radius_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 填充圆形
 | ||||
| 	void FillCircle( | ||||
| 		const Point& center, | ||||
| 		float radius | ||||
| 	); | ||||
| 
 | ||||
| 	// 填充椭圆形
 | ||||
| 	void FillEllipse( | ||||
| 		const Point& center, | ||||
| 		float radius_x, | ||||
| 		float radius_y | ||||
| 	); | ||||
| 
 | ||||
| 	// 填充矩形
 | ||||
| 	void FillRect( | ||||
| 		const Rect& rect | ||||
| 	); | ||||
| 
 | ||||
| 	// 填充圆角矩形
 | ||||
| 	void FillRoundedRect( | ||||
| 		const Rect& rect, | ||||
| 		float radius_x, | ||||
| 		float radius_y | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	E2D_DISABLE_COPY(Canvas); | ||||
| 
 | ||||
| protected: | ||||
| 	float	stroke_width_; | ||||
| 	Stroke	stroke_; | ||||
| 	ID2D1RenderTarget * render_target_; | ||||
| 	ID2D1SolidColorBrush * fill_brush_; | ||||
| 	ID2D1SolidColorBrush * line_brush_; | ||||
| 	ID2D1StrokeStyle * stroke_style_; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -1,5 +1,5 @@ | |||
| #pragma once | ||||
| #include "e2dcommon.h" | ||||
| #include "e2dutil.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #pragma once | ||||
| #include "e2dcommon.h" | ||||
| #include "e2dutil.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| #include "e2dmacros.h" | ||||
| #include "e2dcommon.h" | ||||
| #include "e2dutil.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| #include "e2dimpl.h" | ||||
| #include "e2dcomponent.h" | ||||
| #include "e2dnode.h" | ||||
| #include "e2dtransition.h" | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,931 @@ | |||
| #pragma once | ||||
| #include "e2dutil.h" | ||||
| #include "e2devent.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| 
 | ||||
| 	class Action; | ||||
| 	class Scene; | ||||
| 
 | ||||
| 
 | ||||
| 	// 绘图接口
 | ||||
| 	class Drawable | ||||
| 	{ | ||||
| 	public: | ||||
| 		// 渲染图形
 | ||||
| 		virtual void Draw() const = 0; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 更新接口
 | ||||
| 	class Updatable | ||||
| 	{ | ||||
| 	public: | ||||
| 		// 渲染图形
 | ||||
| 		virtual void Update() = 0; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 按键消息处理接口
 | ||||
| 	class KeyEventHandler | ||||
| 	{ | ||||
| 	public: | ||||
| 		// 处理按键消息
 | ||||
| 		virtual void Handle(KeyEvent e) = 0; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 鼠标消息处理接口
 | ||||
| 	class MouseEventHandler | ||||
| 	{ | ||||
| 	public: | ||||
| 		// 处理鼠标消息
 | ||||
| 		virtual void Handle(MouseEvent e) = 0; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 碰撞消息处理接口
 | ||||
| 	class CollisionHandler | ||||
| 	{ | ||||
| 	public: | ||||
| 		// 处理碰撞消息
 | ||||
| 		virtual void Handle(Collision collision) = 0; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 节点
 | ||||
| 	class Node : | ||||
| 		public Ref | ||||
| 	{ | ||||
| 		friend class Collider; | ||||
| 
 | ||||
| 	public: | ||||
| 		// 节点属性
 | ||||
| 		struct Property | ||||
| 		{ | ||||
| 			Point pos;			// 坐标
 | ||||
| 			Size size;			// 大小
 | ||||
| 			Point anchor;		// 锚点坐标
 | ||||
| 			Point scale;		// 缩放
 | ||||
| 			Point skew;			// 倾斜角度
 | ||||
| 			float rotation;		// 旋转角度
 | ||||
| 
 | ||||
| 			Property operator+ (Property const & prop) const; | ||||
| 			Property operator- (Property const & prop) const; | ||||
| 
 | ||||
| 			static const Property Origin; | ||||
| 		}; | ||||
| 
 | ||||
| 	public: | ||||
| 		typedef std::vector<Node*> Nodes; | ||||
| 		typedef std::vector<Action*> Actions; | ||||
| 
 | ||||
| 		Node(); | ||||
| 
 | ||||
| 		virtual ~Node(); | ||||
| 
 | ||||
| 		// 获取节点显示状态
 | ||||
| 		bool IsVisible() const; | ||||
| 
 | ||||
| 		// 获取节点名称
 | ||||
| 		const String& GetName() const; | ||||
| 
 | ||||
| 		// 获取节点名称的 Hash 值
 | ||||
| 		size_t GetHashName() const; | ||||
| 
 | ||||
| 		// 获取节点绘图顺序
 | ||||
| 		int GetOrder() const; | ||||
| 
 | ||||
| 		// 获取节点横坐标
 | ||||
| 		float GetPosX() const; | ||||
| 
 | ||||
| 		// 获取节点纵坐标
 | ||||
| 		float GetPosY() const; | ||||
| 
 | ||||
| 		// 获取节点坐标
 | ||||
| 		Point GetPos() const; | ||||
| 
 | ||||
| 		// 获取节点宽度
 | ||||
| 		float GetWidth() const; | ||||
| 
 | ||||
| 		// 获取节点高度
 | ||||
| 		float GetHeight() const; | ||||
| 
 | ||||
| 		// 获取节点宽度(不考虑缩放)
 | ||||
| 		float GetRealWidth() const; | ||||
| 
 | ||||
| 		// 获取节点高度(不考虑缩放)
 | ||||
| 		float GetRealHeight() const; | ||||
| 
 | ||||
| 		// 获取节点大小(不考虑缩放)
 | ||||
| 		Size GetRealSize() const; | ||||
| 
 | ||||
| 		// 获取节点的锚点
 | ||||
| 		float GetAnchorX() const; | ||||
| 
 | ||||
| 		// 获取节点的锚点
 | ||||
| 		float GetAnchorY() const; | ||||
| 
 | ||||
| 		// 获取节点大小
 | ||||
| 		Size GetSize() const; | ||||
| 
 | ||||
| 		// 获取节点横向缩放比例
 | ||||
| 		float GetScaleX() const; | ||||
| 
 | ||||
| 		// 获取节点纵向缩放比例
 | ||||
| 		float GetScaleY() const; | ||||
| 
 | ||||
| 		// 获取节点横向倾斜角度
 | ||||
| 		float GetSkewX() const; | ||||
| 
 | ||||
| 		// 获取节点纵向倾斜角度
 | ||||
| 		float GetSkewY() const; | ||||
| 
 | ||||
| 		// 获取节点旋转角度
 | ||||
| 		float GetRotation() const; | ||||
| 
 | ||||
| 		// 获取节点透明度
 | ||||
| 		float GetOpacity() const; | ||||
| 
 | ||||
| 		// 获取节点属性
 | ||||
| 		Property GetProperty() const; | ||||
| 
 | ||||
| 		// 获取差别属性
 | ||||
| 		Property GetExtrapolate() const; | ||||
| 
 | ||||
| 		// 获取节点碰撞体
 | ||||
| 		Collider * GetCollider(); | ||||
| 
 | ||||
| 		// 获取父节点
 | ||||
| 		Node * GetParent() const; | ||||
| 
 | ||||
| 		// 获取节点所在场景
 | ||||
| 		Scene * GetParentScene() const; | ||||
| 
 | ||||
| 		// 设置节点是否显示
 | ||||
| 		void SetVisible( | ||||
| 			bool value | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点名称
 | ||||
| 		void SetName( | ||||
| 			const String& name | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点横坐标
 | ||||
| 		virtual void SetPosX( | ||||
| 			float x | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点纵坐标
 | ||||
| 		virtual void SetPosY( | ||||
| 			float y | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点坐标
 | ||||
| 		virtual void SetPos( | ||||
| 			const Point & point | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点坐标
 | ||||
| 		virtual void SetPos( | ||||
| 			float x, | ||||
| 			float y | ||||
| 		); | ||||
| 
 | ||||
| 		// 节点坐标固定
 | ||||
| 		virtual void SetPosFixed( | ||||
| 			bool fixed | ||||
| 		); | ||||
| 
 | ||||
| 		// 移动节点
 | ||||
| 		virtual void Move( | ||||
| 			float x, | ||||
| 			float y | ||||
| 		); | ||||
| 
 | ||||
| 		// 移动节点
 | ||||
| 		virtual void Move( | ||||
| 			const Point & v | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点绘图顺序
 | ||||
| 		// 默认为 0
 | ||||
| 		virtual void SetOrder( | ||||
| 			int order | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置横向缩放比例
 | ||||
| 		// 默认为 1.0
 | ||||
| 		virtual void SetScaleX( | ||||
| 			float scale_x | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置纵向缩放比例
 | ||||
| 		// 默认为 1.0
 | ||||
| 		virtual void SetScaleY( | ||||
| 			float scale_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置缩放比例
 | ||||
| 		// 默认为 (1.0, 1.0)
 | ||||
| 		virtual void SetScale( | ||||
| 			float scale_x, | ||||
| 			float scale_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置缩放比例
 | ||||
| 		// 默认为 1.0
 | ||||
| 		virtual void SetScale( | ||||
| 			float scale | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置横向倾斜角度
 | ||||
| 		// 默认为 0
 | ||||
| 		virtual void SetSkewX( | ||||
| 			float skew_x | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置纵向倾斜角度
 | ||||
| 		// 默认为 0
 | ||||
| 		virtual void SetSkewY( | ||||
| 			float skew_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置倾斜角度
 | ||||
| 		// 默认为 (0, 0)
 | ||||
| 		virtual void SetSkew( | ||||
| 			float skew_x, | ||||
| 			float skew_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置旋转角度
 | ||||
| 		// 默认为 0
 | ||||
| 		virtual void SetRotation( | ||||
| 			float rotation | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置透明度
 | ||||
| 		// 默认为 1.0, 范围 [0, 1]
 | ||||
| 		virtual void SetOpacity( | ||||
| 			float opacity | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置锚点的横向位置
 | ||||
| 		// 默认为 0, 范围 [0, 1]
 | ||||
| 		virtual void SetAnchorX( | ||||
| 			float anchor_x | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置锚点的纵向位置
 | ||||
| 		// 默认为 0, 范围 [0, 1]
 | ||||
| 		virtual void SetAnchorY( | ||||
| 			float anchor_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置锚点位置
 | ||||
| 		// 默认为 (0, 0), 范围 [0, 1]
 | ||||
| 		virtual void SetAnchor( | ||||
| 			float anchor_x, | ||||
| 			float anchor_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 修改节点宽度
 | ||||
| 		virtual void SetWidth( | ||||
| 			float width | ||||
| 		); | ||||
| 
 | ||||
| 		// 修改节点高度
 | ||||
| 		virtual void SetHeight( | ||||
| 			float height | ||||
| 		); | ||||
| 
 | ||||
| 		// 修改节点大小
 | ||||
| 		virtual void SetSize( | ||||
| 			float width, | ||||
| 			float height | ||||
| 		); | ||||
| 
 | ||||
| 		// 修改节点大小
 | ||||
| 		virtual void SetSize( | ||||
| 			Size size | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点属性
 | ||||
| 		virtual void SetProperty( | ||||
| 			Property prop | ||||
| 		); | ||||
| 
 | ||||
| 		// 启用或关闭渲染区域裁剪
 | ||||
| 		virtual void SetClipEnabled( | ||||
| 			bool enabled | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置节点边缘颜色
 | ||||
| 		virtual void SetBorderColor( | ||||
| 			const Color& color | ||||
| 		); | ||||
| 
 | ||||
| 		// 判断点是否在节点内
 | ||||
| 		bool ContainsPoint( | ||||
| 			const Point& point | ||||
| 		); | ||||
| 
 | ||||
| 		// 判断两物体是否相交
 | ||||
| 		bool Intersects( | ||||
| 			Node * node | ||||
| 		); | ||||
| 
 | ||||
| 		// 添加子节点
 | ||||
| 		void AddChild( | ||||
| 			Node * child, | ||||
| 			int order = 0		/* 渲染顺序 */ | ||||
| 		); | ||||
| 
 | ||||
| 		// 添加多个子节点
 | ||||
| 		void AddChild( | ||||
| 			const Nodes& nodes,	/* 节点数组 */ | ||||
| 			int order = 0		/* 渲染顺序 */ | ||||
| 		); | ||||
| 
 | ||||
| 		// 获取所有名称相同的子节点
 | ||||
| 		Nodes GetChildren( | ||||
| 			const String& name | ||||
| 		) const; | ||||
| 
 | ||||
| 		// 获取名称相同的子节点
 | ||||
| 		Node* GetChild( | ||||
| 			const String& name | ||||
| 		) const; | ||||
| 
 | ||||
| 		// 获取所有子节点
 | ||||
| 		const Nodes& GetAllChildren() const; | ||||
| 
 | ||||
| 		// 获取子节点数量
 | ||||
| 		int GetChildrenCount() const; | ||||
| 
 | ||||
| 		// 移除子节点
 | ||||
| 		bool RemoveChild( | ||||
| 			Node * child | ||||
| 		); | ||||
| 
 | ||||
| 		// 移除所有名称相同的子节点
 | ||||
| 		void RemoveChildren( | ||||
| 			const String& child_name | ||||
| 		); | ||||
| 
 | ||||
| 		// 移除所有节点
 | ||||
| 		void RemoveAllChildren(); | ||||
| 
 | ||||
| 		// 从父节点移除
 | ||||
| 		void RemoveFromParent(); | ||||
| 
 | ||||
| 		// 执行动作
 | ||||
| 		void RunAction( | ||||
| 			Action * action | ||||
| 		); | ||||
| 
 | ||||
| 		// 继续动作
 | ||||
| 		void ResumeAction( | ||||
| 			const String& name | ||||
| 		); | ||||
| 
 | ||||
| 		// 暂停动作
 | ||||
| 		void PauseAction( | ||||
| 			const String& name | ||||
| 		); | ||||
| 
 | ||||
| 		// 停止动作
 | ||||
| 		void StopAction( | ||||
| 			const String& name | ||||
| 		); | ||||
| 
 | ||||
| 		// 继续所有暂停动作
 | ||||
| 		void ResumeAllActions(); | ||||
| 
 | ||||
| 		// 暂停所有动作
 | ||||
| 		void PauseAllActions(); | ||||
| 
 | ||||
| 		// 停止所有动作
 | ||||
| 		void StopAllActions(); | ||||
| 
 | ||||
| 		// 获取所有动作
 | ||||
| 		const Actions& GetAllActions() const; | ||||
| 
 | ||||
| 		// 刷新动作进度
 | ||||
| 		void UpdateActionsTime(); | ||||
| 
 | ||||
| 		// 分发鼠标消息
 | ||||
| 		virtual bool Dispatch( | ||||
| 			const MouseEvent& e, | ||||
| 			bool handled | ||||
| 		); | ||||
| 
 | ||||
| 		// 分发按键消息
 | ||||
| 		virtual bool Dispatch( | ||||
| 			const KeyEvent& e, | ||||
| 			bool handled | ||||
| 		); | ||||
| 
 | ||||
| 		// 遍历节点
 | ||||
| 		virtual void Visit(); | ||||
| 
 | ||||
| 	protected: | ||||
| 		E2D_DISABLE_COPY(Node); | ||||
| 
 | ||||
| 		// 渲染节点边缘
 | ||||
| 		void DrawBorder(); | ||||
| 
 | ||||
| 		// 渲染碰撞体轮廓
 | ||||
| 		void DrawCollider(); | ||||
| 
 | ||||
| 		// 设置节点所在场景
 | ||||
| 		void SetParentScene( | ||||
| 			Scene * scene | ||||
| 		); | ||||
| 
 | ||||
| 		// 子节点排序
 | ||||
| 		void SortChildren(); | ||||
| 
 | ||||
| 		// 更新转换矩阵
 | ||||
| 		void UpdateTransform(); | ||||
| 
 | ||||
| 		// 更新节点透明度
 | ||||
| 		void UpdateOpacity(); | ||||
| 
 | ||||
| 		// 更新动作
 | ||||
| 		void UpdateActions(); | ||||
| 
 | ||||
| 	protected: | ||||
| 		String		name_; | ||||
| 		size_t		hash_name_; | ||||
| 		Point		pos_; | ||||
| 		Size		size_; | ||||
| 		Point		scale_; | ||||
| 		Point		anchor_; | ||||
| 		Point		skew_; | ||||
| 		float		rotation_; | ||||
| 		float		display_opacity_; | ||||
| 		float		real_opacity_; | ||||
| 		int			order_; | ||||
| 		bool		visible_; | ||||
| 		bool		clip_enabled_; | ||||
| 		bool		need_sort_; | ||||
| 		bool		need_transform_; | ||||
| 		bool		fixed_position_; | ||||
| 		Collider	collider_; | ||||
| 		Scene *		parent_scene_; | ||||
| 		Node *		parent_; | ||||
| 		Property	extrapolate_; | ||||
| 		Color		border_color_; | ||||
| 		Actions		actions_; | ||||
| 		Nodes		children_; | ||||
| 		ID2D1Geometry*		border_; | ||||
| 		D2D1::Matrix3x2F	initial_matrix_; | ||||
| 		D2D1::Matrix3x2F	final_matrix_; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 场景
 | ||||
| 	class Scene : | ||||
| 		public Node | ||||
| 	{ | ||||
| 	public: | ||||
| 		Scene(); | ||||
| 
 | ||||
| 		virtual ~Scene(); | ||||
| 
 | ||||
| 		// 进入场景
 | ||||
| 		virtual void OnEnter() {} | ||||
| 
 | ||||
| 		// 退出场景
 | ||||
| 		virtual void OnExit() {} | ||||
| 
 | ||||
| 		// 关闭窗口
 | ||||
| 		// 说明:返回 false 将阻止窗口关闭
 | ||||
| 		virtual bool OnCloseWindow() { return true; } | ||||
| 
 | ||||
| 		// 显示或隐藏节点边缘
 | ||||
| 		// 默认:隐藏
 | ||||
| 		void ShowBorder( | ||||
| 			bool visible | ||||
| 		); | ||||
| 
 | ||||
| 		// 显示或隐藏碰撞体
 | ||||
| 		// 默认:隐藏
 | ||||
| 		void ShowCollider( | ||||
| 			bool visible | ||||
| 		); | ||||
| 
 | ||||
| 		// 遍历节点
 | ||||
| 		virtual void Visit() override; | ||||
| 
 | ||||
| 	protected: | ||||
| 		E2D_DISABLE_COPY(Scene); | ||||
| 
 | ||||
| 	protected: | ||||
| 		bool border_visible_; | ||||
| 		bool collider_visible_; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 精灵
 | ||||
| 	class Sprite : | ||||
| 		public Node, | ||||
| 		public Drawable | ||||
| 	{ | ||||
| 	public: | ||||
| 		Sprite(); | ||||
| 
 | ||||
| 		explicit Sprite( | ||||
| 			Image * image | ||||
| 		); | ||||
| 
 | ||||
| 		explicit Sprite( | ||||
| 			const Resource& res | ||||
| 		); | ||||
| 
 | ||||
| 		explicit Sprite( | ||||
| 			const Resource& res, | ||||
| 			const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 		); | ||||
| 
 | ||||
| 		explicit Sprite( | ||||
| 			const String& file_name | ||||
| 		); | ||||
| 
 | ||||
| 		explicit Sprite( | ||||
| 			const String& file_name, | ||||
| 			const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 		); | ||||
| 
 | ||||
| 		virtual ~Sprite(); | ||||
| 
 | ||||
| 		// 加载图片文件
 | ||||
| 		bool Open( | ||||
| 			const Resource& res | ||||
| 		); | ||||
| 
 | ||||
| 		// 加载图片文件
 | ||||
| 		bool Open( | ||||
| 			const String& file_name | ||||
| 		); | ||||
| 
 | ||||
| 		// 加载图片
 | ||||
| 		bool Open( | ||||
| 			Image * image | ||||
| 		); | ||||
| 
 | ||||
| 		// 将图片裁剪为矩形
 | ||||
| 		void Crop( | ||||
| 			const Rect& crop_rect	/* 裁剪矩形 */ | ||||
| 		); | ||||
| 
 | ||||
| 		// 获取 Image 对象
 | ||||
| 		Image * GetImage() const; | ||||
| 
 | ||||
| 		// 渲染精灵
 | ||||
| 		virtual void Draw() const override; | ||||
| 
 | ||||
| 	protected: | ||||
| 		E2D_DISABLE_COPY(Sprite); | ||||
| 
 | ||||
| 	protected: | ||||
| 		Image * image_; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 文本
 | ||||
| 	class Text : | ||||
| 		public Node, | ||||
| 		public Drawable | ||||
| 	{ | ||||
| 	public: | ||||
| 		// 文本对齐方式
 | ||||
| 		enum class Align | ||||
| 		{ | ||||
| 			Left,		/* 左对齐 */ | ||||
| 			Right,		/* 右对齐 */ | ||||
| 			Center		/* 居中对齐 */ | ||||
| 		}; | ||||
| 
 | ||||
| 		// 文本样式
 | ||||
| 		class Style | ||||
| 		{ | ||||
| 		public: | ||||
| 			Color		color;				// 颜色
 | ||||
| 			Align		alignment;			// 对齐方式
 | ||||
| 			bool		wrap;				// 打开自动换行
 | ||||
| 			float		wrap_width;			// 自动换行宽度
 | ||||
| 			float		line_spacing;		// 行间距
 | ||||
| 			bool		underline;			// 下划线
 | ||||
| 			bool		strikethrough;		// 删除线
 | ||||
| 			bool		outline;			// 显示描边
 | ||||
| 			Color		outline_color;		// 描边颜色
 | ||||
| 			float		outline_width;		// 描边线宽
 | ||||
| 			Stroke		outline_stroke;		// 描边线相交样式
 | ||||
| 
 | ||||
| 		public: | ||||
| 			Style(); | ||||
| 
 | ||||
| 			Style( | ||||
| 				Color color, | ||||
| 				Align alignment = Align::Left, | ||||
| 				bool wrap = false, | ||||
| 				float wrap_width = 0.f, | ||||
| 				float line_spacing = 0.f, | ||||
| 				bool underline = false, | ||||
| 				bool strikethrough = false, | ||||
| 				bool outline = true, | ||||
| 				Color outline_color = Color(Color::Black, 0.5), | ||||
| 				float outline_width = 1.f, | ||||
| 				Stroke outline_stroke = Stroke::Round | ||||
| 			); | ||||
| 		}; | ||||
| 
 | ||||
| 	public: | ||||
| 		Text(); | ||||
| 
 | ||||
| 		explicit Text( | ||||
| 			const String& text,						/* 文字内容 */ | ||||
| 			const Font& font = Font(),				/* 字体 */ | ||||
| 			const Style& style = Style()			/* 文本样式 */ | ||||
| 		); | ||||
| 
 | ||||
| 		virtual ~Text(); | ||||
| 
 | ||||
| 		// 获取文本
 | ||||
| 		const String& GetText() const; | ||||
| 
 | ||||
| 		// 获取字体
 | ||||
| 		const Font& GetFont() const; | ||||
| 
 | ||||
| 		// 获取文本样式
 | ||||
| 		const Style& GetStyle() const; | ||||
| 
 | ||||
| 		// 获取字体族
 | ||||
| 		const String& GetFontFamily() const; | ||||
| 
 | ||||
| 		// 获取当前字号
 | ||||
| 		float GetFontSize() const; | ||||
| 
 | ||||
| 		// 获取当前字体粗细值
 | ||||
| 		UINT GetFontWeight() const; | ||||
| 
 | ||||
| 		// 获取文字颜色
 | ||||
| 		const Color& GetColor() const; | ||||
| 
 | ||||
| 		// 获取描边颜色
 | ||||
| 		const Color& GetOutlineColor() const; | ||||
| 
 | ||||
| 		// 获取描边线宽
 | ||||
| 		float GetOutlineWidth() const; | ||||
| 
 | ||||
| 		// 获取描边线相交样式
 | ||||
| 		Stroke GetOutlineStroke() const; | ||||
| 
 | ||||
| 		// 获取文本显示行数
 | ||||
| 		int GetLineCount() const; | ||||
| 
 | ||||
| 		// 是否是斜体
 | ||||
| 		bool IsItalic() const; | ||||
| 
 | ||||
| 		// 是否显示删除线
 | ||||
| 		bool strikethrough() const; | ||||
| 
 | ||||
| 		// 是否显示下划线
 | ||||
| 		bool underline() const; | ||||
| 
 | ||||
| 		// 是否显示描边
 | ||||
| 		bool outline() const; | ||||
| 
 | ||||
| 		// 设置文本
 | ||||
| 		void SetText( | ||||
| 			const String& text | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置文本样式
 | ||||
| 		void SetStyle( | ||||
| 			const Style& style | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置字体
 | ||||
| 		void SetFont( | ||||
| 			const Font& font | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置字体族
 | ||||
| 		void SetFontFamily( | ||||
| 			const String& family | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置字号(默认值为 22)
 | ||||
| 		void SetFontSize( | ||||
| 			float size | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置字体粗细值(默认值为 Text::Font::Weight::Normal)
 | ||||
| 		void SetFontWeight( | ||||
| 			UINT weight | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置文字颜色(默认值为 Color::WHITE)
 | ||||
| 		void SetColor( | ||||
| 			Color color | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置文字斜体(默认值为 false)
 | ||||
| 		void SetItalic( | ||||
| 			bool value | ||||
| 		); | ||||
| 
 | ||||
| 		// 打开或关闭文本自动换行(默认为关闭)
 | ||||
| 		void SetWrapEnabled( | ||||
| 			bool wrap | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置文本自动换行的宽度(默认为 0)
 | ||||
| 		void SetWrapWidth( | ||||
| 			float wrap_width | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置行间距(默认为 0)
 | ||||
| 		void SetLineSpacing( | ||||
| 			float line_spacing | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置对齐方式(默认为 Align::Left)
 | ||||
| 		void SetAlignment( | ||||
| 			Align align | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置下划线(默认值为 false)
 | ||||
| 		void SetUnderline( | ||||
| 			bool underline | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置删除线(默认值为 false)
 | ||||
| 		void SetStrikethrough( | ||||
| 			bool strikethrough | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置是否显示描边
 | ||||
| 		void SetOutline( | ||||
| 			bool outline | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置描边颜色
 | ||||
| 		void SetOutlineColor( | ||||
| 			Color outline_color | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置描边线宽
 | ||||
| 		void SetOutlineWidth( | ||||
| 			float outline_width | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置描边线相交样式
 | ||||
| 		void SetOutlineStroke( | ||||
| 			Stroke outline_stroke | ||||
| 		); | ||||
| 
 | ||||
| 		// 渲染文字
 | ||||
| 		virtual void Draw() const override; | ||||
| 
 | ||||
| 	protected: | ||||
| 		E2D_DISABLE_COPY(Text); | ||||
| 
 | ||||
| 		// 重新排版文字
 | ||||
| 		void Reset(); | ||||
| 
 | ||||
| 		// 创建文字格式化
 | ||||
| 		void CreateFormat(); | ||||
| 
 | ||||
| 		// 创建文字布局
 | ||||
| 		void CreateLayout(); | ||||
| 
 | ||||
| 	protected: | ||||
| 		String	text_; | ||||
| 		Font	font_; | ||||
| 		Style	style_; | ||||
| 		IDWriteTextFormat * text_format_; | ||||
| 		IDWriteTextLayout * text_layout_; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// 画布
 | ||||
| 	class Canvas : | ||||
| 		public Node, | ||||
| 		public Drawable | ||||
| 	{ | ||||
| 	public: | ||||
| 		Canvas( | ||||
| 			float width, | ||||
| 			float height | ||||
| 		); | ||||
| 
 | ||||
| 		virtual ~Canvas(); | ||||
| 
 | ||||
| 		// 设置线条颜色
 | ||||
| 		void SetLineColor( | ||||
| 			const Color& color | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置填充颜色
 | ||||
| 		void SetFillColor( | ||||
| 			const Color& color | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置线条宽度
 | ||||
| 		void SetStrokeWidth( | ||||
| 			float width | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置线条相交样式
 | ||||
| 		void SetStrokeStyle( | ||||
| 			Stroke strokeStyle | ||||
| 		); | ||||
| 
 | ||||
| 		// 获取线条颜色
 | ||||
| 		Color GetLineColor() const; | ||||
| 
 | ||||
| 		// 获取填充颜色
 | ||||
| 		Color GetFillColor() const; | ||||
| 
 | ||||
| 		// 获取线条宽度
 | ||||
| 		float GetStrokeWidth() const; | ||||
| 
 | ||||
| 		// 获取线条相交样式
 | ||||
| 		Stroke GetStrokeStyle() const; | ||||
| 
 | ||||
| 		// 画直线
 | ||||
| 		void DrawLine( | ||||
| 			const Point& begin, | ||||
| 			const Point& end | ||||
| 		); | ||||
| 
 | ||||
| 		// 画圆形边框
 | ||||
| 		void DrawCircle( | ||||
| 			const Point& center, | ||||
| 			float radius | ||||
| 		); | ||||
| 
 | ||||
| 		// 画椭圆形边框
 | ||||
| 		void DrawEllipse( | ||||
| 			const Point& center, | ||||
| 			float radius_x, | ||||
| 			float radius_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 画矩形边框
 | ||||
| 		void DrawRect( | ||||
| 			const Rect& rect | ||||
| 		); | ||||
| 
 | ||||
| 		// 画圆角矩形边框
 | ||||
| 		void DrawRoundedRect( | ||||
| 			const Rect& rect, | ||||
| 			float radius_x, | ||||
| 			float radius_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 填充圆形
 | ||||
| 		void FillCircle( | ||||
| 			const Point& center, | ||||
| 			float radius | ||||
| 		); | ||||
| 
 | ||||
| 		// 填充椭圆形
 | ||||
| 		void FillEllipse( | ||||
| 			const Point& center, | ||||
| 			float radius_x, | ||||
| 			float radius_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 填充矩形
 | ||||
| 		void FillRect( | ||||
| 			const Rect& rect | ||||
| 		); | ||||
| 
 | ||||
| 		// 填充圆角矩形
 | ||||
| 		void FillRoundedRect( | ||||
| 			const Rect& rect, | ||||
| 			float radius_x, | ||||
| 			float radius_y | ||||
| 		); | ||||
| 
 | ||||
| 	protected: | ||||
| 		E2D_DISABLE_COPY(Canvas); | ||||
| 
 | ||||
| 	protected: | ||||
| 		float	stroke_width_; | ||||
| 		Stroke	stroke_; | ||||
| 		ID2D1RenderTarget * render_target_; | ||||
| 		ID2D1SolidColorBrush * fill_brush_; | ||||
| 		ID2D1SolidColorBrush * line_brush_; | ||||
| 		ID2D1StrokeStyle * stroke_style_; | ||||
| 	}; | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,510 @@ | |||
| #pragma once | ||||
| #include "e2dutil.h" | ||||
| #include "e2dimpl.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| 
 | ||||
| // 随机数产生器
 | ||||
| class Random | ||||
| { | ||||
| public: | ||||
| 	// 取得范围内的一个整型随机数
 | ||||
| 	template<typename T> | ||||
| 	static inline T Range(T min, T max)  | ||||
| 	{  | ||||
| 		return e2d::Random::RandomInt(min, max);  | ||||
| 	} | ||||
| 
 | ||||
| 	// 取得范围内的一个浮点数随机数
 | ||||
| 	static inline float Range(float min, float max)  | ||||
| 	{  | ||||
| 		return e2d::Random::RandomReal(min, max);  | ||||
| 	} | ||||
| 
 | ||||
| 	// 取得范围内的一个浮点数随机数
 | ||||
| 	static inline double Range(double min, double max) | ||||
| 	{  | ||||
| 		return e2d::Random::RandomReal(min, max);  | ||||
| 	} | ||||
| 
 | ||||
| private: | ||||
| 	template<typename T> | ||||
| 	static T RandomInt(T min, T max) | ||||
| 	{ | ||||
| 		std::uniform_int_distribution<T> dist(min, max); | ||||
| 		return dist(Random::GetEngine()); | ||||
| 	} | ||||
| 
 | ||||
| 	template<typename T> | ||||
| 	static T RandomReal(T min, T max) | ||||
| 	{ | ||||
| 		std::uniform_real_distribution<T> dist(min, max); | ||||
| 		return dist(Random::GetEngine()); | ||||
| 	} | ||||
| 
 | ||||
| 	// 获取随机数产生器
 | ||||
| 	static std::default_random_engine &GetEngine(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 音乐
 | ||||
| class Music : | ||||
| 	public Ref | ||||
| { | ||||
| 	friend class VoiceCallback; | ||||
| 
 | ||||
| public: | ||||
| 	Music(); | ||||
| 
 | ||||
| 	explicit Music( | ||||
| 		const e2d::String& file_path	/* 音乐文件路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Music( | ||||
| 		const Resource& res		/* 音乐资源 */ | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~Music(); | ||||
| 
 | ||||
| 	// 打开音乐文件
 | ||||
| 	bool Open( | ||||
| 		const e2d::String& file_path	/* 音乐文件路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 打开音乐资源
 | ||||
| 	bool Open( | ||||
| 		const Resource& res | ||||
| 	); | ||||
| 
 | ||||
| 	// 播放
 | ||||
| 	bool Play( | ||||
| 		int loopCount = 0 | ||||
| 	); | ||||
| 
 | ||||
| 	// 暂停
 | ||||
| 	void Pause(); | ||||
| 
 | ||||
| 	// 继续
 | ||||
| 	void Resume(); | ||||
| 
 | ||||
| 	// 停止
 | ||||
| 	void Stop(); | ||||
| 
 | ||||
| 	// 关闭并回收资源
 | ||||
| 	void Close(); | ||||
| 
 | ||||
| 	// 是否正在播放
 | ||||
| 	bool IsPlaying() const; | ||||
| 
 | ||||
| 	// 设置音量
 | ||||
| 	bool SetVolume( | ||||
| 		float volume | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置播放结束时的执行函数
 | ||||
| 	void SetCallbackOnEnd( | ||||
| 		const Function& func | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置循环播放中每一次播放结束时的执行函数
 | ||||
| 	void SetCallbackOnLoopEnd( | ||||
| 		const Function& func | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取 IXAudio2SourceVoice 对象
 | ||||
| 	IXAudio2SourceVoice * GetSourceVoice() const; | ||||
| 
 | ||||
| protected: | ||||
| 	bool _readMMIO(); | ||||
| 
 | ||||
| 	bool _resetFile(); | ||||
| 
 | ||||
| 	bool _read( | ||||
| 		BYTE* buffer, | ||||
| 		DWORD size_to_read | ||||
| 	); | ||||
| 
 | ||||
| 	bool _findMediaFileCch( | ||||
| 		wchar_t* dest_path, | ||||
| 		int cch_dest, | ||||
| 		const wchar_t * file_name | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	bool					opened_; | ||||
| 	DWORD					size_; | ||||
| 	CHAR*					buffer_; | ||||
| 	BYTE*					wave_data_; | ||||
| 	HMMIO					hmmio_; | ||||
| 	MMCKINFO				ck_; | ||||
| 	MMCKINFO				ck_riff_; | ||||
| 	WAVEFORMATEX*			wfx_; | ||||
| 	VoiceCallback			callback_; | ||||
| 	IXAudio2SourceVoice*	voice_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 音乐播放器
 | ||||
| class Player | ||||
| { | ||||
| public: | ||||
| 	// 获取播放器实例
 | ||||
| 	static Player * GetInstance(); | ||||
| 
 | ||||
| 	// 销毁实例
 | ||||
| 	static void DestroyInstance(); | ||||
| 
 | ||||
| 	// 预加载音乐资源
 | ||||
| 	bool Preload( | ||||
| 		const String& file_path	/* 音乐文件路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 播放音乐
 | ||||
| 	bool Play( | ||||
| 		const String& file_path,	/* 音乐文件路径 */ | ||||
| 		int loop_count = 0		/* 重复播放次数,设置 -1 为循环播放 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 暂停音乐
 | ||||
| 	void Pause( | ||||
| 		const String& file_path	/* 音乐文件路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续播放音乐
 | ||||
| 	void Resume( | ||||
| 		const String& file_path	/* 音乐文件路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止音乐
 | ||||
| 	void Stop( | ||||
| 		const String& file_path	/* 音乐文件路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取音乐播放状态
 | ||||
| 	bool IsPlaying( | ||||
| 		const String& file_path	/* 音乐文件路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 预加载音乐资源
 | ||||
| 	bool Preload( | ||||
| 		const Resource& res		/* 音乐资源 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 播放音乐
 | ||||
| 	bool Play( | ||||
| 		const Resource& res,	/* 音乐资源 */ | ||||
| 		int loop_count = 0		/* 重复播放次数,设置 -1 为循环播放 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 暂停音乐
 | ||||
| 	void Pause( | ||||
| 		const Resource& res		/* 音乐资源 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续播放音乐
 | ||||
| 	void Resume( | ||||
| 		const Resource& res		/* 音乐资源 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止音乐
 | ||||
| 	void Stop( | ||||
| 		const Resource& res		/* 音乐资源 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取音乐播放状态
 | ||||
| 	bool IsPlaying( | ||||
| 		const Resource& res		/* 音乐资源 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取音量
 | ||||
| 	float GetVolume(); | ||||
| 
 | ||||
| 	// 设置音量
 | ||||
| 	void SetVolume( | ||||
| 		float volume	/* 音量范围为 -224 ~ 224,0 是静音,1 是正常音量 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 暂停所有音乐
 | ||||
| 	void PauseAll(); | ||||
| 
 | ||||
| 	// 继续播放所有音乐
 | ||||
| 	void ResumeAll(); | ||||
| 
 | ||||
| 	// 停止所有音乐
 | ||||
| 	void StopAll(); | ||||
| 
 | ||||
| 	// 清空音乐缓存
 | ||||
| 	void ClearCache(); | ||||
| 
 | ||||
| protected: | ||||
| 	Player(); | ||||
| 
 | ||||
| 	~Player(); | ||||
| 
 | ||||
| 	E2D_DISABLE_COPY(Player); | ||||
| 
 | ||||
| protected: | ||||
| 	float volume_; | ||||
| 	std::map<size_t, Music*> musics_; | ||||
| 
 | ||||
| 	static Player * instance_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class Timer; | ||||
| 
 | ||||
| // 定时任务
 | ||||
| class Task : | ||||
| 	public Ref | ||||
| { | ||||
| 	friend class Timer; | ||||
| 
 | ||||
| public: | ||||
| 	explicit Task( | ||||
| 		const Function& func,		/* 执行函数 */ | ||||
| 		const String& name = L""	/* 任务名称 */ | ||||
| 	); | ||||
| 
 | ||||
| 	explicit Task( | ||||
| 		const Function& func,		/* 执行函数 */ | ||||
| 		float delay,				/* 时间间隔(秒) */ | ||||
| 		int times = -1,				/* 执行次数(设 -1 为永久执行) */ | ||||
| 		const String& name = L""	/* 任务名称 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动任务
 | ||||
| 	void Start(); | ||||
| 
 | ||||
| 	// 停止任务
 | ||||
| 	void Stop(); | ||||
| 
 | ||||
| 	// 任务是否正在执行
 | ||||
| 	bool IsRunning() const; | ||||
| 
 | ||||
| 	// 获取任务名称
 | ||||
| 	const String& GetName() const; | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行任务
 | ||||
| 	void Update(); | ||||
| 
 | ||||
| 	// 任务是否就绪
 | ||||
| 	bool IsReady() const; | ||||
| 
 | ||||
| protected: | ||||
| 	bool		running_; | ||||
| 	bool		stopped_; | ||||
| 	int			run_times_; | ||||
| 	int			total_times_; | ||||
| 	String		name_; | ||||
| 	Duration	delay_; | ||||
| 	Time		last_time_; | ||||
| 	Function	callback_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 定时器
 | ||||
| class Timer | ||||
| { | ||||
| public: | ||||
| 	// 获取定时器实例
 | ||||
| 	static Timer * GetInstance(); | ||||
| 
 | ||||
| 	// 添加任务
 | ||||
| 	void AddTask( | ||||
| 		Task * task | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动任务
 | ||||
| 	void StartTasks( | ||||
| 		const String& task_name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止任务
 | ||||
| 	void StopTasks( | ||||
| 		const String& task_name | ||||
| 	); | ||||
| 
 | ||||
| 	// 移除任务
 | ||||
| 	void RemoveTasks( | ||||
| 		const String& task_name | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动所有任务
 | ||||
| 	void StartAllTasks(); | ||||
| 
 | ||||
| 	// 停止所有任务
 | ||||
| 	void StopAllTasks(); | ||||
| 
 | ||||
| 	// 移除所有任务
 | ||||
| 	void RemoveAllTasks(); | ||||
| 
 | ||||
| 	// 更新定时器
 | ||||
| 	void Update(); | ||||
| 
 | ||||
| 	// 刷新所有任务计时
 | ||||
| 	void UpdateTime(); | ||||
| 
 | ||||
| private: | ||||
| 	Timer(); | ||||
| 
 | ||||
| 	~Timer(); | ||||
| 
 | ||||
| 	E2D_DISABLE_COPY(Timer); | ||||
| 
 | ||||
| private: | ||||
| 	std::vector<Task*> tasks_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 数据管理工具
 | ||||
| class Data | ||||
| { | ||||
| public: | ||||
| 	Data( | ||||
| 		const String& key,					/* 键值 */ | ||||
| 		const String& field = L"Defalut"	/* 字段名称 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 该数据是否存在
 | ||||
| 	bool Exists() const; | ||||
| 
 | ||||
| 	// 保存 int 类型的值
 | ||||
| 	bool SaveInt( | ||||
| 		int value | ||||
| 	); | ||||
| 
 | ||||
| 	// 保存 float 类型的值
 | ||||
| 	bool SaveFloat( | ||||
| 		float value | ||||
| 	); | ||||
| 
 | ||||
| 	// 保存 double 类型的值
 | ||||
| 	bool SaveDouble( | ||||
| 		double value | ||||
| 	); | ||||
| 
 | ||||
| 	// 保存 bool 类型的值
 | ||||
| 	bool SaveBool( | ||||
| 		bool value | ||||
| 	); | ||||
| 
 | ||||
| 	// 保存 String 类型的值
 | ||||
| 	bool SaveString( | ||||
| 		const String& value | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取 int 类型的值
 | ||||
| 	int GetInt() const; | ||||
| 
 | ||||
| 	// 获取 float 类型的值
 | ||||
| 	float GetFloat() const; | ||||
| 
 | ||||
| 	// 获取 double 类型的值
 | ||||
| 	double GetDouble() const; | ||||
| 
 | ||||
| 	// 获取 bool 类型的值
 | ||||
| 	bool GetBool() const; | ||||
| 
 | ||||
| 	// 获取 字符串 类型的值
 | ||||
| 	String GetString(); | ||||
| 
 | ||||
| protected: | ||||
| 	String key_; | ||||
| 	String field_; | ||||
| 	const String& data_path_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 文件
 | ||||
| class File | ||||
| { | ||||
| public: | ||||
| 	File(); | ||||
| 
 | ||||
| 	File( | ||||
| 		const String& file_name | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ~File(); | ||||
| 
 | ||||
| 	// 打开文件
 | ||||
| 	bool Open( | ||||
| 		const String& file_name | ||||
| 	); | ||||
| 
 | ||||
| 	// 文件或文件夹是否存在
 | ||||
| 	bool Exists() const; | ||||
| 
 | ||||
| 	// 是否是文件夹
 | ||||
| 	bool IsFolder() const; | ||||
| 
 | ||||
| 	// 删除文件
 | ||||
| 	bool Delete(); | ||||
| 
 | ||||
| 	// 获取文件路径
 | ||||
| 	const String& GetPath() const; | ||||
| 
 | ||||
| 	// 获取文件扩展名
 | ||||
| 	String GetExtension() const; | ||||
| 
 | ||||
| 	// 释放资源到临时文件目录
 | ||||
| 	static File Extract( | ||||
| 		int resource_name,				/* 资源名称 */ | ||||
| 		const String& resource_type,	/* 资源类型 */ | ||||
| 		const String& dest_file_name	/* 目标文件名 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 添加文件搜索路径
 | ||||
| 	static void AddSearchPath( | ||||
| 		const String& path | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建文件夹
 | ||||
| 	static bool CreateFolder( | ||||
| 		const String& dir_path	/* 文件夹路径 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 弹出打开文件对话框
 | ||||
| 	static File ShowOpenDialog( | ||||
| 		const String& title = L"打开",	/* 对话框标题 */ | ||||
| 		const String& filter = L""		/* 筛选扩展名,例如 "*.jpg;*.jpeg" */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 弹出保存文件对话框
 | ||||
| 	static File ShowSaveDialog( | ||||
| 		const String& title = L"保存",	/* 对话框标题 */ | ||||
| 		const String& def_file = L"",	/* 默认保存的文件名 */ | ||||
| 		const String& def_ext = L""		/* 默认追加的扩展名,例如 "txt" */ | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	DWORD attributes_; | ||||
| 	String file_path_; | ||||
| 
 | ||||
| 	static std::list<String> search_paths_; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 路径
 | ||||
| class Path | ||||
| { | ||||
| 	friend class Game; | ||||
| 
 | ||||
| public: | ||||
| 	// 获取数据的默认保存路径
 | ||||
| 	static const String& GetDataPath(); | ||||
| 
 | ||||
| 	// 获取临时文件目录
 | ||||
| 	static const String& GetTemporaryPath(); | ||||
| 
 | ||||
| 	// 获取 LocalAppData 目录
 | ||||
| 	static const String& GetLocalAppDataPath(); | ||||
| 
 | ||||
| 	// 获取当前程序的运行路径
 | ||||
| 	static const String& GetExeFilePath(); | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -1,5 +1,5 @@ | |||
| #pragma once | ||||
| #include "e2dcommon.h" | ||||
| #include "e2dutil.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
|  |  | |||
							
								
								
									
										1273
									
								
								core/e2dutil.h
								
								
								
								
							
							
						
						
									
										1273
									
								
								core/e2dutil.h
								
								
								
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -18,10 +18,11 @@ | |||
| 
 | ||||
| 
 | ||||
| #include "e2dmacros.h" | ||||
| #include "e2dcommon.h" | ||||
| #include "e2dmanager.h" | ||||
| #include "e2dcomponent.h" | ||||
| #include "e2dutil.h" | ||||
| #include "e2dmanager.h" | ||||
| #include "e2dnode.h" | ||||
| #include "e2dcomponent.h" | ||||
| #include "e2dtool.h" | ||||
| #include "e2daction.h" | ||||
| #include "e2dtransition.h" | ||||
| #include "e2dmodule.h" | ||||
|  |  | |||
|  | @ -19,17 +19,17 @@ | |||
|     </ProjectConfiguration> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2daction.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dbase.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcommon.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcustom.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcomponent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dimpl.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmodule.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmacros.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmanager.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dnode.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtool.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtransition.h" /> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\core\Action\Action.cpp" /> | ||||
|  |  | |||
|  | @ -30,17 +30,17 @@ | |||
|     </Filter> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2daction.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dbase.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcommon.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcustom.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmacros.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmanager.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dnode.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtool.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtransition.h" /> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmodule.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcomponent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dimpl.h" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\core\Action\Action.cpp"> | ||||
|  |  | |||
|  | @ -163,17 +163,17 @@ | |||
|     </Link> | ||||
|   </ItemDefinitionGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2daction.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dbase.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcommon.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcustom.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcomponent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dimpl.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmodule.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmacros.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmanager.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dnode.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtool.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtransition.h" /> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\core\Action\Action.cpp" /> | ||||
|  |  | |||
|  | @ -30,17 +30,17 @@ | |||
|     </Filter> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2daction.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dbase.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcommon.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcustom.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmacros.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmanager.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dnode.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtool.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtransition.h" /> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmodule.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcomponent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dimpl.h" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\core\Action\Action.cpp"> | ||||
|  |  | |||
|  | @ -236,6 +236,9 @@ | |||
|     <ClCompile Include="..\..\core\Common\String.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Common\Image.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Common\Time.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Component\Button.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Component\Menu.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Component\ToggleButton.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Custom\Exception.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Custom\SystemException.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Custom\TextRenderer.cpp" /> | ||||
|  | @ -244,11 +247,8 @@ | |||
|     <ClCompile Include="..\..\core\Event\KeyEvent.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Event\MouseEvent.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Manager\CollisionManager.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Button.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Canvas.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Scene.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\ToggleButton.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Menu.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Node.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Sprite.cpp" /> | ||||
|     <ClCompile Include="..\..\core\Node\Text.cpp" /> | ||||
|  | @ -267,16 +267,17 @@ | |||
|     <ClCompile Include="..\..\core\Transition\MoveTransition.cpp" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\core\e2daction.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dimpl.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dnode.h" /> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2daction.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcomponent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dimpl.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmodule.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcommon.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmacros.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmanager.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcomponent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtool.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtransition.h" /> | ||||
|   </ItemGroup> | ||||
|   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||
|  |  | |||
|  | @ -28,6 +28,9 @@ | |||
|     <Filter Include="Event"> | ||||
|       <UniqueIdentifier>{6c9657de-02d5-4d3b-9e1d-bc921eb5aea3}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="Component"> | ||||
|       <UniqueIdentifier>{7ffdcb87-b6a2-4815-be96-5598f74155ee}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\core\Base\Input.cpp"> | ||||
|  | @ -39,12 +42,6 @@ | |||
|     <ClCompile Include="..\..\core\Common\String.cpp"> | ||||
|       <Filter>Common</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Node\Button.cpp"> | ||||
|       <Filter>Node</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Node\Menu.cpp"> | ||||
|       <Filter>Node</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Node\Node.cpp"> | ||||
|       <Filter>Node</Filter> | ||||
|     </ClCompile> | ||||
|  | @ -174,9 +171,6 @@ | |||
|     <ClCompile Include="..\..\core\Action\FiniteTimeAction.cpp"> | ||||
|       <Filter>Action</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Node\ToggleButton.cpp"> | ||||
|       <Filter>Node</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Common\Rect.cpp"> | ||||
|       <Filter>Common</Filter> | ||||
|     </ClCompile> | ||||
|  | @ -237,18 +231,28 @@ | |||
|     <ClCompile Include="..\..\core\Action\Callback.cpp"> | ||||
|       <Filter>Action</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Component\Button.cpp"> | ||||
|       <Filter>Component</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Component\Menu.cpp"> | ||||
|       <Filter>Component</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\core\Component\ToggleButton.cpp"> | ||||
|       <Filter>Component</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\core\easy2d.h" /> | ||||
|     <ClInclude Include="..\..\core\e2daction.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcommon.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmacros.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmanager.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtransition.h" /> | ||||
|     <ClInclude Include="..\..\core\e2devent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dmodule.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dcomponent.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dimpl.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dnode.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dtool.h" /> | ||||
|     <ClInclude Include="..\..\core\e2dutil.h" /> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
		Loading…
	
		Reference in New Issue