-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse.cpp
More file actions
81 lines (68 loc) · 1.04 KB
/
Mouse.cpp
File metadata and controls
81 lines (68 loc) · 1.04 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
#include"Mouse.h"
Mouse* Mouse::instance = nullptr;
Mouse::Mouse()
{
mx = 0;
my = 0;
clickDown = false;
clickUp = false;
quit = false;
spaceKey = false;
}
Mouse::~Mouse()
{
}
void Mouse::setMouseState()
{
wheel = 0;
setFalseClickUpDown();
SDL_GetMouseState(&mx, &my);
//Handle events on queue
while (SDL_PollEvent(&e) != 0)
{
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT)
{
clickDown = true;
break;
}
else if (e.type == SDL_MOUSEBUTTONUP && e.button.button == SDL_BUTTON_LEFT)
{
clickUp = true;
break;
}
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_SPACE)
{
spaceKey = true;
break;
}
else if(e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_SPACE)
{
spaceKey = false;
break;
}
if (e.type == SDL_QUIT)
{
quit = true;
}
if (e.type == SDL_MOUSEWHEEL)
{
if (e.wheel.y > 0)
{
wheel = -1;
}
else
{
wheel = 1;
}
}
else
{
wheel = 0;
}
}
}
void Mouse::setFalseClickUpDown()
{
clickDown = false;
clickUp = false;
}