-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputHandler.cpp
More file actions
119 lines (100 loc) · 1.92 KB
/
Copy pathInputHandler.cpp
File metadata and controls
119 lines (100 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "Game.h"
#include "InputHandler.h"
InputHandler* InputHandler::s_instance = 0 ;
InputHandler* InputHandler::Instance()
{
if (s_instance == 0)
{
s_instance = new InputHandler();
}
return s_instance;
}
InputHandler::InputHandler()
{
for (size_t i = 0; i < 3; i++)
{
m_mouseButtonStates.push_back(false);
}
m_mousePosition = new Vector2D(0, 0);
}
InputHandler::~InputHandler()
{
}
void InputHandler::Reset()
{
m_mouseButtonStates[LEFT] = false;
m_mouseButtonStates[MIDDLE] = false;
m_mouseButtonStates[RIGHT] = false;
}
bool InputHandler::GetMouseButtonState(int buttonNumber)
{
return m_mouseButtonStates[buttonNumber];
}
Vector2D* InputHandler::GetMousePosition()
{
return m_mousePosition;
}
bool InputHandler::IsKeyDown(SDL_Scancode key)
{
if (m_keystates != 0)
{
if (m_keystates[key] == 1)
{
return true;
}
else
{
return false;
}
}
return false;
}
void InputHandler::Update()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
m_keystates = SDL_GetKeyboardState(0);
if (event.type == SDL_QUIT)
{
Game::Instance()->quit();
}
if (event.type == SDL_MOUSEBUTTONDOWN)
{
if (event.button.button == SDL_BUTTON_LEFT)
{
m_mouseButtonStates[LEFT] = true;
}
if (event.button.button == SDL_BUTTON_MIDDLE)
{
m_mouseButtonStates[MIDDLE] = true;
}
if (event.button.button == SDL_BUTTON_RIGHT)
{
m_mouseButtonStates[RIGHT] = true;
}
}
if (event.type == SDL_MOUSEBUTTONUP)
{
if (event.button.button == SDL_BUTTON_LEFT)
{
m_mouseButtonStates[LEFT] = false;
}
if (event.button.button == SDL_BUTTON_MIDDLE)
{
m_mouseButtonStates[MIDDLE] = false;
}
if (event.button.button == SDL_BUTTON_RIGHT)
{
m_mouseButtonStates[RIGHT] = false;
}
}
if (event.type == SDL_MOUSEMOTION)
{
m_mousePosition->SetX((float)event.motion.x);
m_mousePosition->SetY((float)event.motion.y);
}
}
}
void InputHandler::Clean()
{}