-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
55 lines (48 loc) · 1.27 KB
/
input.c
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
#include "headers/common.h"
#include "headers/defs.h"
extern bool running;
extern int keyboard[MAX_KEYBOARD_KEYS];
void addPixel(void);
void removePixel(void);
void displayList(void);
void free_pixels(void);
void registerInput(void){
if(keyboard[SDL_SCANCODE_LCTRL]){
printf("Adding pixel to screen!\n");
addPixel();
}
if(keyboard[SDL_SCANCODE_RCTRL]){
printf("Displaying list...\n");
removePixel();
displayList();
}
}
// Handles input such as reading the keyboard
static void doKeyDown(SDL_KeyboardEvent *event){
if(event->repeat == 0 && event->keysym.scancode < MAX_KEYBOARD_KEYS){
keyboard[event->keysym.scancode] = 1;
}
}
static void doKeyUp(SDL_KeyboardEvent *event){
if(event->repeat == 0 && event->keysym.scancode < MAX_KEYBOARD_KEYS){
keyboard[event->keysym.scancode] = 0;
}
}
void doInput(void){
SDL_Event event;
while(SDL_PollEvent(&event)){
switch(event.type){
case SDL_QUIT:
running = 0;
break;
case SDL_KEYDOWN:
doKeyDown(&event.key);
break;
case SDL_KEYUP:
doKeyUp(&event.key);
break;
default:
break;
}
}
}