diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 51 | ||||
-rw-r--r-- | src/gui/gui.h | 49 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 10 | ||||
-rw-r--r-- | src/gui/widgets/progressindicator.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 18 |
5 files changed, 64 insertions, 66 deletions
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) |