Skip to content

Commit

Permalink
Linux build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Murdock committed Nov 22, 2023
1 parent f6d217a commit 948bdca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/gui/widgets/named_savestates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ void PCSX::Widgets::NamedSaveStates::draw(GUI* gui, const char* title) {
ImVec2(-FLT_MIN, glyphWidth + style.FramePadding.y * 2),

Check warning on line 33 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L32-L33

Added lines #L32 - L33 were not covered by tests
ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick)) {
// Copy the name to the input box
strcpy_s(m_namedSaveNameString, 128, saveStatePair.second.c_str());
strcpy(m_namedSaveNameString, saveStatePair.second.c_str());

Check warning on line 36 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L36

Added line #L36 was not covered by tests
// Load the save state if it was a double-click
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
loadSaveState(gui, saveStatePair.first);

Check warning on line 39 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L38-L39

Added lines #L38 - L39 were not covered by tests
}
}
// Add a base coloured rect - highlight it if hovering over the button or the current InputText below matches it
bool matches = strcmpi(m_namedSaveNameString, saveStatePair.second.c_str()) == 0;
bool matches = StringsHelpers::strcasecmp(m_namedSaveNameString, saveStatePair.second.c_str());
bool hovered = ImGui::IsItemHovered();
ImGui::GetWindowDrawList()->AddRectFilled(
ImGui::GetCurrentContext()->LastItemData.Rect.Min, ImGui::GetCurrentContext()->LastItemData.Rect.Max,

Check warning on line 46 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L43-L46

Added lines #L43 - L46 were not covered by tests
Expand Down Expand Up @@ -90,8 +90,8 @@ void PCSX::Widgets::NamedSaveStates::draw(GUI* gui, const char* title) {
}
};

ImGui::InputTextWithHint("##SaveNameInput", "Enter the name of your save state here", m_namedSaveNameString, 128,
ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterNonPathCharacters);
ImGui::InputTextWithHint("##SaveNameInput", "Enter the name of your save state here", m_namedSaveNameString,

Check warning on line 93 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L93

Added line #L93 was not covered by tests
NAMED_SAVE_STATE_LENGTH_MAX, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterNonPathCharacters);
ImGui::SameLine(0.0f, 0.0f);

Check warning on line 95 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L95

Added line #L95 was not covered by tests

// Trailing text alignment also needs adjusting, but in the opposite direction
Expand All @@ -102,7 +102,8 @@ void PCSX::Widgets::NamedSaveStates::draw(GUI* gui, const char* title) {

// Add various buttons based on whether a save state exists with that name
auto found = std::find_if(saveStates.begin(), saveStates.end(), [=](auto saveStatePair) {
return strlen(m_namedSaveNameString) > 0 && strcmpi(m_namedSaveNameString, saveStatePair.second.c_str()) == 0;
return strlen(m_namedSaveNameString) > 0 &&
StringsHelpers::strcasecmp(m_namedSaveNameString, saveStatePair.second.c_str());

Check warning on line 106 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L104-L106

Added lines #L104 - L106 were not covered by tests
});
bool exists = found != saveStates.end();

Check warning on line 108 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L108

Added line #L108 was not covered by tests

Expand Down Expand Up @@ -155,7 +156,10 @@ std::vector<std::pair<std::filesystem::path, std::string>> PCSX::Widgets::NamedS
if (filename.find(prefix) == 0 &&
filename.rfind(postfix) == filename.length() - postfix.length()) {
std::string niceName = filename.substr(prefix.length(), filename.length() - (prefix.length() + postfix.length()));

Check warning on line 158 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L151-L158

Added lines #L151 - L158 were not covered by tests
names.emplace_back(entry.path(), niceName);
// Only support names that fit within the character limit
if (niceName.length() < NAMED_SAVE_STATE_LENGTH_MAX) {
names.emplace_back(entry.path(), niceName);

Check warning on line 161 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L160-L161

Added lines #L160 - L161 were not covered by tests
}
}
}
}

Check warning on line 165 in src/gui/widgets/named_savestates.cc

View check run for this annotation

Codecov / codecov/patch

src/gui/widgets/named_savestates.cc#L163-L165

Added lines #L163 - L165 were not covered by tests
Expand Down
5 changes: 4 additions & 1 deletion src/gui/widgets/named_savestates.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ class NamedSaveStates {
std::vector<std::pair<std::filesystem::path, std::string>> getNamedSaveStates(GUI* gui);

private:

static constexpr int NAMED_SAVE_STATE_LENGTH_MAX = 128;

void saveSaveState(GUI* gui, std::filesystem::path saveStatePath);
void loadSaveState(GUI* gui, std::filesystem::path saveStatePath);
void deleteSaveState(std::filesystem::path saveStatePath);

char m_namedSaveNameString[128] = "";
char m_namedSaveNameString[NAMED_SAVE_STATE_LENGTH_MAX] = "";
};

} // namespace Widgets
Expand Down

0 comments on commit 948bdca

Please sign in to comment.