REPEAT_TRUE/FALSE → enum class Input::Repeat

This commit is contained in:
2026-05-16 19:51:24 +02:00
parent 479d9d941a
commit d72630523a
9 changed files with 42 additions and 41 deletions
+6 -6
View File
@@ -8,29 +8,29 @@ namespace GlobalInputs {
auto handle() -> bool {
if (Screen::get() == nullptr || Input::get() == nullptr) { return false; }
if (Input::get()->checkInput(WINDOW_FULLSCREEN, REPEAT_FALSE)) {
if (Input::get()->checkInput(WINDOW_FULLSCREEN, Input::Repeat::OFF)) {
Screen::get()->toggleVideoMode();
return true;
}
if (Input::get()->checkInput(WINDOW_DEC_ZOOM, REPEAT_FALSE)) {
if (Input::get()->checkInput(WINDOW_DEC_ZOOM, Input::Repeat::OFF)) {
Screen::get()->decWindowZoom();
return true;
}
if (Input::get()->checkInput(WINDOW_INC_ZOOM, REPEAT_FALSE)) {
if (Input::get()->checkInput(WINDOW_INC_ZOOM, Input::Repeat::OFF)) {
Screen::get()->incWindowZoom();
return true;
}
if (Input::get()->checkInput(TOGGLE_SHADER, REPEAT_FALSE)) {
if (Input::get()->checkInput(TOGGLE_SHADER, Input::Repeat::OFF)) {
Screen::get()->toggleShaderEnabled();
return true;
}
// F5/F6 només actuen quan el post-procesado està actiu.
if (Screen::isShaderEnabled()) {
if (Input::get()->checkInput(TOGGLE_SHADER_TYPE, REPEAT_FALSE)) {
if (Input::get()->checkInput(TOGGLE_SHADER_TYPE, Input::Repeat::OFF)) {
Screen::get()->toggleActiveShader();
return true;
}
if (Input::get()->checkInput(NEXT_SHADER_PRESET, REPEAT_FALSE)) {
if (Input::get()->checkInput(NEXT_SHADER_PRESET, Input::Repeat::OFF)) {
Screen::get()->nextPreset();
return true;
}
+5 -5
View File
@@ -104,7 +104,7 @@ void Input::bindGameControllerButton(Uint8 input, SDL_GamepadButton button) {
}
// Comprueba si un input esta activo
auto Input::checkInput(Uint8 input, bool repeat, int device, int index) -> bool {
auto Input::checkInput(Uint8 input, Repeat repeat, int device, int index) -> bool {
if (!enabled_) {
return false;
}
@@ -127,11 +127,11 @@ auto Input::checkInput(Uint8 input, bool repeat, int device, int index) -> bool
}
// Helper de checkInput: comprueba el estado de una tecla
auto Input::checkKeyboardInput(Uint8 input, bool repeat) -> bool {
auto Input::checkKeyboardInput(Uint8 input, Repeat repeat) -> bool {
const bool *key_states = SDL_GetKeyboardState(nullptr);
const bool IS_DOWN = key_states[key_bindings_[input].scancode];
if (repeat) {
if (repeat == Repeat::ON) {
return IS_DOWN;
}
@@ -142,10 +142,10 @@ auto Input::checkKeyboardInput(Uint8 input, bool repeat) -> bool {
}
// Helper de checkInput: comprueba el estado de un botón de mando
auto Input::checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool {
auto Input::checkGameControllerInput(Uint8 input, Repeat repeat, int index) -> bool {
const bool IS_DOWN = SDL_GetGamepadButton(connected_controllers_[index], game_controller_bindings_[input].button);
if (repeat) {
if (repeat == Repeat::ON) {
return IS_DOWN;
}
+9 -8
View File
@@ -6,10 +6,6 @@
#include <string> // for string, basic_string
#include <vector> // for vector
// Valores de repetición
constexpr bool REPEAT_TRUE = true;
constexpr bool REPEAT_FALSE = false;
// Métodos de entrada
constexpr int INPUT_USE_KEYBOARD = 0;
constexpr int INPUT_USE_GAMECONTROLLER = 1;
@@ -52,6 +48,11 @@ enum InputDisable : std::uint8_t {
class Input {
public:
enum class Repeat : std::uint8_t {
OFF,
ON
};
// Singleton API
static void init(const std::string &game_controller_db_path); // Crea la instancia
static void destroy(); // Libera la instancia
@@ -63,8 +64,8 @@ class Input {
void bindKey(Uint8 input, SDL_Scancode code); // Asigna inputs a teclas
void bindGameControllerButton(Uint8 input, SDL_GamepadButton button); // Asigna inputs a botones del mando
auto checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si un input esta activo
auto checkAnyInput(int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo
auto checkInput(Uint8 input, Repeat repeat = Repeat::ON, int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si un input esta activo
auto checkAnyInput(int device = INPUT_USE_ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo
auto discoverGameController() -> bool; // Busca si hay un mando conectado
@@ -117,8 +118,8 @@ class Input {
static auto buildControllerName(SDL_Gamepad *pad, int pad_index) -> std::string;
// Helpers de checkInput
auto checkKeyboardInput(Uint8 input, bool repeat) -> bool;
auto checkGameControllerInput(Uint8 input, bool repeat, int index) -> bool;
auto checkKeyboardInput(Uint8 input, Repeat repeat) -> bool;
auto checkGameControllerInput(Uint8 input, Repeat repeat, int index) -> bool;
// Helpers de discoverGameController
void resetGameControllerState();