diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-12-05 23:01:54 +0100 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2008-12-05 15:55:53 -0700 |
commit | 1777c9b48e93e6c5a7aaf5101397566ad61789e1 (patch) | |
tree | 7486d59200ac7826fac8f84bd590efb752e0367b | |
parent | 032f7659014d265a3c34765da2f277b7b0f32691 (diff) | |
download | mana-client-1777c9b48e93e6c5a7aaf5101397566ad61789e1.tar.gz mana-client-1777c9b48e93e6c5a7aaf5101397566ad61789e1.tar.bz2 mana-client-1777c9b48e93e6c5a7aaf5101397566ad61789e1.tar.xz mana-client-1777c9b48e93e6c5a7aaf5101397566ad61789e1.zip |
Fade out mouse cursor when not used for some time
The mouse cursor will now disappear when not used for 15 seconds. When
using OpenGL it will even fade.
Requested by doorsman.
-rw-r--r-- | src/gui/gui.cpp | 47 | ||||
-rw-r--r-- | src/gui/gui.h | 11 |
2 files changed, 46 insertions, 12 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index fcc7ed77..a382ef85 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -37,6 +37,7 @@ #include "../graphics.h" #include "../log.h" +#include "../resources/image.h" #include "../resources/imageset.h" #include "../resources/imageloader.h" #include "../resources/resourcemanager.h" @@ -81,6 +82,8 @@ class GuiConfigListener : public ConfigListener Gui::Gui(Graphics *graphics): mCustomCursor(false), mMouseCursors(NULL), + mMouseCursorAlpha(1.0f), + mMouseInactivityTimer(0), mCursorType(CURSOR_POINTER) { logger->log("Initializing GUI..."); @@ -220,32 +223,47 @@ Gui::~Gui() delete hitBlueFont; delete hitYellowFont; - if (mMouseCursors) { + if (mMouseCursors) mMouseCursors->decRef(); - } delete mGuiFont; delete speechFont; delete viewport; - delete mTop; + delete getTop(); delete guiInput; } -void -Gui::draw() +void Gui::logic() +{ + // Fade out mouse cursor after extended inactivity + if (mMouseInactivityTimer < 100 * 15) { + ++mMouseInactivityTimer; + mMouseCursorAlpha = std::min(1.0f, mMouseCursorAlpha + 0.05f); + } else { + mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f); + } + + gcn::Gui::logic(); +} + +void Gui::draw() { - mGraphics->pushClipArea(mTop->getDimension()); - mTop->draw(mGraphics); + mGraphics->pushClipArea(getTop()->getDimension()); + getTop()->draw(mGraphics); int mouseX, mouseY; Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); - if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) && - mCustomCursor) + if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1)) + && mCustomCursor + && mMouseCursorAlpha > 0.0f) { + Image *mouseCursor = mMouseCursors->get(mCursorType); + mouseCursor->setAlpha(mMouseCursorAlpha); + static_cast<Graphics*>(mGraphics)->drawImage( - mMouseCursors->get(mCursorType), + mouseCursor, mouseX - 15, mouseY - 17); } @@ -253,8 +271,7 @@ Gui::draw() mGraphics->popClipArea(); } -void -Gui::setUseCustomCursor(bool customCursor) +void Gui::setUseCustomCursor(bool customCursor) { if (customCursor != mCustomCursor) { @@ -287,3 +304,9 @@ Gui::setUseCustomCursor(bool customCursor) } } } + +void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput) +{ + gcn::Gui::handleMouseMoved(mouseInput); + mMouseInactivityTimer = 0; +} diff --git a/src/gui/gui.h b/src/gui/gui.h index 8cf91915..f56b1dbf 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -58,6 +58,12 @@ class Gui : public gcn::Gui ~Gui(); /** + * Performs logic of the GUI. Overridden to track mouse pointer + * activity. + */ + void logic(); + + /** * Draws the whole Gui by calling draw functions down in the * Gui hierarchy. It also draws the mouse pointer. */ @@ -94,11 +100,16 @@ class Gui : public gcn::Gui CURSOR_TOTAL }; + protected: + void handleMouseMoved(const gcn::MouseInput &mouseInput); + private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ + float mMouseCursorAlpha; + int mMouseInactivityTimer; int mCursorType; }; |