-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdlwrap.cpp
65 lines (47 loc) · 1.22 KB
/
sdlwrap.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
#include "sdlwrap.h"
bool SdlWrap::initialized = false;
QStringList SdlWrap::deviceList;
bool SdlWrap::init() {
if (initialized == true) return true;
if (SDL_Init(SDL_INIT_JOYSTICK) == 0) {
SDL_JoystickUpdate();
initialized = true;
} else {
initialized = false;
}
return initialized;
}
QString SdlWrap::getError() {
return QString(SDL_GetError());
}
QStringList SdlWrap::getJoystickList() {
if (!initialized) {
deviceList.clear();
return deviceList;
}
SDL_JoystickUpdate();
deviceList.clear();
int len = SdlWrap::getNumJoysticks();
if (len == 0) {
deviceList.append(" ");
}
for(int i = 0; i < len; i++) {
QString info = QString(SDL_JoystickNameForIndex(i));
if (!info.isEmpty()) {
deviceList.append(info);
}
}
return deviceList;
}
int SdlWrap::getNumJoysticks() {
if (!initialized) return 0;
return SDL_NumJoysticks();
}
QString SdlWrap::getJoystickName(int index) {
if (!initialized) return 0;
if (index < 0 || index >= SdlWrap::getNumJoysticks()) return "";
return QString(SDL_JoystickNameForIndex(index));
}
bool SdlWrap::ready() {
return initialized;
}