-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGamepadContext.cpp
More file actions
73 lines (61 loc) · 1.6 KB
/
Copy pathGamepadContext.cpp
File metadata and controls
73 lines (61 loc) · 1.6 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
#include "GamepadContext.h"
#include "InputState.h"
#include "GamepadState.h"
GamepadContext::GamepadContext( ) { }
void GamepadContext::Initialize( int gamepadIndex ) {
m_GamepadIndex = gamepadIndex;
}
void GamepadContext::Deinitialize( ) {
m_GamepadIndex = INVALID_GAMEPAD_INDEX;
}
void GamepadContext::Update() {
m_PressStack.clear();
m_ReleaseStack.clear();
}
bool GamepadContext::HandleEvent( const SDL_Event& event ) {
switch ( event.type ) {
case SDL_CONTROLLERBUTTONDOWN: {
if ( event.cbutton.which == m_GamepadIndex ) {
m_PressStack.push_back( event.cbutton.button );
}
} break;
case SDL_CONTROLLERBUTTONUP: {
if ( event.cbutton.which == m_GamepadIndex ) {
m_ReleaseStack.push_back( event.cbutton.button );
}
} break;
}
return false;
}
bool GamepadContext::ButtonUpDown( SDL_GameControllerButton button ) const {
for ( auto& pressed : m_PressStack ) {
if ( pressed == button ) {
return true;
}
}
return false;
}
bool GamepadContext::ButtonDownUp( SDL_GameControllerButton button ) const {
for ( auto& pressed : m_ReleaseStack ) {
if ( pressed == button ) {
return true;
}
}
return false;
}
bool GamepadContext::ButtonDown( SDL_GameControllerButton button ) const {
const GamepadState* state = g_InputState.GetGamepadState( m_GamepadIndex );
if ( state ) {
return state->ButtonDown( button );
} else {
return false;
}
}
bool GamepadContext::ButtonUp( SDL_GameControllerButton button ) const {
const GamepadState* state = g_InputState.GetGamepadState( m_GamepadIndex );
if ( state ) {
return state->ButtonUp( button );
} else {
return false;
}
}