Repository navigation
Expand file tree
/
Copy pathInput.cpp
More file actions
94 lines (79 loc) · 1.92 KB
/
Copy pathInput.cpp
File metadata and controls
94 lines (79 loc) · 1.92 KB
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
85
86
87
88
89
90
91
92
93
94
#include "Input.h"
#include "RenderableThing.h"
BOOL Input::Init(int w, int h)
{
mouse.leftButton = FALSE;
mouse.righBtutton = FALSE;
mouse.location.x = w / 2;
mouse.location.y = h / 2;
ZeroMemory(keyboard, sizeof(keyboard));
return TRUE;
}
void Input::CopyData(Input *input)
{
input->mouse = mouse;
memcpy(&input->keyboard, keyboard, sizeof(keyboard));
}
BOOL Input::IsPressed(unsigned int key)
{
return (key < MAX_KEYS) ? (keyboard[key] == TRUE) : FALSE;
}
Input::MouseState Input::GetMouseState()
{
return mouse;
}
void Input::Frame(UINT uMessage, WPARAM wParam, LPARAM lParam)
{
switch (uMessage)
{
case WM_KEYDOWN: //键盘按下
if ((unsigned int)wParam < MAX_KEYS)
{
keyboard[(unsigned int)wParam] = TRUE;
}
break;
case WM_KEYUP: //键盘弹起
if ((unsigned int)wParam < MAX_KEYS)
{
keyboard[(unsigned int)wParam] = FALSE;
}
break;
case WM_LBUTTONDBLCLK: //鼠标左键按下
mouse.leftButton = TRUE;
break;
case WM_LBUTTONUP: //鼠标左键弹起
mouse.leftButton = FALSE;
break;
case WM_RBUTTONDBLCLK: //鼠标右键按下
mouse.righBtutton = TRUE;
break;
case WM_RBUTTONUP: //鼠标右键弹起
mouse.righBtutton = FALSE;
break;
case WM_MOUSEMOVE: //鼠标移动,坐标相对于用户区,原点左上角
mouse.location = MAKEPOINTS(lParam);
break;
}
}
void Input::AddObserver(RenderableThing *obs)
{
observers.push_back(obs);
}
void Input::DeleteObserver(RenderableThing *obs)
{
for(auto it = observers.begin(); it != observers.end(); ++it)
{
if((*it) == obs)
{
observers.erase(it);
break;
}
}
}
void Input::InforObservers()
{
for(auto it = observers.begin(); it != observers.end(); ++it)
{
(*it)->HandleInput(this);
}
}