summaryrefslogtreecommitdiff
path: root/src/gui/gui.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-12-05 23:01:54 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-12-07 01:46:33 +0100
commit1ad1ed215a9f33d2d55efbfb43130dfc58a2a1a4 (patch)
tree2f6a12b8c785afe38085d24df28dd9e7c5920eeb /src/gui/gui.cpp
parent5554fdc59a308c46012f3afa16af60d66a00465e (diff)
downloadmana-1ad1ed215a9f33d2d55efbfb43130dfc58a2a1a4.tar.gz
mana-1ad1ed215a9f33d2d55efbfb43130dfc58a2a1a4.tar.bz2
mana-1ad1ed215a9f33d2d55efbfb43130dfc58a2a1a4.tar.xz
mana-1ad1ed215a9f33d2d55efbfb43130dfc58a2a1a4.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. (cherry picked from eAthena branch)
Diffstat (limited to 'src/gui/gui.cpp')
-rw-r--r--src/gui/gui.cpp47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 930d4939..dc6306b4 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/resourcemanager.h"
#include "../resources/imageloader.h"
@@ -74,6 +75,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...");
@@ -157,32 +160,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);
}
@@ -190,8 +208,7 @@ Gui::draw()
mGraphics->popClipArea();
}
-void
-Gui::setUseCustomCursor(bool customCursor)
+void Gui::setUseCustomCursor(bool customCursor)
{
if (customCursor != mCustomCursor)
{
@@ -224,3 +241,9 @@ Gui::setUseCustomCursor(bool customCursor)
}
}
}
+
+void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput)
+{
+ gcn::Gui::handleMouseMoved(mouseInput);
+ mMouseInactivityTimer = 0;
+}