-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.cpp
executable file
·70 lines (64 loc) · 1.65 KB
/
input.cpp
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
int upcount = 0, downcount = 0;
int handle_input()
{
scrolled[SDL_BUTTON_WHEELUP] = false;
scrolled[SDL_BUTTON_WHEELDOWN] = false;
while( SDL_PollEvent( &event ) )
{
if(event.type == SDL_QUIT) quit = true;
else if(event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_w: upcount = 150; break;
case SDLK_UP: upcount = 150; break;
case SDLK_s: downcount = 150; break;
case SDLK_DOWN: downcount = 150; break;
}
}
else if(event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_w: upcount = -1; break;
case SDLK_UP: upcount = -1; break;
case SDLK_s: downcount = -1; break;
case SDLK_DOWN: downcount = -1; break;
}
}
else if(event.type == SDL_MOUSEMOTION)
{
//cout << "mousemove" << endl;
mousex = event.motion.x;
mousey = event.motion.y;
}
else if(event.type == SDL_MOUSEBUTTONDOWN)
{
mousepressed[event.button.button] = true;
if(event.button.button == SDL_BUTTON_WHEELUP) scrolled[SDL_BUTTON_WHEELUP] =true;
if(event.button.button == SDL_BUTTON_WHEELDOWN) scrolled[SDL_BUTTON_WHEELDOWN]=true;
}
else if(event.type == SDL_MOUSEBUTTONUP)
{
mousepressed[event.button.button] = false;
}
}
if(upcount > 0)
{
upcount -= tickselapsed;
if(upcount < 1)
{
scrolled[SDL_BUTTON_WHEELUP] = 1;
upcount += 150;
}
}
if(downcount > 0)
{
downcount -= tickselapsed;
if(downcount < 1)
{
scrolled[SDL_BUTTON_WHEELDOWN] = 1;
downcount += 150;
}
}
}