Skip to content

Commit

Permalink
ImGuiOverlays: Change icon colour depending on controller mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 18, 2024
1 parent b2577ef commit aa9a5e3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/core/analog_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void AnalogController::Reset()
if (g_settings.controller_disable_analog_mode_forcing || System::IsRunningUnknownGame())
{
Host::AddIconOSDMessage(
fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD,
fmt::format("Controller{}AnalogMode", m_index), ICON_PF_GAMEPAD_ALT,
TRANSLATE_STR("OSDMessage",
"Analog mode forcing is disabled by game settings. Controller will start in digital mode."),
10.0f);
Expand Down Expand Up @@ -279,6 +279,11 @@ std::optional<u32> AnalogController::GetAnalogInputBytes() const
m_axis_state[static_cast<size_t>(Axis::RightY)] << 8 | m_axis_state[static_cast<size_t>(Axis::RightX)];
}

u32 AnalogController::GetInputOverlayIconColor() const
{
return m_analog_mode ? 0xFF2534F0u : 0xFFCCCCCCu;
}

void AnalogController::ResetTransferState()
{
if (m_analog_toggle_queued)
Expand All @@ -300,7 +305,7 @@ void AnalogController::SetAnalogMode(bool enabled, bool show_message)
if (show_message)
{
Host::AddIconOSDMessage(
fmt::format("analog_mode_toggle_{}", m_index), ICON_FA_GAMEPAD,
fmt::format("analog_mode_toggle_{}", m_index), ICON_PF_GAMEPAD_ALT,
enabled ? fmt::format(TRANSLATE_FS("Controller", "Controller {} switched to analog mode."), m_index + 1u) :
fmt::format(TRANSLATE_FS("Controller", "Controller {} switched to digital mode."), m_index + 1u));
}
Expand All @@ -313,7 +318,7 @@ void AnalogController::ProcessAnalogModeToggle()
if (m_analog_locked)
{
Host::AddIconOSDMessage(
fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD,
fmt::format("Controller{}AnalogMode", m_index), ICON_PF_GAMEPAD_ALT,
fmt::format(m_analog_mode ?
TRANSLATE_FS("AnalogController", "Controller {} is locked to analog mode by the game.") :
TRANSLATE_FS("AnalogController", "Controller {} is locked to digital mode by the game."),
Expand Down Expand Up @@ -875,7 +880,7 @@ static const SettingInfo s_settings[] = {
const Controller::ControllerInfo AnalogController::INFO = {ControllerType::AnalogController,
"AnalogController",
TRANSLATE_NOOP("ControllerType", "Analog Controller"),
ICON_PF_GAMEPAD,
ICON_PF_GAMEPAD_ALT,
s_binding_info,
s_settings,
Controller::VibrationCapabilities::LargeSmallMotors};
Expand Down
1 change: 1 addition & 0 deletions src/core/analog_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class AnalogController final : public Controller
void SetBindState(u32 index, float value) override;
u32 GetButtonStateBits() const override;
std::optional<u32> GetAnalogInputBytes() const override;
u32 GetInputOverlayIconColor() const override;

void ResetTransferState() override;
bool Transfer(const u8 data_in, u8* data_out) override;
Expand Down
5 changes: 5 additions & 0 deletions src/core/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ std::optional<u32> Controller::GetAnalogInputBytes() const
return std::nullopt;
}

u32 Controller::GetInputOverlayIconColor() const
{
return 0xFFFFFFFFu;
}

void Controller::LoadSettings(SettingsInterface& si, const char* section)
{
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class Controller
/// Returns analog input bytes packed as a u32. Values are specific to controller type.
virtual std::optional<u32> GetAnalogInputBytes() const;

/// Returns the colour to use in the input overlay.
virtual u32 GetInputOverlayIconColor() const;

/// Loads/refreshes any per-controller settings.
virtual void LoadSettings(SettingsInterface& si, const char* section);

Expand Down
2 changes: 1 addition & 1 deletion src/core/digital_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static const SettingInfo s_settings[] = {
const Controller::ControllerInfo DigitalController::INFO = {ControllerType::DigitalController,
"DigitalController",
TRANSLATE_NOOP("ControllerType", "Digital Controller"),
ICON_PF_GAMEPAD,
ICON_PF_GAMEPAD_ALT,
s_binding_info,
s_settings,
Controller::VibrationCapabilities::NoVibration};
Expand Down
18 changes: 15 additions & 3 deletions src/core/imgui_overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,22 @@ void ImGuiManager::DrawInputsOverlay()
if (!cinfo)
continue;

float text_start_x = current_x;
if (cinfo->icon_name)
text.format("{} {}", cinfo->icon_name, port + 1u);
{
const ImVec2 icon_size = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, cinfo->icon_name);
const u32 icon_color = controller->GetInputOverlayIconColor();
dl->AddText(font, font->FontSize, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color,
cinfo->icon_name, nullptr, 0.0f, &clip_rect);
dl->AddText(font, font->FontSize, ImVec2(current_x, current_y), icon_color, cinfo->icon_name, nullptr, 0.0f,
&clip_rect);
text_start_x += icon_size.x;
text.format(" {}", port + 1u);
}
else
{
text.format("{} |", port + 1u);
}

for (const Controller::ControllerBindingInfo& bi : cinfo->bindings)
{
Expand Down Expand Up @@ -687,9 +699,9 @@ void ImGuiManager::DrawInputsOverlay()
}
}

dl->AddText(font, font->FontSize, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color,
dl->AddText(font, font->FontSize, ImVec2(text_start_x + shadow_offset, current_y + shadow_offset), shadow_color,
text.c_str(), text.end_ptr(), 0.0f, &clip_rect);
dl->AddText(font, font->FontSize, ImVec2(current_x, current_y), text_color, text.c_str(), text.end_ptr(), 0.0f,
dl->AddText(font, font->FontSize, ImVec2(text_start_x, current_y), text_color, text.c_str(), text.end_ptr(), 0.0f,
&clip_rect);

current_y += font->FontSize + spacing;
Expand Down
12 changes: 6 additions & 6 deletions src/util/imgui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,12 @@ bool ImGuiManager::AddIconFonts(float size)
0xf5aa, 0xf5aa, 0xf5e7, 0xf5e7, 0xf65d, 0xf65e, 0xf6a9, 0xf6a9, 0xf6cf, 0xf6cf, 0xf70c, 0xf70c, 0xf794, 0xf794,
0xf7a0, 0xf7a0, 0xf7c2, 0xf7c2, 0xf807, 0xf807, 0xf815, 0xf815, 0xf818, 0xf818, 0xf84c, 0xf84c, 0xf8cc, 0xf8cc,
0x0, 0x0};
static constexpr ImWchar range_pf[] = {0x2196, 0x2199, 0x219e, 0x21a1, 0x21b0, 0x21b3, 0x21ba, 0x21c3, 0x21c7, 0x21ca,
0x21d0, 0x21d4, 0x21dc, 0x21dd, 0x21e0, 0x21e3, 0x21ed, 0x21ee, 0x21f7, 0x21f8,
0x21fa, 0x21fb, 0x227a, 0x227f, 0x2284, 0x2284, 0x235e, 0x235e, 0x2360, 0x2361,
0x2364, 0x2366, 0x23b2, 0x23b4, 0x23ce, 0x23ce, 0x23f4, 0x23f7, 0x2427, 0x243a,
0x243c, 0x243e, 0x2460, 0x246b, 0x24f5, 0x24fd, 0x24ff, 0x24ff, 0x2717, 0x2717,
0x278a, 0x278e, 0x27fc, 0x27fc, 0xe001, 0xe001, 0xff21, 0xff3a, 0x0, 0x0};
static constexpr ImWchar range_pf[] = {
0x2196, 0x2199, 0x219e, 0x21a1, 0x21b0, 0x21b3, 0x21ba, 0x21c3, 0x21c7, 0x21ca, 0x21d0, 0x21d4, 0x21dc,
0x21dd, 0x21e0, 0x21e3, 0x21ed, 0x21ee, 0x21f3, 0x21f3, 0x21f7, 0x21f8, 0x21fa, 0x21fb, 0x227a, 0x227f,
0x2284, 0x2284, 0x235e, 0x235e, 0x2360, 0x2361, 0x2364, 0x2366, 0x23b2, 0x23b4, 0x23ce, 0x23ce, 0x23f4,
0x23f7, 0x2427, 0x243a, 0x243c, 0x243e, 0x2460, 0x246b, 0x24f5, 0x24fd, 0x24ff, 0x24ff, 0x2717, 0x2717,
0x278a, 0x278e, 0x27fc, 0x27fc, 0xe001, 0xe001, 0xff21, 0xff3a, 0x0, 0x0};

{
ImFontConfig cfg;
Expand Down

0 comments on commit aa9a5e3

Please sign in to comment.