summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-01 21:11:53 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 14:39:09 +0100
commitc7e48aaf7eb0f2df76327b963879416a0cc8d5e7 (patch)
treeb8bec0950af7dcd9a913d6aa92a7944216e6ae48
parent5efaa5125fe92a5438b3cc2949f4d720bced5a7a (diff)
downloadMana-c7e48aaf7eb0f2df76327b963879416a0cc8d5e7.tar.gz
Mana-c7e48aaf7eb0f2df76327b963879416a0cc8d5e7.tar.bz2
Mana-c7e48aaf7eb0f2df76327b963879416a0cc8d5e7.tar.xz
Mana-c7e48aaf7eb0f2df76327b963879416a0cc8d5e7.zip
Updated mouse cursors to latest version
The new cursor types are not used yet for now.
-rw-r--r--data/graphics/gui/mouse.pngbin9204 -> 6969 bytes
-rw-r--r--src/gui/gui.cpp51
-rw-r--r--src/gui/gui.h49
-rw-r--r--src/gui/viewport.cpp10
-rw-r--r--src/gui/widgets/progressindicator.cpp2
-rw-r--r--src/gui/widgets/window.cpp18
-rw-r--r--src/resources/imageset.cpp2
-rw-r--r--src/resources/imageset.h5
8 files changed, 67 insertions, 70 deletions
diff --git a/data/graphics/gui/mouse.png b/data/graphics/gui/mouse.png
index 46a86e0b..1f2a22c3 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 17f4897d..2d470a3e 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -77,12 +77,7 @@ class GuiConfigListener : public EventListener
Gui *mGui;
};
-Gui::Gui(Graphics *graphics):
- mCustomCursor(false),
- mMouseCursors(nullptr),
- mMouseCursorAlpha(1.0f),
- mMouseInactivityTimer(0),
- mCursorType(CURSOR_POINTER)
+Gui::Gui(Graphics *graphics)
{
logger->log("Initializing GUI...");
// Set graphics
@@ -208,7 +203,7 @@ void Gui::draw()
&& mCustomCursor
&& mMouseCursorAlpha > 0.0f)
{
- Image *mouseCursor = mMouseCursors->get(mCursorType);
+ Image *mouseCursor = mMouseCursors->get(static_cast<size_t>(mCursorType));
mouseCursor->setAlpha(mMouseCursorAlpha);
static_cast<Graphics*>(mGraphics)->drawImage(
@@ -233,32 +228,32 @@ void Gui::videoResized(int width, int height)
void Gui::setUseCustomCursor(bool customCursor)
{
- if (customCursor != mCustomCursor)
+ if (mCustomCursor == customCursor)
+ return;
+
+ mCustomCursor = customCursor;
+
+ if (mCustomCursor)
{
- mCustomCursor = customCursor;
+ // Hide the SDL mouse cursor
+ SDL_ShowCursor(SDL_DISABLE);
- if (mCustomCursor)
- {
- // Hide the SDL mouse cursor
- SDL_ShowCursor(SDL_DISABLE);
+ // Load the mouse cursor
+ mMouseCursors = Theme::getImageSetFromTheme("mouse.png", 40, 40);
- // Load the mouse cursor
- mMouseCursors = Theme::getImageSetFromTheme("mouse.png", 40, 40);
+ if (!mMouseCursors)
+ logger->error("Unable to load mouse cursors.");
+ }
+ else
+ {
+ // Show the SDL mouse cursor
+ SDL_ShowCursor(SDL_ENABLE);
- if (!mMouseCursors)
- logger->error("Unable to load mouse cursors.");
- }
- else
+ // Unload the mouse cursor
+ if (mMouseCursors)
{
- // Show the SDL mouse cursor
- SDL_ShowCursor(SDL_ENABLE);
-
- // Unload the mouse cursor
- if (mMouseCursors)
- {
- mMouseCursors->decRef();
- mMouseCursors = nullptr;
- }
+ mMouseCursors->decRef();
+ mMouseCursors = nullptr;
}
}
}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index eea3f23d..b731514f 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -41,6 +41,26 @@ class SDLInput;
*/
/**
+ * Cursors are in graphic order from left to right.
+ * CURSOR_POINTER should be left untouched.
+ */
+enum class Cursor {
+ POINTER = 0,
+ RESIZE_ACROSS,
+ RESIZE_DOWN,
+ RESIZE_DOWN_LEFT,
+ RESIZE_DOWN_RIGHT,
+ FIGHT,
+ PICKUP,
+ TALK,
+ ACTION,
+ LEFT,
+ UP,
+ RIGHT,
+ DOWN,
+};
+
+/**
* Main GUI class.
*
* \ingroup GUI
@@ -93,26 +113,9 @@ class Gui : public gcn::Gui
/**
* Sets which cursor should be used.
*/
- void setCursorType(int index)
+ void setCursorType(Cursor index)
{ mCursorType = index; }
- /**
- * Cursors are in graphic order from left to right.
- * CURSOR_POINTER should be left untouched.
- * CURSOR_TOTAL should always be last.
- */
- enum {
- CURSOR_POINTER = 0,
- CURSOR_RESIZE_ACROSS,
- CURSOR_RESIZE_DOWN,
- CURSOR_RESIZE_DOWN_LEFT,
- CURSOR_RESIZE_DOWN_RIGHT,
- CURSOR_FIGHT,
- CURSOR_PICKUP,
- CURSOR_TALK,
- CURSOR_TOTAL
- };
-
protected:
void handleMouseMoved(const gcn::MouseInput &mouseInput) override;
void handleTextInput(const TextInput &textInput);
@@ -121,11 +124,11 @@ class Gui : public gcn::Gui
GuiConfigListener *mConfigListener;
gcn::Font *mGuiFont; /**< The global GUI font */
gcn::Font *mInfoParticleFont; /**< Font for Info Particles*/
- bool mCustomCursor; /**< Show custom cursor */
- ImageSet *mMouseCursors; /**< Mouse cursor images */
- float mMouseCursorAlpha;
- int mMouseInactivityTimer;
- int mCursorType;
+ bool mCustomCursor = false; /**< Show custom cursor */
+ ImageSet *mMouseCursors = nullptr; /**< Mouse cursor images */
+ float mMouseCursorAlpha = 1.0f;
+ int mMouseInactivityTimer = 0;
+ Cursor mCursorType = Cursor::POINTER;
};
extern Gui *gui; /**< The GUI system */
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 0cadb9fc..9db1707c 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -589,26 +589,26 @@ void Viewport::updateCursorType()
{
// NPCs
case ActorSprite::NPC:
- gui->setCursorType(Gui::CURSOR_TALK);
+ gui->setCursorType(Cursor::TALK);
break;
// Monsters
case ActorSprite::MONSTER:
- gui->setCursorType(Gui::CURSOR_FIGHT);
+ gui->setCursorType(Cursor::FIGHT);
break;
default:
- gui->setCursorType(Gui::CURSOR_POINTER);
+ gui->setCursorType(Cursor::POINTER);
break;
}
// Item mouseover
}
else if (mHoverItem)
{
- gui->setCursorType(Gui::CURSOR_PICKUP);
+ gui->setCursorType(Cursor::PICKUP);
}
else
{
- gui->setCursorType(Gui::CURSOR_POINTER);
+ gui->setCursorType(Cursor::POINTER);
}
}
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
index 2495a62d..40523e9a 100644
--- a/src/gui/widgets/progressindicator.cpp
+++ b/src/gui/widgets/progressindicator.cpp
@@ -36,7 +36,7 @@ ProgressIndicator::ProgressIndicator()
32, 32);
auto *anim = new Animation;
- for (ImageSet::size_type i = 0; i < images->size(); ++i)
+ for (size_t i = 0; i < images->size(); ++i)
anim->addFrame(images->get(i), 100, 0, 0);
mIndicator = new SimpleAnimation(anim);
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 6d970b0b..6290ef62 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -67,7 +67,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent,
if (mModal)
{
- gui->setCursorType(Gui::CURSOR_POINTER);
+ gui->setCursorType(Cursor::POINTER);
requestModalFocus();
}
@@ -274,7 +274,7 @@ void Window::widgetHidden(const gcn::Event &event)
{
if (gui)
{
- gui->setCursorType(Gui::CURSOR_POINTER);
+ gui->setCursorType(Cursor::POINTER);
}
WidgetListIterator it;
@@ -384,7 +384,7 @@ void Window::mouseReleased(gcn::MouseEvent &event)
if (mGrip && mouseResize)
{
mouseResize = 0;
- gui->setCursorType(Gui::CURSOR_POINTER);
+ gui->setCursorType(Cursor::POINTER);
}
// This should be the responsibility of Guichan (and is from 0.8.0 on)
@@ -394,7 +394,7 @@ void Window::mouseReleased(gcn::MouseEvent &event)
void Window::mouseExited(gcn::MouseEvent &event)
{
if (mGrip && !mouseResize)
- gui->setCursorType(Gui::CURSOR_POINTER);
+ gui->setCursorType(Cursor::POINTER);
}
void Window::mouseMoved(gcn::MouseEvent &event)
@@ -405,20 +405,20 @@ void Window::mouseMoved(gcn::MouseEvent &event)
switch (resizeHandles)
{
case BOTTOM | RIGHT:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_RIGHT);
+ gui->setCursorType(Cursor::RESIZE_DOWN_RIGHT);
break;
case BOTTOM | LEFT:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN_LEFT);
+ gui->setCursorType(Cursor::RESIZE_DOWN_LEFT);
break;
case BOTTOM:
- gui->setCursorType(Gui::CURSOR_RESIZE_DOWN);
+ gui->setCursorType(Cursor::RESIZE_DOWN);
break;
case RIGHT:
case LEFT:
- gui->setCursorType(Gui::CURSOR_RESIZE_ACROSS);
+ gui->setCursorType(Cursor::RESIZE_ACROSS);
break;
default:
- gui->setCursorType(Gui::CURSOR_POINTER);
+ gui->setCursorType(Cursor::POINTER);
}
if (viewport)
diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp
index 4eec23f8..34cf1fd8 100644
--- a/src/resources/imageset.cpp
+++ b/src/resources/imageset.cpp
@@ -46,7 +46,7 @@ ImageSet::~ImageSet()
delete_all(mImages);
}
-Image *ImageSet::get(size_type i) const
+Image *ImageSet::get(size_t i) const
{
if (i >= mImages.size())
{
diff --git a/src/resources/imageset.h b/src/resources/imageset.h
index 8f377369..6c7d59ab 100644
--- a/src/resources/imageset.h
+++ b/src/resources/imageset.h
@@ -51,10 +51,9 @@ class ImageSet : public Resource
*/
int getHeight() const { return mHeight; }
- using size_type = std::vector<Image *>::size_type;
- Image *get(size_type i) const;
+ Image *get(size_t i) const;
- size_type size() const { return mImages.size(); }
+ size_t size() const { return mImages.size(); }
int getOffsetX() const
{ return mOffsetX; }