diff --git a/core/Event/Collision.cpp b/core/Event/Collision.cpp index 26833cc1..2d4dd6ed 100644 --- a/core/Event/Collision.cpp +++ b/core/Event/Collision.cpp @@ -1,4 +1,4 @@ -#include "..\e2dcommon.h" +#include "..\e2devent.h" e2d::Collision::Collision() : _node(nullptr) diff --git a/core/Event/KeyEvent.cpp b/core/Event/KeyEvent.cpp index cb854367..da44f263 100644 --- a/core/Event/KeyEvent.cpp +++ b/core/Event/KeyEvent.cpp @@ -1,4 +1,4 @@ -#include "..\e2dcommon.h" +#include "..\e2devent.h" e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) diff --git a/core/Event/MouseEvent.cpp b/core/Event/MouseEvent.cpp index 1a77275d..85419fe6 100644 --- a/core/Event/MouseEvent.cpp +++ b/core/Event/MouseEvent.cpp @@ -1,4 +1,4 @@ -#include "..\e2dcommon.h" +#include "..\e2devent.h" #include "..\e2dbase.h" e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index 2f9420ff..557c1345 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -1,4 +1,5 @@ #include "..\e2dmanager.h" +#include "..\e2devent.h" #include "..\e2dnode.h" #include "..\e2dtransition.h" diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 97d575c1..77cd7f4b 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -1,4 +1,5 @@ #include "..\e2dnode.h" +#include "..\e2devent.h" #include "..\e2dmanager.h" #include "..\e2daction.h" diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 4f21e677..0274d56f 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -372,6 +372,75 @@ private: }; +// 键盘键值 +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 { @@ -505,181 +574,6 @@ public: }; -// 鼠标键值 -enum class MouseCode : int -{ - Left, /* 鼠标左键 */ - Right, /* 鼠标右键 */ - Middle /* 鼠标中键 */ -}; - - -// 键盘键值 -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, -}; - - -// 按键消息 -class KeyEvent -{ -public: - // 按键消息类型 - enum class Type : int - { - Down = 0x0100, // 按下 - Up // 抬起 - }; - -public: - explicit KeyEvent( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam - ); - - // 获取按键键值 - KeyCode getCode() const; - - // 获取按键次数 - int getCount() const; - - // 获取事件类型 - KeyEvent::Type getType() const; - - // VK 键值转换 - static KeyCode convertKeyCode( - WPARAM wParam - ); - -protected: - int _count; - KeyCode _code; - KeyEvent::Type _type; -}; - - -// 鼠标消息 -class MouseEvent -{ -public: - // 鼠标消息类型 - enum class Type : int - { - Move = 0x0200, // 鼠标移动 - LeftDown, // 鼠标左键按下 - LeftUp, // 鼠标左键抬起 - LeftDoubleClick, // 鼠标左键双击 - RightDown, // 鼠标右键按下 - RightUp, // 鼠标右键抬起 - RightDoubleClick, // 鼠标右键双击 - MiddleDown, // 鼠标中键按下 - MiddleUp, // 鼠标中键抬起 - MiddleDoubleClick, // 鼠标中键双击 - Wheel // 滑动滚轮 - }; - -public: - explicit MouseEvent( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam - ); - - // 获取鼠标横坐标 - float getX() const; - - // 获取鼠标纵坐标 - float getY() const; - - // 获取鼠标坐标 - Point getPos() const; - - // 获取事件类型 - MouseEvent::Type getType() const; - - float getWheelDelta() const; - - // 鼠标左键是否按下 - bool isLButtonDown() const; - - // 鼠标右键是否按下 - bool isRButtonDown() const; - - // 鼠标中键是否按下 - bool isMButtonDown() const; - - // Shift 键是否按下 - bool isShiftDown() const; - - // Ctrl 键是否按下 - bool isCtrlDown() const; - -protected: - UINT _message; - WPARAM _wParam; - LPARAM _lParam; - Point _pos; - MouseEvent::Type _type; -}; - - class Node; // 碰撞体 @@ -783,46 +677,6 @@ protected: }; -// 碰撞事件 -class Collision -{ -public: - Collision(); - - explicit Collision( - Node* node, - Collider::Relation relation - ); - - ~Collision(); - - // 获取发生碰撞节点 - Node* getNode() const; - - // 获取交集关系 - Collider::Relation getRelation() const; - -protected: - Node* _node; - Collider::Relation _relation; -}; - - -// 消息处理 -class EventHandler -{ -public: - // 处理按键消息 - virtual void handle(KeyEvent e) { } - - // 处理鼠标消息 - virtual void handle(MouseEvent e) { } - - // 处理碰撞消息 - virtual void handle(Collision collision) { } -}; - - // 资源 class Resource { diff --git a/core/e2devent.h b/core/e2devent.h new file mode 100644 index 00000000..13ddfd8b --- /dev/null +++ b/core/e2devent.h @@ -0,0 +1,153 @@ +#pragma once +#include "e2dcommon.h" + +namespace e2d +{ + + +// 按键消息 +class KeyEvent +{ +public: + // 按键消息类型 + enum class Type : int + { + Down = 0x0100, // 按下 + Up // 抬起 + }; + +public: + explicit KeyEvent( + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam + ); + + // 获取按键键值 + KeyCode getCode() const; + + // 获取按键次数 + int getCount() const; + + // 获取事件类型 + KeyEvent::Type getType() const; + + // VK 键值转换 + static KeyCode convertKeyCode( + WPARAM wParam + ); + +protected: + int _count; + KeyCode _code; + KeyEvent::Type _type; +}; + + +// 鼠标消息 +class MouseEvent +{ +public: + // 鼠标消息类型 + enum class Type : int + { + Move = 0x0200, // 鼠标移动 + LeftDown, // 鼠标左键按下 + LeftUp, // 鼠标左键抬起 + LeftDoubleClick, // 鼠标左键双击 + RightDown, // 鼠标右键按下 + RightUp, // 鼠标右键抬起 + RightDoubleClick, // 鼠标右键双击 + MiddleDown, // 鼠标中键按下 + MiddleUp, // 鼠标中键抬起 + MiddleDoubleClick, // 鼠标中键双击 + Wheel // 滑动滚轮 + }; + +public: + explicit MouseEvent( + HWND hWnd, + UINT message, + WPARAM wParam, + LPARAM lParam + ); + + // 获取鼠标横坐标 + float getX() const; + + // 获取鼠标纵坐标 + float getY() const; + + // 获取鼠标坐标 + Point getPos() const; + + // 获取事件类型 + MouseEvent::Type getType() const; + + float getWheelDelta() const; + + // 鼠标左键是否按下 + bool isLButtonDown() const; + + // 鼠标右键是否按下 + bool isRButtonDown() const; + + // 鼠标中键是否按下 + bool isMButtonDown() const; + + // Shift 键是否按下 + bool isShiftDown() const; + + // Ctrl 键是否按下 + bool isCtrlDown() const; + +protected: + UINT _message; + WPARAM _wParam; + LPARAM _lParam; + Point _pos; + MouseEvent::Type _type; +}; + + +// 碰撞事件 +class Collision +{ +public: + Collision(); + + explicit Collision( + Node* node, + Collider::Relation relation + ); + + ~Collision(); + + // 获取发生碰撞节点 + Node* getNode() const; + + // 获取交集关系 + Collider::Relation getRelation() const; + +protected: + Node * _node; + Collider::Relation _relation; +}; + + +// 消息处理 +class EventHandler +{ +public: + // 处理按键消息 + virtual void handle(KeyEvent e) { } + + // 处理鼠标消息 + virtual void handle(MouseEvent e) { } + + // 处理碰撞消息 + virtual void handle(Collision collision) { } +}; + +} \ No newline at end of file diff --git a/core/e2dmanager.h b/core/e2dmanager.h index 75b31374..edf626fe 100644 --- a/core/e2dmanager.h +++ b/core/e2dmanager.h @@ -9,6 +9,8 @@ namespace e2d class Node; class Scene; class Action; +class KeyEvent; +class MouseEvent; class Transition; diff --git a/core/e2dnode.h b/core/e2dnode.h index 494cc461..bbd9b2b2 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -1,5 +1,6 @@ #pragma once #include "e2dbase.h" +#include "e2devent.h" namespace e2d { diff --git a/project/vs2012/Easy2D.vcxproj b/project/vs2012/Easy2D.vcxproj index b3d57b97..4c3acdcb 100644 --- a/project/vs2012/Easy2D.vcxproj +++ b/project/vs2012/Easy2D.vcxproj @@ -23,6 +23,7 @@ + diff --git a/project/vs2012/Easy2D.vcxproj.filters b/project/vs2012/Easy2D.vcxproj.filters index 23fb53cd..b22b002a 100644 --- a/project/vs2012/Easy2D.vcxproj.filters +++ b/project/vs2012/Easy2D.vcxproj.filters @@ -34,6 +34,7 @@ + diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj index 93a4c667..27272915 100644 --- a/project/vs2013/Easy2D.vcxproj +++ b/project/vs2013/Easy2D.vcxproj @@ -167,6 +167,7 @@ + diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters index ceb284e8..27f5d73f 100644 --- a/project/vs2013/Easy2D.vcxproj.filters +++ b/project/vs2013/Easy2D.vcxproj.filters @@ -34,6 +34,7 @@ + diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 5130057c..b3bf34d2 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -268,6 +268,7 @@ + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index fdfd2378..544586ce 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -246,5 +246,6 @@ + \ No newline at end of file