| 
									
										
										
										
											2018-10-03 22:02:46 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | #pragma once
 | 
					
						
							|  |  |  |  | #include "macros.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | #include "keys.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 00:21:59 +08:00
										 |  |  |  | namespace easy2d | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | 
					
						
							|  |  |  |  | 	struct MouseEvent | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 		float x; | 
					
						
							|  |  |  |  | 		float y; | 
					
						
							|  |  |  |  | 		bool left_btn_down;		// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		bool right_btn_down;	// <20>Ҽ<EFBFBD><D2BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		struct	// Events::MouseDown | Events::MouseUp | Events::MouseClick | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 			int button; | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 		}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		struct	// Events::MouseWheel | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 			float wheel; | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 		}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		static bool Check(UINT type); | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | 
					
						
							|  |  |  |  | 	struct KeyboardEvent | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		int code;		// enum KeyCode
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 		int count; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		static bool Check(UINT type); | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2018-05-10 18:18:02 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | 
					
						
							|  |  |  |  | 	struct WindowEvent | 
					
						
							| 
									
										
										
										
											2018-11-22 19:31:44 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  |  | 		union | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 			struct		// Events::WindowMoved | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				int x; | 
					
						
							|  |  |  |  | 				int y; | 
					
						
							|  |  |  |  | 			}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 			struct		// Events::WindowResized | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				int width; | 
					
						
							|  |  |  |  | 				int height; | 
					
						
							|  |  |  |  | 			}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 			struct		// Events::WindowFocusChanged | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				bool focus; | 
					
						
							|  |  |  |  | 			}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 			struct		// Events::WindowTitleChanged | 
					
						
							| 
									
										
										
										
											2019-01-24 22:22:11 +08:00
										 |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				const wchar_t* title; | 
					
						
							|  |  |  |  | 			}; | 
					
						
							|  |  |  |  | 		}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		static bool Check(UINT type); | 
					
						
							|  |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>¼<EFBFBD>
 | 
					
						
							|  |  |  |  | 	struct CustomEvent | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		void* data; | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 	}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20>¼<EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2019-02-09 00:03:24 +08:00
										 |  |  |  | 	struct E2D_API Event | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		enum Type : UINT | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			First, | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | 
					
						
							|  |  |  |  | 			MouseFirst, | 
					
						
							|  |  |  |  | 			MouseMove,			// <20>ƶ<EFBFBD>
 | 
					
						
							|  |  |  |  | 			MouseBtnDown,		// <20><><EFBFBD>갴<EFBFBD><EAB0B4>
 | 
					
						
							|  |  |  |  | 			MouseBtnUp,			// <20><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7>
 | 
					
						
							|  |  |  |  | 			MouseWheel,			// <20><><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>
 | 
					
						
							|  |  |  |  | 			MouseHover,			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			MouseOut,			// <20><><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
 | 
					
						
							|  |  |  |  | 			Click,				// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			MouseLast, | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | 
					
						
							|  |  |  |  | 			KeyFirst, | 
					
						
							|  |  |  |  | 			KeyDown,			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			KeyUp,				// <20><><EFBFBD><EFBFBD>̧<EFBFBD><CCA7>
 | 
					
						
							|  |  |  |  | 			KeyLast, | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 			WindowFirst, | 
					
						
							|  |  |  |  | 			WindowMoved,		// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
 | 
					
						
							|  |  |  |  | 			WindowResized,		// <20><><EFBFBD>ڴ<EFBFBD>С<EFBFBD>仯
 | 
					
						
							|  |  |  |  | 			WindowFocusChanged,	// <20><><EFBFBD>û<EFBFBD>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			WindowTitleChanged,	// <20><><EFBFBD><EFBFBD><EFBFBD>仯
 | 
					
						
							|  |  |  |  | 			WindowClosed,		// <20><><EFBFBD>ڱ<EFBFBD><DAB1>ر<EFBFBD>
 | 
					
						
							|  |  |  |  | 			WindowLast, | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			Last | 
					
						
							|  |  |  |  | 		}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		UINT type; | 
					
						
							| 
									
										
										
										
											2019-01-26 13:09:58 +08:00
										 |  |  |  | 		Node* target; | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		union | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			MouseEvent mouse; | 
					
						
							|  |  |  |  | 			KeyboardEvent key; | 
					
						
							|  |  |  |  | 			WindowEvent win; | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 			CustomEvent custom; | 
					
						
							| 
									
										
										
										
											2019-01-24 12:21:01 +08:00
										 |  |  |  | 		}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 		Event(UINT type = Type::First) : type(type), target(nullptr) {} | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2019-02-12 16:12:15 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// Check-functions
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	inline bool MouseEvent::Check(UINT type) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return type > Event::MouseFirst && type < Event::MouseLast; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	inline bool KeyboardEvent::Check(UINT type) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return type > Event::KeyFirst && type < Event::KeyLast; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	inline bool WindowEvent::Check(UINT type) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		return type > Event::WindowFirst && type < Event::WindowLast; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 21:39:26 +08:00
										 |  |  |  | } |