Improving menu class. Selector flickers when selecting
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "input.h"
|
||||
#include <stdio.h>
|
||||
//#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
@@ -21,6 +21,8 @@ Input::Input()
|
||||
// Destructor
|
||||
Input::~Input()
|
||||
{
|
||||
SDL_GameControllerClose(mGameController);
|
||||
mGameController = nullptr;
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||
@@ -30,7 +32,7 @@ void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a un botón del mando
|
||||
void Input::bindGameController(Uint8 input, SDL_GameControllerButton button)
|
||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||
{
|
||||
mGameControllerBindings[input].button = button;
|
||||
}
|
||||
@@ -139,7 +141,8 @@ bool Input::discoverGameController()
|
||||
if (SDL_IsGameController(i))
|
||||
mNumGamepads++;
|
||||
|
||||
printf(" (%i joysticks found, %i are gamepads)\n", nJoysticks, mNumGamepads);
|
||||
printf("\nChecking for game controllers...\n");
|
||||
printf("%i joysticks found, %i are gamepads\n", nJoysticks, mNumGamepads);
|
||||
|
||||
if (mNumGamepads > 0)
|
||||
{
|
||||
@@ -150,7 +153,13 @@ bool Input::discoverGameController()
|
||||
// Abre el mando y lo añade a la lista
|
||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
{
|
||||
mConnectedControllers.push_back(pad);
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
std::cout << SDL_GameControllerNameForIndex(i) << std::endl;
|
||||
name.resize(25);
|
||||
mControllerNames.push_back(name);
|
||||
}
|
||||
else
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -169,4 +178,10 @@ bool Input::gameControllerFound()
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
std::string Input::getControllerName(int index)
|
||||
{
|
||||
return mControllerNames[index];
|
||||
}
|
||||
Reference in New Issue
Block a user