From e1bf362d13de7d96019b388a5a89694b3aeae7fd Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 30 Jan 2021 15:49:09 +1000 Subject: [PATCH] CommonHostInterface: Extract ff/turbo hotkeys to functions --- src/frontend-common/common_host_interface.cpp | 58 +++++++++---------- src/frontend-common/common_host_interface.h | 8 +++ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index fb8dc0a35..c8d392b89 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1535,6 +1535,30 @@ bool CommonHostInterface::AddRumbleToInputMap(const std::string& binding, u32 co return false; } +void CommonHostInterface::SetFastForwardEnabled(bool enabled) +{ + if (!System::IsValid()) + return; + + m_fast_forward_enabled = enabled; + UpdateSpeedLimiterState(); + AddOSDMessage(enabled ? TranslateStdString("OSDMessage", "Fast forwarding...") : + TranslateStdString("OSDMessage", "Stopped fast forwarding."), + 2.0f); +} + +void CommonHostInterface::SetTurboEnabled(bool enabled) +{ + if (!System::IsValid()) + return; + + m_turbo_enabled = enabled; + UpdateSpeedLimiterState(); + AddOSDMessage(enabled ? TranslateStdString("OSDMessage", "Turboing...") : + TranslateStdString("OSDMessage", "Stopped turboing."), + 2.0f); +} + void CommonHostInterface::RegisterHotkeys() { RegisterGeneralHotkeys(); @@ -1545,47 +1569,23 @@ void CommonHostInterface::RegisterHotkeys() void CommonHostInterface::RegisterGeneralHotkeys() { + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FastForward"), - TRANSLATABLE("Hotkeys", "Fast Forward"), [this](bool pressed) { - m_fast_forward_enabled = pressed; - UpdateSpeedLimiterState(); - AddOSDMessage(m_fast_forward_enabled ? TranslateStdString("OSDMessage", "Fast forwarding...") : - TranslateStdString("OSDMessage", "Stopped fast forwarding."), - 2.0f); - }); + TRANSLATABLE("Hotkeys", "Fast Forward"), [this](bool pressed) { SetFastForwardEnabled(pressed); }); RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFastForward"), StaticString(TRANSLATABLE("Hotkeys", "Toggle Fast Forward")), [this](bool pressed) { if (pressed) - { - m_fast_forward_enabled = !m_fast_forward_enabled; - UpdateSpeedLimiterState(); - AddOSDMessage(m_fast_forward_enabled ? - TranslateStdString("OSDMessage", "Fast forwarding...") : - TranslateStdString("OSDMessage", "Stopped fast forwarding."), - 2.0f); - } + SetFastForwardEnabled(!m_fast_forward_enabled); }); RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Turbo"), - TRANSLATABLE("Hotkeys", "Turbo"), [this](bool pressed) { - m_turbo_enabled = pressed; - UpdateSpeedLimiterState(); - AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") : - TranslateStdString("OSDMessage", "Stopped turboing."), - 2.0f); - }); + TRANSLATABLE("Hotkeys", "Turbo"), [this](bool pressed) { SetTurboEnabled(pressed); }); RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleTurbo"), StaticString(TRANSLATABLE("Hotkeys", "Toggle Turbo")), [this](bool pressed) { if (pressed) - { - m_turbo_enabled = !m_turbo_enabled; - UpdateSpeedLimiterState(); - AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") : - TranslateStdString("OSDMessage", "Stopped turboing."), - 2.0f); - } + SetTurboEnabled(!m_turbo_enabled); }); #ifndef ANDROID RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFullscreen"), diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 36a0897b2..e948dfbe0 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -222,6 +222,14 @@ public: /// This is the APK for Android builds, or the program directory for standalone builds. virtual std::unique_ptr OpenPackageFile(const char* path, u32 flags) override; + /// Toggles fast forward state. + bool IsFastForwardEnabled() const { return m_fast_forward_enabled; } + void SetFastForwardEnabled(bool enabled); + + /// Toggles turbo state. + bool IsTurboEnabled() const { return m_turbo_enabled; } + void SetTurboEnabled(bool enabled); + protected: enum : u32 {