-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDPInput.cpp
More file actions
115 lines (98 loc) · 2.18 KB
/
DPInput.cpp
File metadata and controls
115 lines (98 loc) · 2.18 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <assert.h>
#include "DPInput.h"
#include "Log.h"
#include <SDL/SDL.h>
DPInput *ginput;
DPInput::DPInput()
{
ginput=this;
joystick = NULL;
if (SDL_NumJoysticks() > 0)
joystick = SDL_JoystickOpen(0);
SDL_EnableUNICODE(1);
//memset( m_keys, 0, 256 );
memset( m_keysScancode, 0, 256 );
};
DPInput::~DPInput()
{
};
void DPInput::Update()
{
m_keys = SDL_GetKeyState(&m_numkeys);
};
void DPInput::SetKeyPressed(int scancode/*, SDLKey key*/, bool pressed)
{
assert(scancode>=0 && scancode<=255);
//assert(key>=0 && key<=255);
//m_keys[key]=pressed;
m_keysScancode[scancode]=pressed;
}
bool DPInput::KeyPressedScancode(int key)
{
return m_keysScancode[key];
};
bool DPInput::KeyPressed(SDLKey key)
{
// if(diKeys[key]&0x80)
// return true;
//if (diKeys[key])
assert(key>=0 && key<m_numkeys);
return m_keys[key];
};
#if 0
bool DPInput::JoyButton(int index)
{
if(!enabled)
return false;
// LogPrint("dinput: checking button %i (numbuttons=%i)", index, joysticks[cur_joystick].num_buttons);
index+=4; // Translate to actual button mapping (to allow for d-pad buttons)
// if(nojoystick || index<0 || index>=joysticks[cur_joystick].num_buttons+4)
// return false;
/* if(joysticks[cur_joystick].button[index])
LogPrint("dinput: joybutton %i=true", index);
else
LogPrint("dinput: joybutton %i=false", index);*/
return joysticks[cur_joystick].button[index];
};
/*
bool DPInput::IsAnalog()
{
return analog;
};
*/
int DPInput::NumJoyAxes()
{
if(nojoystick)
return 0;
return joysticks[cur_joystick].num_axes;
};
int DPInput::NumJoyButtons()
{
if(nojoystick)
return 0;
return joysticks[cur_joystick].num_buttons;
};
void DPInput::SelectJoystick(int id)
{
if(id<0) id=0;
if(id>=num_joysticks) id=num_joysticks-1;
cur_joystick=id;
};
#endif // if 0
float DPInput::JoyAxis(int axis)
{
Sint16 intvalue;
if (joystick) {
intvalue = SDL_JoystickGetAxis(joystick, axis);
return ((float)intvalue + 0.5) / 32767.5f;
}
return 0.0f;
};
void DPInput::Disable()
{
enabled=false;
};
void DPInput::Enable()
{
enabled=true;
};