From 6eca1b485dba7355d827745284ed2f0072f9e370 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Tue, 26 Mar 2024 10:47:51 +0000 Subject: Use SDL2 support for color and system mouse cursors This way the cursor is not limited by the framerate nor affected by input lag. Also, when custom cursor is disabled, a few different system cursors are now used instead. It also avoids an issue on Wayland, where hiding the cursor (as done to render our own one) would cause the cursor to get locked within the window. On macOS it fixes two cursors being visible when hovering the window while it is in the background. The cursor can unfortunately no longer gently fade away. --- src/resources/resourcemanager.cpp | 15 ++++++++++----- src/resources/resourcemanager.h | 34 ++++++++++++++++++++++------------ src/resources/theme.cpp | 4 +--- 3 files changed, 33 insertions(+), 20 deletions(-) (limited to 'src/resources') diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index e2979f06..f43aea41 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -230,6 +230,11 @@ std::string ResourceManager::getPath(const std::string &file) return path; } +SDL_RWops *ResourceManager::open(const std::string &path) +{ + return PHYSFSRWOPS_openRead(path.c_str()); +} + Resource *ResourceManager::get(const std::string &idPath, const std::function &generator) { @@ -265,10 +270,10 @@ Resource *ResourceManager::get(const std::string &idPath, return resource; } -Resource *ResourceManager::load(const std::string &path, loader fun) +Resource *ResourceManager::get(const std::string &path, loader fun) { return get(path, [&] () -> Resource * { - if (SDL_RWops *rw = PHYSFSRWOPS_openRead(path.c_str())) + if (SDL_RWops *rw = open(path)) return fun(rw); return nullptr; }); @@ -276,12 +281,12 @@ Resource *ResourceManager::load(const std::string &path, loader fun) Music *ResourceManager::getMusic(const std::string &idPath) { - return static_cast(load(idPath, Music::load)); + return static_cast(get(idPath, Music::load)); } SoundEffect *ResourceManager::getSoundEffect(const std::string &idPath) { - return static_cast(load(idPath, SoundEffect::load)); + return static_cast(get(idPath, SoundEffect::load)); } Image *ResourceManager::getImage(const std::string &idPath) @@ -295,7 +300,7 @@ Image *ResourceManager::getImage(const std::string &idPath) d = std::make_unique(path.substr(p + 1)); path = path.substr(0, p); } - SDL_RWops *rw = PHYSFSRWOPS_openRead(path.c_str()); + SDL_RWops *rw = open(path); if (!rw) return nullptr; diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 7a92818f..6694321c 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -104,6 +104,16 @@ class ResourceManager */ std::string getPath(const std::string &file); + /** + * Opens a file for reading. The caller is responsible for closing the + * file. + * + * @param path The file name. + * @return A valid SDL_RWops pointer or NULL if the file + * could not be opened. + */ + SDL_RWops *open(const std::string &path); + /** * Creates a resource and adds it to the resource map. * @@ -124,18 +134,7 @@ class ResourceManager * @return A valid resource or NULL if the resource could * not be loaded. */ - Resource *load(const std::string &path, loader fun); - - /** - * Copies a file from one place to another (useful for extracting - * raw files from a zip archive, for example) - * - * @param src Source file name - * @param dst Destination file name - * @return true on success, false on failure. An error message should be - * in the log file. - */ - bool copyFile(const std::string &src, const std::string &dst); + Resource *get(const std::string &path, loader fun); /** * Convenience wrapper around ResourceManager::get for loading @@ -182,6 +181,17 @@ class ResourceManager void *loadFile(const std::string &filename, int &filesize, bool inflate = true); + /** + * Copies a file from one place to another (useful for extracting + * raw files from a zip archive, for example) + * + * @param src Source file name + * @param dst Destination file name + * @return true on success, false on failure. An error message should be + * in the log file. + */ + bool copyFile(const std::string &src, const std::string &dst); + /** * Retrieves the contents of a text file. */ diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index 1db92feb..67cd6650 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -49,9 +49,7 @@ static void initDefaultThemePath() ResourceManager *resman = ResourceManager::getInstance(); defaultThemePath = branding.getStringValue("guiThemePath"); - if (!defaultThemePath.empty() && resman->isDirectory(defaultThemePath)) - return; - else + if (defaultThemePath.empty() || !resman->isDirectory(defaultThemePath)) defaultThemePath = "graphics/gui/"; } -- cgit v1.2.3-70-g09d2