180 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			C++
		
	
	
	
		
		
			
		
	
	
			180 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			C++
		
	
	
	
|  | // Copyright (c) 2016-2018 Easy2D - Nomango
 | |||
|  | // 
 | |||
|  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | |||
|  | // of this software and associated documentation files (the "Software"), to deal
 | |||
|  | // in the Software without restriction, including without limitation the rights
 | |||
|  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | |||
|  | // copies of the Software, and to permit persons to whom the Software is
 | |||
|  | // furnished to do so, subject to the following conditions:
 | |||
|  | // 
 | |||
|  | // The above copyright notice and this permission notice shall be included in
 | |||
|  | // all copies or substantial portions of the Software.
 | |||
|  | // 
 | |||
|  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | |||
|  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | |||
|  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | |||
|  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | |||
|  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | |||
|  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | |||
|  | // THE SOFTWARE.
 | |||
|  | 
 | |||
|  | #pragma once
 | |||
|  | #include "keys.hpp"
 | |||
|  | 
 | |||
|  | namespace easy2d | |||
|  | { | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | |||
|  | 	struct MouseEvent | |||
|  | 	{ | |||
|  | 		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>
 | |||
|  | 
 | |||
|  | 		union | |||
|  | 		{ | |||
|  | 			struct	// Events::MouseDown | Events::MouseUp | Events::MouseClick | |||
|  | 			{ | |||
|  | 				int button; | |||
|  | 			}; | |||
|  | 
 | |||
|  | 			struct	// Events::MouseWheel | |||
|  | 			{ | |||
|  | 				float wheel; | |||
|  | 			}; | |||
|  | 		}; | |||
|  | 
 | |||
|  | 		static bool Check(UINT type); | |||
|  | 	}; | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | |||
|  | 	struct KeyboardEvent | |||
|  | 	{ | |||
|  | 		int count; | |||
|  | 		union | |||
|  | 		{ | |||
|  | 			struct	// Events::KeyDown | Events::KeyUp | |||
|  | 			{ | |||
|  | 				int code;		// enum KeyCode
 | |||
|  | 			}; | |||
|  | 
 | |||
|  | 			struct	// Events::Char | |||
|  | 			{ | |||
|  | 				char c; | |||
|  | 			}; | |||
|  | 		}; | |||
|  | 
 | |||
|  | 		static bool Check(UINT type); | |||
|  | 	}; | |||
|  | 
 | |||
|  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
 | |||
|  | 	struct WindowEvent | |||
|  | 	{ | |||
|  | 		union | |||
|  | 		{ | |||
|  | 			struct		// Events::WindowMoved | |||
|  | 			{ | |||
|  | 				int x; | |||
|  | 				int y; | |||
|  | 			}; | |||
|  | 
 | |||
|  | 			struct		// Events::WindowResized | |||
|  | 			{ | |||
|  | 				int width; | |||
|  | 				int height; | |||
|  | 			}; | |||
|  | 
 | |||
|  | 			struct		// Events::WindowFocusChanged | |||
|  | 			{ | |||
|  | 				bool focus; | |||
|  | 			}; | |||
|  | 
 | |||
|  | 			struct		// Events::WindowTitleChanged | |||
|  | 			{ | |||
|  | 				const wchar_t* title; | |||
|  | 			}; | |||
|  | 		}; | |||
|  | 
 | |||
|  | 		static bool Check(UINT type); | |||
|  | 	}; | |||
|  | 
 | |||
|  | 	// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>¼<EFBFBD>
 | |||
|  | 	struct CustomEvent | |||
|  | 	{ | |||
|  | 		void* data; | |||
|  | 	}; | |||
|  | 
 | |||
|  | 	class Node; | |||
|  | 
 | |||
|  | 	// <20>¼<EFBFBD>
 | |||
|  | 	struct E2D_API Event | |||
|  | 	{ | |||
|  | 		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>
 | |||
|  | 			Char,				// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
 | |||
|  | 			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; | |||
|  | 		Node* target; | |||
|  | 
 | |||
|  | 		union | |||
|  | 		{ | |||
|  | 			MouseEvent mouse; | |||
|  | 			KeyboardEvent key; | |||
|  | 			WindowEvent win; | |||
|  | 			CustomEvent custom; | |||
|  | 		}; | |||
|  | 
 | |||
|  | 		Event(UINT type = Type::First) : type(type), target(nullptr) {} | |||
|  | 	}; | |||
|  | 
 | |||
|  | 
 | |||
|  | 	// 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; | |||
|  | 	} | |||
|  | 
 | |||
|  | } |