Skip to content

Commit

Permalink
GunCon: Allow empty/disabled crosshair
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 13, 2024
1 parent 8ec9c90 commit 3cf7a94
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
31 changes: 21 additions & 10 deletions src/core/guncon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,16 @@ static const Controller::ControllerBindingInfo s_binding_info[] = {
#undef BUTTON
};

#ifndef __ANDROID__
static constexpr const char* DEFAULT_CROSSHAIR_PATH = "images" FS_OSPATH_SEPARATOR_STR "crosshair.png";
#else
static constexpr const char* DEFAULT_CROSSHAIR_PATH = "";
#endif

static const SettingInfo s_settings[] = {
{SettingInfo::Type::Path, "CrosshairImagePath", TRANSLATE_NOOP("GunCon", "Crosshair Image Path"),
TRANSLATE_NOOP("GunCon", "Path to an image to use as a crosshair/cursor."), nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, 0.0f},
TRANSLATE_NOOP("GunCon", "Path to an image to use as a crosshair/cursor."), DEFAULT_CROSSHAIR_PATH, nullptr, nullptr,
nullptr, nullptr, nullptr, 0.0f},
{SettingInfo::Type::Float, "CrosshairScale", TRANSLATE_NOOP("GunCon", "Crosshair Image Scale"),
TRANSLATE_NOOP("GunCon", "Scale of crosshair image on screen."), "1.0", "0.0001", "100.0", "0.10", "%.0f%%", nullptr,
100.0f},
Expand All @@ -313,7 +319,7 @@ void GunCon::LoadSettings(const SettingsInterface& si, const char* section, bool

m_x_scale = si.GetFloatValue(section, "XScale", 1.0f);

std::string cursor_path = si.GetStringValue(section, "CrosshairImagePath");
std::string cursor_path = si.GetStringValue(section, "CrosshairImagePath", DEFAULT_CROSSHAIR_PATH);
const float cursor_scale = si.GetFloatValue(section, "CrosshairScale", 1.0f);
u32 cursor_color = 0xFFFFFF;
if (std::string cursor_color_str = si.GetStringValue(section, "CrosshairColor", ""); !cursor_color_str.empty())
Expand All @@ -326,11 +332,6 @@ void GunCon::LoadSettings(const SettingsInterface& si, const char* section, bool
cursor_color = cursor_color_opt.value();
}

#ifndef __ANDROID__
if (cursor_path.empty())
cursor_path = Path::Combine(EmuFolders::Resources, "images/crosshair.png");
#endif

const s32 prev_pointer_index = GetSoftwarePointerIndex();

m_has_relative_binds = (si.ContainsValue(section, "RelativeLeft") || si.ContainsValue(section, "RelativeRight") ||
Expand All @@ -350,15 +351,25 @@ void GunCon::LoadSettings(const SettingsInterface& si, const char* section, bool
}

// Pointer changed, so need to update software cursor.
const bool had_software_cursor = m_cursor_path.empty();
const bool had_software_cursor = !m_cursor_path.empty();
m_cursor_path = std::move(cursor_path);
m_cursor_scale = cursor_scale;
m_cursor_color = cursor_color;
if (static_cast<u32>(new_pointer_index) < InputManager::MAX_SOFTWARE_CURSORS)
{
if (!m_cursor_path.empty())
{
ImGuiManager::SetSoftwareCursor(new_pointer_index, m_cursor_path, m_cursor_scale, m_cursor_color);
std::string image_path;
#ifndef __ANDROID__
if (!Path::IsAbsolute(m_cursor_path))
image_path = Path::Combine(EmuFolders::Resources, m_cursor_path);
else
image_path = m_cursor_path;
#else
image_path = m_cursor_path;
#endif

ImGuiManager::SetSoftwareCursor(new_pointer_index, std::move(image_path), m_cursor_scale, m_cursor_color);
if (m_has_relative_binds)
UpdateSoftwarePointerPosition();
}
Expand Down
31 changes: 21 additions & 10 deletions src/core/justifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,16 @@ static const Controller::ControllerBindingInfo s_binding_info[] = {
#undef BUTTON
};

#ifndef __ANDROID__
static constexpr const char* DEFAULT_CROSSHAIR_PATH = "images" FS_OSPATH_SEPARATOR_STR "crosshair.png";
#else
static constexpr const char* DEFAULT_CROSSHAIR_PATH = "";
#endif

static const SettingInfo s_settings[] = {
{SettingInfo::Type::Path, "CrosshairImagePath", TRANSLATE_NOOP("Justifier", "Crosshair Image Path"),
TRANSLATE_NOOP("Justifier", "Path to an image to use as a crosshair/cursor."), nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, 0.0f},
TRANSLATE_NOOP("Justifier", "Path to an image to use as a crosshair/cursor."), DEFAULT_CROSSHAIR_PATH, nullptr,
nullptr, nullptr, nullptr, nullptr, 0.0f},
{SettingInfo::Type::Float, "CrosshairScale", TRANSLATE_NOOP("Justifier", "Crosshair Image Scale"),
TRANSLATE_NOOP("Justifier", "Scale of crosshair image on screen."), "1.0", "0.0001", "100.0", "0.10", "%.0f%%",
nullptr, 100.0f},
Expand Down Expand Up @@ -402,7 +408,7 @@ void Justifier::LoadSettings(const SettingsInterface& si, const char* section, b

m_x_scale = si.GetFloatValue(section, "XScale", 1.0f);

std::string cursor_path = si.GetStringValue(section, "CrosshairImagePath");
std::string cursor_path = si.GetStringValue(section, "CrosshairImagePath", DEFAULT_CROSSHAIR_PATH);
const float cursor_scale = si.GetFloatValue(section, "CrosshairScale", 1.0f);
u32 cursor_color = 0xFFFFFF;
if (std::string cursor_color_str = si.GetStringValue(section, "CrosshairColor", ""); !cursor_color_str.empty())
Expand All @@ -415,11 +421,6 @@ void Justifier::LoadSettings(const SettingsInterface& si, const char* section, b
cursor_color = cursor_color_opt.value();
}

#ifndef __ANDROID__
if (cursor_path.empty())
cursor_path = Path::Combine(EmuFolders::Resources, "images/crosshair.png");
#endif

const s32 prev_pointer_index = GetSoftwarePointerIndex();

m_has_relative_binds = (si.ContainsValue(section, "RelativeLeft") || si.ContainsValue(section, "RelativeRight") ||
Expand All @@ -439,15 +440,25 @@ void Justifier::LoadSettings(const SettingsInterface& si, const char* section, b
}

// Pointer changed, so need to update software cursor.
const bool had_software_cursor = m_cursor_path.empty();
const bool had_software_cursor = !m_cursor_path.empty();
m_cursor_path = std::move(cursor_path);
m_cursor_scale = cursor_scale;
m_cursor_color = cursor_color;
if (static_cast<u32>(new_pointer_index) < InputManager::MAX_SOFTWARE_CURSORS)
{
if (!m_cursor_path.empty())
{
ImGuiManager::SetSoftwareCursor(new_pointer_index, m_cursor_path, m_cursor_scale, m_cursor_color);
std::string image_path;
#ifndef __ANDROID__
if (!Path::IsAbsolute(m_cursor_path))
image_path = Path::Combine(EmuFolders::Resources, m_cursor_path);
else
image_path = m_cursor_path;
#else
image_path = m_cursor_path;
#endif

ImGuiManager::SetSoftwareCursor(new_pointer_index, std::move(image_path), m_cursor_scale, m_cursor_color);
if (m_has_relative_binds)
UpdateSoftwarePointerPosition();
}
Expand Down

0 comments on commit 3cf7a94

Please sign in to comment.