add e2devent.h

This commit is contained in:
Nomango 2018-08-14 00:41:59 +08:00
parent 1c1f349234
commit 09a3850135
15 changed files with 236 additions and 218 deletions

View File

@ -1,4 +1,4 @@
#include "..\e2dcommon.h" #include "..\e2devent.h"
e2d::Collision::Collision() e2d::Collision::Collision()
: _node(nullptr) : _node(nullptr)

View File

@ -1,4 +1,4 @@
#include "..\e2dcommon.h" #include "..\e2devent.h"
e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

View File

@ -1,4 +1,4 @@
#include "..\e2dcommon.h" #include "..\e2devent.h"
#include "..\e2dbase.h" #include "..\e2dbase.h"
e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

View File

@ -1,4 +1,5 @@
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
#include "..\e2devent.h"
#include "..\e2dnode.h" #include "..\e2dnode.h"
#include "..\e2dtransition.h" #include "..\e2dtransition.h"

View File

@ -1,4 +1,5 @@
#include "..\e2dnode.h" #include "..\e2dnode.h"
#include "..\e2devent.h"
#include "..\e2dmanager.h" #include "..\e2dmanager.h"
#include "..\e2daction.h" #include "..\e2daction.h"

View File

@ -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 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; 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 class Resource
{ {

153
core/e2devent.h Normal file
View File

@ -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) { }
};
}

View File

@ -9,6 +9,8 @@ namespace e2d
class Node; class Node;
class Scene; class Scene;
class Action; class Action;
class KeyEvent;
class MouseEvent;
class Transition; class Transition;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "e2dbase.h" #include "e2dbase.h"
#include "e2devent.h"
namespace e2d namespace e2d
{ {

View File

@ -23,6 +23,7 @@
<ClInclude Include="..\..\core\e2dbase.h" /> <ClInclude Include="..\..\core\e2dbase.h" />
<ClInclude Include="..\..\core\e2dcommon.h" /> <ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dcustom.h" /> <ClInclude Include="..\..\core\e2dcustom.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" /> <ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dnode.h" /> <ClInclude Include="..\..\core\e2dnode.h" />

View File

@ -34,6 +34,7 @@
<ClInclude Include="..\..\core\e2dbase.h" /> <ClInclude Include="..\..\core\e2dbase.h" />
<ClInclude Include="..\..\core\e2dcommon.h" /> <ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dcustom.h" /> <ClInclude Include="..\..\core\e2dcustom.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" /> <ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dnode.h" /> <ClInclude Include="..\..\core\e2dnode.h" />

View File

@ -167,6 +167,7 @@
<ClInclude Include="..\..\core\e2dbase.h" /> <ClInclude Include="..\..\core\e2dbase.h" />
<ClInclude Include="..\..\core\e2dcommon.h" /> <ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dcustom.h" /> <ClInclude Include="..\..\core\e2dcustom.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" /> <ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dnode.h" /> <ClInclude Include="..\..\core\e2dnode.h" />

View File

@ -34,6 +34,7 @@
<ClInclude Include="..\..\core\e2dbase.h" /> <ClInclude Include="..\..\core\e2dbase.h" />
<ClInclude Include="..\..\core\e2dcommon.h" /> <ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dcustom.h" /> <ClInclude Include="..\..\core\e2dcustom.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" /> <ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dnode.h" /> <ClInclude Include="..\..\core\e2dnode.h" />

View File

@ -268,6 +268,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\e2daction.h" /> <ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dcustom.h" /> <ClInclude Include="..\..\core\e2dcustom.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2dbase.h" /> <ClInclude Include="..\..\core\e2dbase.h" />
<ClInclude Include="..\..\core\e2dcommon.h" /> <ClInclude Include="..\..\core\e2dcommon.h" />

View File

@ -246,5 +246,6 @@
<ClInclude Include="..\..\core\e2dtool.h" /> <ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dtransition.h" /> <ClInclude Include="..\..\core\e2dtransition.h" />
<ClInclude Include="..\..\core\e2dcustom.h" /> <ClInclude Include="..\..\core\e2dcustom.h" />
<ClInclude Include="..\..\core\e2devent.h" />
</ItemGroup> </ItemGroup>
</Project> </Project>