diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-26 10:47:51 +0000 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-26 10:47:51 +0000 |
commit | 6eca1b485dba7355d827745284ed2f0072f9e370 (patch) | |
tree | 6298e90b5ec5802ac26c9a8b674c7cbd59d0c048 /src/gui/gui.h | |
parent | 5dd1950adfef870b26670cbee938513433953d19 (diff) | |
download | mana-6eca1b485dba7355d827745284ed2f0072f9e370.tar.gz mana-6eca1b485dba7355d827745284ed2f0072f9e370.tar.bz2 mana-6eca1b485dba7355d827745284ed2f0072f9e370.tar.xz mana-6eca1b485dba7355d827745284ed2f0072f9e370.zip |
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.
Diffstat (limited to 'src/gui/gui.h')
-rw-r--r-- | src/gui/gui.h | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/gui/gui.h b/src/gui/gui.h index 29dcdef2..e5f5149a 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -22,14 +22,17 @@ #ifndef GUI_H #define GUI_H +#include "eventlistener.h" #include "guichanfwd.h" #include <guichan/gui.hpp> +#include <SDL.h> + +#include <vector> + class TextInput; class Graphics; -class GuiConfigListener; -class ImageSet; class SDLInput; /** @@ -65,7 +68,7 @@ enum class Cursor { * * \ingroup GUI */ -class Gui : public gcn::Gui +class Gui : public gcn::Gui, public EventListener { public: Gui(Graphics *screen); @@ -78,11 +81,7 @@ class Gui : public gcn::Gui */ void logic() override; - /** - * Draws the whole Gui by calling draw functions down in the - * Gui hierarchy. It also draws the mouse pointer. - */ - void draw() override; + void event(Event::Channel channel, const Event &event) override; /** * Called when the application window has been resized. @@ -115,21 +114,25 @@ class Gui : public gcn::Gui /** * Sets which cursor should be used. */ - void setCursorType(Cursor index) - { mCursorType = index; } + void setCursorType(Cursor cursor); protected: void handleMouseMoved(const gcn::MouseInput &mouseInput) override; void handleTextInput(const TextInput &textInput); private: - GuiConfigListener *mConfigListener; + void updateCursor(); + + void loadCustomCursors(); + void loadSystemCursors(); + gcn::Font *mGuiFont; /**< The global GUI font */ gcn::Font *mInfoParticleFont; /**< Font for Info Particles*/ bool mCustomCursor = false; /**< Show custom cursor */ - ImageSet *mMouseCursors = nullptr; /**< Mouse cursor images */ - float mMouseCursorAlpha = 1.0f; - int mMouseInactivityTimer = 0; + float mCustomCursorScale = 1.0f; + std::vector<SDL_Cursor *> mSystemMouseCursors; + std::vector<SDL_Cursor *> mCustomMouseCursors; + int mLastMouseActivityTime = 0; Cursor mCursorType = Cursor::POINTER; }; |