Change Background Image for games (#2334)

* Added opacity change instead of blur for background image

* Fixed integer overflow when refreshing grid list

* Added slider to control background image opacity

* Added show background image button

* Added UI code for checkbox and English and Spanish translations for new UI elements

* Removed background image caching

* Background image update on apply/save

* Only recompute image if opacity or game changes

* Fixed segfault when trying to change opacity after table refresh

* Placed background image settings under GUI in settings file
This commit is contained in:
pdaloxd 2025-02-04 08:33:38 +01:00 committed by GitHub
parent 363604c6f0
commit b6ad512e34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 279 additions and 56 deletions

View file

@ -95,6 +95,8 @@ std::vector<std::string> m_pkg_viewer;
std::vector<std::string> m_elf_viewer;
std::vector<std::string> m_recent_files;
std::string emulator_language = "en";
static int backgroundImageOpacity = 50;
static bool showBackgroundImage = true;
// Language
u32 m_language = 1; // english
@ -611,6 +613,22 @@ u32 GetLanguage() {
return m_language;
}
int getBackgroundImageOpacity() {
return backgroundImageOpacity;
}
void setBackgroundImageOpacity(int opacity) {
backgroundImageOpacity = std::clamp(opacity, 0, 100);
}
bool getShowBackgroundImage() {
return showBackgroundImage;
}
void setShowBackgroundImage(bool show) {
showBackgroundImage = show;
}
void load(const std::filesystem::path& path) {
// If the configuration file does not exist, create it and return
std::error_code error;
@ -731,6 +749,8 @@ void load(const std::filesystem::path& path) {
m_recent_files = toml::find_or<std::vector<std::string>>(gui, "recentFiles", {});
m_table_mode = toml::find_or<int>(gui, "gameTableMode", 0);
emulator_language = toml::find_or<std::string>(gui, "emulatorLanguage", "en");
backgroundImageOpacity = toml::find_or<int>(gui, "backgroundImageOpacity", 50);
showBackgroundImage = toml::find_or<bool>(gui, "showBackgroundImage", true);
}
if (data.contains("Settings")) {
@ -821,6 +841,8 @@ void save(const std::filesystem::path& path) {
data["GUI"]["addonInstallDir"] =
std::string{fmt::UTF(settings_addon_install_dir.u8string()).data};
data["GUI"]["emulatorLanguage"] = emulator_language;
data["GUI"]["backgroundImageOpacity"] = backgroundImageOpacity;
data["GUI"]["showBackgroundImage"] = showBackgroundImage;
data["Settings"]["consoleLanguage"] = m_language;
std::ofstream file(path, std::ios::binary);
@ -914,6 +936,8 @@ void setDefaultValues() {
separateupdatefolder = false;
compatibilityData = false;
checkCompatibilityOnStartup = false;
backgroundImageOpacity = 50;
showBackgroundImage = true;
}
constexpr std::string_view GetDefaultKeyboardConfig() {

View file

@ -30,6 +30,8 @@ bool getEnableDiscordRPC();
bool getSeparateUpdateEnabled();
bool getCompatibilityEnabled();
bool getCheckCompatibilityOnStartup();
int getBackgroundImageOpacity();
bool getShowBackgroundImage();
std::string getLogFilter();
std::string getLogType();
@ -88,6 +90,8 @@ void setGameInstallDirs(const std::vector<std::filesystem::path>& settings_insta
void setSaveDataPath(const std::filesystem::path& path);
void setCompatibilityEnabled(bool use);
void setCheckCompatibilityOnStartup(bool use);
void setBackgroundImageOpacity(int opacity);
void setShowBackgroundImage(bool show);
void setCursorState(s16 cursorState);
void setCursorHideTimeout(int newcursorHideTimeout);