summaryrefslogtreecommitdiff
path: root/Runtime/Events/InputEvent.h
blob: 5502aea86621207bfdb1a7a0ed4d6b451d0c99cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once

#include <windows.h>
#include "Runtime/Lua/LuaHelper.h"
#include "Runtime/Math/Math.h"

enum EInputEventType
{
	InputEvent_MouseDown = 0, 
	InputEvent_MouseUp = 1, 
	InputEvent_MouseMove = 2, 
	InputEvent_MouseDrag = 3, 
	InputEvent_KeyDown = 4, 
	InputEvent_KeyUp = 5,
	InputEvent_ScrollWheel = 6, 
	InputEvent_Repaint = 7, 
	InputEvent_Layout = 8,
	InputEvent_DragUpdated = 9,
	InputEvent_DragPerform = 10,
	InputEvent_DragExited = 15, 
	InputEvent_Ignore = 11,
	InputEvent_Used = 12,
	InputEvent_ValidateCommand = 13,
	InputEvent_ExecuteCommand = 14,
	InputEvent_ContextClick = 16,
	InputEvent_MouseEnterWindow = 20,
	InputEvent_MouseLeaveWindow = 21, 
	InputEvent_MagnifyGesture = 1000, 
	InputEvent_SwipeGesture = 1001, 
	InputEvent_RotateGesture = 1002
};

enum EModifiers {
    Modifier_Shift = 1 << 0,
    Modifier_Control = 1 << 1,
    Modifier_Alt = 1 << 2,
    Modifier_Command = 1 << 3,
    Modifier_Numeric = 1 << 4,
    Modifier_CapsLock = 1 << 5,
    Modifier_FunctionKey = 1 << 6
};

enum EMouseButton {
    Mouse_LeftButton = 1, 
    Mouse_RightButton = 2, 
    Mouse_MiddleButton = 3
};

// 输入事件,是脚本层面接收和处理的事件
struct InputEvent : public LuaBind::INativeTable
{
	EInputEventType type;

	Vector2f mousePosition;
	Vector2f mouseDelta;

	int      button;        ///< mouse button number. (bitfield of MouseButton enum)
	int      modifiers;     ///< keyboard modifier flags. (bitfield of Modifiers enum)
	float    pressure;      ///< Stylus pressure.
	int      clickCount;
	uint16_t character;     ///< unicode keyboard character (with modifiers).
	uint16_t keycode;       ///< The keyboard scancode of the event.
	int      displayIndex;  ///< Display index to which this event belongs.
	char*    commandString;
	bool     keyRepeat;     ///< Is the event the result of key repeat?

	bool use;

	static InputEvent RepaintEvent(HWND window);

    InputEvent();
    InputEvent(UINT message, WPARAM wParam, LPARAM lParam, HWND window);
	void Init();

	void CastToTable(LuaBind::State& state) const override;
    void RestoreFromTable(LuaBind::State& state, int index) override;

};

namespace Events
{
    bool IsMouseEvent(EInputEventType type);
    bool IsKeyEvent(EInputEventType type);
}