summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-04-26 11:49:50 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-09-02 13:37:14 +0200
commited589aa6fbe1a763a9132d6d8d9e9e807b423b5e (patch)
tree929cf5fa79592c641b2958797a6642c443d8705b
parente2755e28439956cbb3c34adfaa87ae1b083e6029 (diff)
downloadmana-ed589aa6fbe1a763a9132d6d8d9e9e807b423b5e.tar.gz
mana-ed589aa6fbe1a763a9132d6d8d9e9e807b423b5e.tar.bz2
mana-ed589aa6fbe1a763a9132d6d8d9e9e807b423b5e.tar.xz
mana-ed589aa6fbe1a763a9132d6d8d9e9e807b423b5e.zip
Added a hand mouse cursor, used when hovering links
InputEvent::mIsConsumed is used to tell the Window it should not change the mouse cursor as well. This change also adds a closed hand mouse cursor, though this is unused for now (might be useful when dragging stuff around). The new cursors are by meway.
-rw-r--r--data/graphics/gui/mouse.pngbin6969 -> 11417 bytes
-rw-r--r--src/gui/gui.cpp8
-rw-r--r--src/gui/gui.h3
-rw-r--r--src/gui/widgets/browserbox.cpp6
-rw-r--r--src/gui/widgets/window.cpp21
5 files changed, 24 insertions, 14 deletions
diff --git a/data/graphics/gui/mouse.png b/data/graphics/gui/mouse.png
index 1f2a22c3..a53d5fb1 100644
--- a/data/graphics/gui/mouse.png
+++ b/data/graphics/gui/mouse.png
Binary files differ
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 92dab954..26d0913e 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -301,7 +301,7 @@ void Gui::loadCustomCursors()
0, targetCursorSize, targetCursorSize, 32,
rmask, gmask, bmask, amask);
- for (int i = 0; i <= static_cast<int>(Cursor::DOWN); ++i)
+ for (int i = 0; i <= static_cast<int>(Cursor::LAST); ++i)
{
int x = i % columns * cursorSize;
int y = i / columns * cursorSize;
@@ -330,7 +330,7 @@ void Gui::loadSystemCursors()
constexpr struct {
Cursor cursor;
SDL_SystemCursor systemCursor;
- } cursors[] = {
+ } cursors[static_cast<int>(Cursor::LAST) + 1] = {
{ Cursor::POINTER, SDL_SYSTEM_CURSOR_ARROW },
{ Cursor::RESIZE_ACROSS, SDL_SYSTEM_CURSOR_SIZEWE },
{ Cursor::RESIZE_DOWN, SDL_SYSTEM_CURSOR_SIZENS },
@@ -343,7 +343,9 @@ void Gui::loadSystemCursors()
{ Cursor::LEFT, SDL_SYSTEM_CURSOR_ARROW },
{ Cursor::UP, SDL_SYSTEM_CURSOR_ARROW },
{ Cursor::RIGHT, SDL_SYSTEM_CURSOR_ARROW },
- { Cursor::DOWN, SDL_SYSTEM_CURSOR_ARROW }
+ { Cursor::DOWN, SDL_SYSTEM_CURSOR_ARROW },
+ { Cursor::DRAG, SDL_SYSTEM_CURSOR_SIZEALL },
+ { Cursor::HAND, SDL_SYSTEM_CURSOR_HAND },
};
for (auto cursor : cursors)
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 1cba3fbc..7c3c3afd 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -61,6 +61,9 @@ enum class Cursor {
UP,
RIGHT,
DOWN,
+ DRAG,
+ HAND,
+ LAST = HAND,
};
/**
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 07ed9299..96feddb9 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -173,13 +173,17 @@ void BrowserBox::mousePressed(gcn::MouseEvent &event)
updateHoveredLink(event.getX(), event.getY());
- if (mHoveredLink)
+ if (mHoveredLink) {
mLinkHandler->handleLink(mHoveredLink->link);
+ gui->setCursorType(Cursor::POINTER);
+ }
}
void BrowserBox::mouseMoved(gcn::MouseEvent &event)
{
updateHoveredLink(event.getX(), event.getY());
+ gui->setCursorType(mHoveredLink ? Cursor::HAND : Cursor::POINTER);
+ event.consume(); // Suppress mouse cursor change by parent
}
void BrowserBox::mouseExited(gcn::MouseEvent &event)
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 70b6dae8..6231bcbf 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -383,14 +383,9 @@ void Window::close()
void Window::mouseReleased(gcn::MouseEvent &event)
{
- if (mGrip && mouseResize)
- {
- mouseResize = 0;
- gui->setCursorType(Cursor::POINTER);
- }
+ mouseResize = 0;
- // This should be the responsibility of Guichan (and is from 0.8.0 on)
- mMoved = false;
+ gcn::Window::mouseReleased(event);
}
void Window::mouseExited(gcn::MouseEvent &event)
@@ -401,6 +396,15 @@ void Window::mouseExited(gcn::MouseEvent &event)
void Window::mouseMoved(gcn::MouseEvent &event)
{
+ // Make sure BeingPopup is hidden (Viewport does not receive mouseExited)
+ if (viewport)
+ viewport->hideBeingPopup();
+
+ // Don't change mouse cursor when event was consumed by child widget
+ // (in this case child widget is responsible for mouse cursor)
+ if (event.isConsumed())
+ return;
+
int resizeHandles = getResizeHandles(event);
// Changes the custom mouse cursor based on it's current position.
@@ -425,9 +429,6 @@ void Window::mouseMoved(gcn::MouseEvent &event)
default:
gui->setCursorType(Cursor::POINTER);
}
-
- if (viewport)
- viewport->hideBeingPopup();
}
void Window::mouseDragged(gcn::MouseEvent &event)