-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keyboard.cpp
50 lines (41 loc) · 1.04 KB
/
Keyboard.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
#include <iostream>
#include <SDL.h>
#include "Keyboard.hpp"
Keyboard* Keyboard::mInstance = 0;
Keyboard* Keyboard::instance(){
return mInstance;
}
void Keyboard::create(){
try{
if(mInstance) throw "[*ERROR*] Keyboard::create() cannnot create instance twice";
mInstance = new Keyboard();
}catch(char *error){
fprintf(stderr,"%s\n",error);
abort();
}
}
void Keyboard::destroy(){
delete mInstance;
}
bool Keyboard::is_keyon(SDL_Keycode key){
if(keys.find( key ) == keys.end()) return false;
return keys[key] == KEY_PUSH;
}
bool Keyboard::is_keyoff(SDL_Keycode key){
if(keys.find( key ) == keys.end()) return true;
return keys[key] == KEY_RELEASE;
}
bool Keyboard::is_keytoggle(SDL_Keycode key){
if(keys.find( key ) == keys.end()) return false;
return keys[key] == KEY_TOGGLE;
}
void Keyboard::keyon(SDL_Keycode key){
if(keys[key] != KEY_TOGGLE)
keys[key] = KEY_PUSH;
}
void Keyboard::keyoff(SDL_Keycode key){
keys[key] = KEY_RELEASE;
}
void Keyboard::keytoggle(SDL_Keycode key){
keys[key] = KEY_TOGGLE;
}