forked from counter185/voidsprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i made controller support but forgot what even for
- Loading branch information
1 parent
b7a22e3
commit eb6114f
Showing
7 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "Gamepad.h" | ||
#include "Notification.h" | ||
|
||
void Gamepad::TryCaptureGamepad() | ||
{ | ||
int n = SDL_NumJoysticks(); | ||
if (n > 0) { | ||
gamepad = SDL_GameControllerOpen(0); | ||
} | ||
|
||
if (gamepad != NULL) { | ||
g_addNotification(Notification("Gamepad connected", SDL_GameControllerName(gamepad))); | ||
} | ||
gamepadConnected = gamepad != NULL; | ||
} | ||
|
||
void Gamepad::TakeEvent(SDL_Event evt) | ||
{ | ||
switch (evt.type) { | ||
case SDL_CONTROLLERDEVICEADDED: | ||
if (!gamepadConnected) { | ||
TryCaptureGamepad(); | ||
} | ||
break; | ||
case SDL_CONTROLLERDEVICEREMOVED: | ||
if (gamepad == NULL || !SDL_GameControllerGetAttached(gamepad)) { | ||
gamepad = NULL; | ||
gamepadConnected = false; | ||
TryCaptureGamepad(); | ||
} | ||
break; | ||
case SDL_CONTROLLERAXISMOTION: | ||
if (evt.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX) { | ||
gamepadLSX = evt.caxis.value / 32768.0f; | ||
} | ||
if (evt.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY) { | ||
gamepadLSY = evt.caxis.value / 32768.0f; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
void Gamepad::SetLightbar(uint8_t r, uint8_t g, uint8_t b) | ||
{ | ||
if (gamepad != NULL) { | ||
SDL_GameControllerSetLED(gamepad, r, g, b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
#include "globals.h" | ||
|
||
class Gamepad | ||
{ | ||
public: | ||
float gamepadLSX = 0, gamepadLSY = 0; | ||
|
||
bool gamepadConnected = false; | ||
SDL_GameController* gamepad = NULL; | ||
void TryCaptureGamepad(); | ||
void TakeEvent(SDL_Event evt); | ||
void SetLightbar(uint8_t r, uint8_t g, uint8_t b); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters