blob: 169aa8c099a2b7936555303be98b6e064618abf4 (
plain)
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
|
#include <mkb.h>
bool mkb_search(MKb *mkb, SDL_Scancode scancode) {
for (int i=0; i<mkb->kbnum; i++) {
if (mkb->kb[i] == scancode)
return true;
}
return false;
}
bool mkb_statesearch (MKb *mkb, SDL_Scancode scancode) {
const Uint8 *state = SDL_GetKeyboardState(NULL);
if (state[scancode]) return true;
return false;
}
void mkb_init(MKb *mkb) {
mkb->kbnum = 0;
for (int i=0;i<3;mkb->mheld[i]=0,mkb->mclick[i]=0,i++);
mkb->mwheeldelta = 0;
}
void mkb_process(MKb *mkb) {
mkb->kbnum = 0;
SDL_GetMouseState(&(mkb->mx), &(mkb->my));
for (int i=0;i<3;i++) {
if (mkb->mclick[i] > 0) mkb->mheld[i] += 1;
else if (mkb->mheld[i] > 0) mkb->mheld[i] = -1;
else mkb->mheld[i] = 0;
}
mkb->mwheeldelta = 0;
}
void mkb_event(MKb *mkb, SDL_Event *e) {
if(e->type == SDL_KEYDOWN && e->key.repeat == 0) {
mkb->kb[mkb->kbnum++] = e->key.keysym.scancode;
}
if(e->type == SDL_KEYUP) {
}
if(e->type == SDL_MOUSEBUTTONDOWN) {
if (e->button.button == SDL_BUTTON_LEFT) { mkb->mclick[0] = 1; }
if (e->button.button == SDL_BUTTON_MIDDLE) { mkb->mclick[1] = 1; }
if (e->button.button == SDL_BUTTON_RIGHT) { mkb->mclick[2] = 1; }
}
if(e->type == SDL_MOUSEBUTTONUP) {
if (e->button.button == SDL_BUTTON_LEFT) { mkb->mclick[0] = 0; }
if (e->button.button == SDL_BUTTON_MIDDLE) { mkb->mclick[1] = 0; }
if (e->button.button == SDL_BUTTON_RIGHT) { mkb->mclick[2] = 0; }
}
if(e->type == SDL_MOUSEWHEEL) {
mkb->mwheeldelta = e->wheel.y;
}
}
|