diff options
Diffstat (limited to 'src')
187 files changed, 5994 insertions, 8824 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 054ab4823..02a7240f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -720,11 +720,13 @@ SET(SRCS notifications.h notifymanager.cpp notifymanager.h + render/graphicsdef.hpp render/graphics_calcImageRect.hpp render/graphics_drawImageRect.hpp render/nullopenglgraphics.cpp render/nullopenglgraphics.h render/openglgraphicsdef.hpp + render/openglgraphicsdefadvanced.hpp render/renderers.cpp render/renderers.h render/rendererslistsdl.h @@ -757,6 +759,7 @@ SET(SRCS render/sdl2softwaregraphics.h render/sdlgraphics.cpp render/sdlgraphics.h + render/softwaregraphicsdef.hpp sdlshared.h shopitem.cpp shopitem.h @@ -790,13 +793,12 @@ SET(SRCS walklayer.h events/actionevent.h listeners/actionlistener.h - gui/base/basiccontainer.hpp + gui/widgets/basiccontainer.h gui/cliprect.h gui/color.h listeners/deathlistener.h events/event.h listeners/focuslistener.h - gui/base/gui.hpp events/inputguievent.h input/key.h events/keyevent.h @@ -811,33 +813,14 @@ SET(SRCS utils/sdlpixel.h gui/widgets/widget.h listeners/widgetlistener.h - gui/base/widgets/button.hpp - gui/base/widgets/checkbox.hpp - gui/base/widgets/container.hpp - gui/base/widgets/label.hpp - gui/base/widgets/listbox.hpp - gui/base/widgets/radiobutton.hpp - gui/base/widgets/scrollarea.hpp - gui/base/widgets/slider.hpp - gui/base/widgets/textbox.hpp - gui/base/widgets/textfield.hpp - gui/base/basiccontainer.cpp + gui/widgets/basiccontainer2.h + gui/widgets/basiccontainer.cpp gui/cliprect.cpp gui/color.cpp - gui/base/gui.cpp input/key.cpp gui/rect.cpp gui/widgets/widget.cpp - gui/base/widgets/button.cpp - gui/base/widgets/checkbox.cpp - gui/base/widgets/container.cpp - gui/base/widgets/label.cpp - gui/base/widgets/listbox.cpp - gui/base/widgets/radiobutton.cpp - gui/base/widgets/scrollarea.cpp - gui/base/widgets/slider.cpp - gui/base/widgets/textbox.cpp - gui/base/widgets/textfield.cpp + gui/widgets/basiccontainer2.cpp ) SET(SRCS_EVOL diff --git a/src/Makefile.am b/src/Makefile.am index 2b1eb4c68..8483fa994 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,6 +62,7 @@ dyecmd_SOURCES += dyetool/dyemain.cpp \ render/sdl2graphics.h \ render/sdlgraphics.cpp \ render/sdlgraphics.h \ + render/softwaregraphicsdef.hpp \ resources/action.cpp \ resources/action.h \ resources/animation.cpp \ @@ -152,14 +153,13 @@ endif manaplus_SOURCES += events/actionevent.h \ listeners/actionlistener.h \ - gui/base/basiccontainer.hpp \ + gui/widgets/basiccontainer.h \ gui/cliprect.h \ gui/color.h \ listeners/deathlistener.h \ events/event.h \ listeners/focuslistener.h \ render/graphics.h \ - gui/base/gui.hpp \ events/inputguievent.h \ input/key.h \ events/keyevent.h \ @@ -174,33 +174,14 @@ manaplus_SOURCES += events/actionevent.h \ utils/sdlpixel.h \ gui/widgets/widget.h \ listeners/widgetlistener.h \ - gui/base/widgets/button.hpp \ - gui/base/widgets/checkbox.hpp \ - gui/base/widgets/container.hpp \ - gui/base/widgets/label.hpp \ - gui/base/widgets/listbox.hpp \ - gui/base/widgets/radiobutton.hpp \ - gui/base/widgets/scrollarea.hpp \ - gui/base/widgets/slider.hpp \ - gui/base/widgets/textbox.hpp \ - gui/base/widgets/textfield.hpp \ - gui/base/basiccontainer.cpp \ + gui/widgets/basiccontainer2.h \ + gui/widgets/basiccontainer.cpp \ gui/cliprect.cpp \ gui/color.cpp \ - gui/base/gui.cpp \ input/key.cpp \ gui/rect.cpp \ gui/widgets/widget.cpp \ - gui/base/widgets/button.cpp \ - gui/base/widgets/checkbox.cpp \ - gui/base/widgets/container.cpp \ - gui/base/widgets/label.cpp \ - gui/base/widgets/listbox.cpp \ - gui/base/widgets/radiobutton.cpp \ - gui/base/widgets/scrollarea.cpp \ - gui/base/widgets/slider.cpp \ - gui/base/widgets/textbox.cpp \ - gui/base/widgets/textfield.cpp + gui/widgets/basiccontainer2.cpp manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/avatarlistbox.h \ @@ -819,11 +800,13 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ notifications.h \ notifymanager.cpp \ notifymanager.h \ + render/graphicsdef.hpp \ render/graphics_calcImageRect.hpp \ render/graphics_drawImageRect.hpp \ render/nullopenglgraphics.cpp \ render/nullopenglgraphics.h \ render/openglgraphicsdef.hpp \ + render/openglgraphicsdefadvanced.hpp \ render/renderers.cpp \ render/renderers.h \ render/rendererslistsdl.h \ @@ -856,6 +839,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ render/sdl2softwaregraphics.h \ render/sdlgraphics.cpp \ render/sdlgraphics.h \ + render/softwaregraphicsdef.hpp \ sdlshared.h \ shopitem.cpp \ shopitem.h \ diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index b8ea34286..381244799 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -703,17 +703,17 @@ impHandler0(hideWindows) return true; } -impHandler0(helpWindowShow) +static bool showHelpPage(const std::string &page, const bool showHide) { if (helpWindow) { - if (helpWindow->isWindowVisible()) + if (showHide && helpWindow->isWindowVisible()) { helpWindow->setVisible(false); } else { - helpWindow->loadHelp("index"); + helpWindow->loadHelp(page); helpWindow->requestMoveToTop(); } return true; @@ -721,6 +721,16 @@ impHandler0(helpWindowShow) return false; } +impHandler0(helpWindowShow) +{ + return showHelpPage("index", true); +} + +impHandler0(aboutWindowShow) +{ + return showHelpPage("about", false); +} + static void showHideWindow(Window *const window) { if (window) diff --git a/src/actionmanager.h b/src/actionmanager.h index ca8c3e2b9..7a0ad6e17 100644 --- a/src/actionmanager.h +++ b/src/actionmanager.h @@ -102,6 +102,7 @@ namespace ActionManager decHandler(hideWindows); decHandler(helpWindowShow); + decHandler(aboutWindowShow); decHandler(setupWindowShow); decHandler(statusWindowShow); decHandler(inventoryWindowShow); diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 3d9d06bef..889f2b906 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -2430,9 +2430,9 @@ void LocalPlayer::crazyMoveA() else if (emo >= 'A' && emo <= 'Z') emoteId = static_cast<unsigned char>(emo - 'A' + 37); } - if (mMoveProgram[mCrazyMoveState] == 'e') + if (mMoveProgram[mCrazyMoveState - 1] == 'e') emote(emoteId); - else + else if (client->limitPackets(PACKET_CHAT)) Net::getPetHandler()->emote(emoteId, 0); mCrazyMoveState ++; diff --git a/src/client.cpp b/src/client.cpp index 5d635f522..d8cd1f6f2 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -76,6 +76,7 @@ #include "gui/widgets/desktop.h" #include "net/chathandler.h" +#include "net/download.h" #include "net/gamehandler.h" #include "net/generalhandler.h" #include "net/guildhandler.h" @@ -185,7 +186,8 @@ bool isSafeMode = false; int serverVersion = 0; unsigned int tmwServerVersion = 0; int start_time; - +unsigned int mLastHost = 0; +unsigned long mSearchHash = 0; int textures_count = 0; #ifdef WIN32 @@ -234,6 +236,7 @@ Client::Client(const Options &options) : mSetupButton(nullptr), mVideoButton(nullptr), mHelpButton(nullptr), + mAboutButton(nullptr), mThemesButton(nullptr), mPerfomanceButton(nullptr), #ifdef ANDROID @@ -243,13 +246,13 @@ Client::Client(const Options &options) : mOldState(STATE_START), mIcon(nullptr), mCaption(), + mOldUpdates(), mFpsManager(), mSkin(nullptr), + mGuiAlpha(1.0F), mButtonPadding(1), mButtonSpacing(3), mKeyboardHeight(0), - mOldUpdates(), - mGuiAlpha(1.0F), mLimitFps(false), mConfigAutoSaved(false), mIsMinimized(false), @@ -1123,7 +1126,7 @@ int Client::gameExec() if (!gui) break; - gcn::Container *const top = static_cast<gcn::Container*>( + BasicContainer2 *const top = static_cast<BasicContainer2*>( gui->getTop()); if (!top) @@ -1136,7 +1139,6 @@ int Client::gameExec() ADDBUTTON(mSetupButton, new Button(mDesktop, // TRANSLATORS: setup tab quick button _("Setup"), "Setup", this)) -#ifndef WIN32 ADDBUTTON(mPerfomanceButton, new Button(mDesktop, // TRANSLATORS: perfoamance tab quick button _("Performance"), "Perfomance", this)) @@ -1146,6 +1148,9 @@ int Client::gameExec() ADDBUTTON(mThemesButton, new Button(mDesktop, // TRANSLATORS: theme tab quick button _("Theme"), "Themes", this)) + ADDBUTTON(mAboutButton, new Button(mDesktop, + // TRANSLATORS: theme tab quick button + _("About"), "about", this)) ADDBUTTON(mHelpButton, new Button(mDesktop, // TRANSLATORS: theme tab quick button _("Help"), "help", this)) @@ -1154,7 +1159,6 @@ int Client::gameExec() // TRANSLATORS: close quick button _("Close"), "close", this)) #endif -#endif mDesktop->setSize(mainGraphics->getWidth(), mainGraphics->getHeight()); } @@ -1299,6 +1303,9 @@ int Client::gameExec() loginData.updateType = serverConfig.getValue("updateType", 1); + mSearchHash = Net::Download::adlerBuffer( + const_cast<char*>(mCurrentServer.hostname.c_str()), + mCurrentServer.hostname.size()); if (mOptions.username.empty() || mOptions.password.empty()) { @@ -1323,7 +1330,7 @@ int Client::gameExec() // TRANSLATORS: connection dialog header _("Logging in"), STATE_SWITCH_SERVER); mCurrentDialog->postInit(); - accountLogin(&loginData); + Net::getLoginHandler()->loginOrRegister(&loginData); BLOCK_END("Client::gameExec STATE_LOGIN_ATTEMPT") break; @@ -1579,6 +1586,8 @@ int Client::gameExec() mVideoButton = nullptr; delete mThemesButton; mThemesButton = nullptr; + delete mAboutButton; + mAboutButton = nullptr; delete mHelpButton; mHelpButton = nullptr; delete mPerfomanceButton; @@ -1869,6 +1878,11 @@ void Client::action(const ActionEvent &event) inputManager.executeAction(Input::KEY_WINDOW_HELP); return; } + else if (eventId == "about") + { + inputManager.executeAction(Input::KEY_WINDOW_ABOUT); + return; + } else if (eventId == "Video") { tab = "Video"; @@ -2340,30 +2354,6 @@ void Client::initScreenshotDir() logger->log("screenshotDirectory: " + mScreenshotDir); } -void Client::accountLogin(LoginData *const data) -{ - if (!data) - return; - - logger->log("Username is %s", data->username.c_str()); - - // Send login infos - if (data->registerLogin) - Net::getLoginHandler()->registerAccount(data); - else - Net::getLoginHandler()->loginAccount(data); - - // Clear the password, avoids auto login when returning to login - data->password.clear(); - - const bool remember = data->remember; - if (remember) - serverConfig.setValue("username", data->username); - else - serverConfig.setValue("username", ""); - serverConfig.setValue("remember", remember); -} - #ifndef ANDROID void Client::storeSafeParameters() const { @@ -2984,7 +2974,10 @@ void Client::checkConfigVersion() if (version < 6) config.setValue("blur", false); - config.setValue("cfgver", 6); + if (version < 7) + config.setValue("download-music", true); + + config.setValue("cfgver", 7); } Window *Client::openErrorDialog(const std::string &header, diff --git a/src/client.h b/src/client.h index 0e6528ca3..0d7749e3f 100644 --- a/src/client.h +++ b/src/client.h @@ -372,8 +372,6 @@ private: static void initFeatures(); - static void accountLogin(LoginData *const data); - #ifndef ANDROID void storeSafeParameters() const; #endif @@ -427,6 +425,7 @@ private: Button *mSetupButton; Button *mVideoButton; Button *mHelpButton; + Button *mAboutButton; Button *mThemesButton; Button *mPerfomanceButton; #ifdef ANDROID @@ -439,13 +438,13 @@ private: SDL_Surface *mIcon; std::string mCaption; + std::string mOldUpdates; FPSmanager mFpsManager; Skin *mSkin; + float mGuiAlpha; int mButtonPadding; int mButtonSpacing; int mKeyboardHeight; - std::string mOldUpdates; - float mGuiAlpha; bool mLimitFps; bool mConfigAutoSaved; bool mIsMinimized; @@ -455,5 +454,7 @@ private: }; extern Client *client; +extern unsigned int mLastHost; +extern unsigned long mSearchHash; #endif // CLIENT_H diff --git a/src/configuration.cpp b/src/configuration.cpp index ed2adfc61..54420a9f3 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -49,6 +49,7 @@ const std::string unusedKeys[] = { "AttackRange", "emoteshortcut0", + "screenshotDirectory2", "AttackRangeBorder", "AttackRangeBorderDelay", "AttackRangeBorderGradient", @@ -205,7 +206,6 @@ const std::string unusedKeys[] = "playerHomes", "remember", "screenshotDirectory", - "screenshotDirectory2", "" }; @@ -223,6 +223,7 @@ void ConfigurationObject::deleteKey(const std::string &key) void Configuration::setValue(const std::string &key, const std::string &value) { ConfigurationObject::setValue(key, value); + mUpdated = true; // Notify listeners const ListenerMapIterator list = mListenerMap.find(key); @@ -347,7 +348,8 @@ Configuration::Configuration() : mDefaultsData(nullptr), mDirectory(), mFilename(), - mUseResManager(false) + mUseResManager(false), + mUpdated(false) { #ifdef DEBUG_CONFIG mLogKeys = false; @@ -803,11 +805,18 @@ void ConfigurationObject::writeToXML(const XmlTextWriterPtr writer) } } +void Configuration::writeUpdated() +{ + if (mUpdated) + write(); +} + void Configuration::write() { if (mConfigPath.empty()) return; + mUpdated = false; // Do not attempt to write to file that cannot be opened for writing FILE *const testFile = fopen(mConfigPath.c_str(), "w"); if (!testFile) @@ -885,7 +894,8 @@ void Configuration::removeListeners(ConfigListener *const listener) void Configuration::removeOldKeys() { if (mOptions.find(unusedKeys[0]) != mOptions.end() - || mOptions.find(unusedKeys[1]) != mOptions.end()) + || mOptions.find(unusedKeys[1]) != mOptions.end() + || mOptions.find(unusedKeys[2]) != mOptions.end()) { int f = 0; while (unusedKeys[f] != "") diff --git a/src/configuration.h b/src/configuration.h index daa10f51b..b1875247b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -225,6 +225,8 @@ class ConfigurationObject #endif }; +#define valTest(num) mStatsRe##num + /** * Configuration handler for reading (and writing). * @@ -346,6 +348,8 @@ class Configuration final : public ConfigurationObject std::string getFileName() const A_WARN_UNUSED { return mFilename; } + void writeUpdated(); + private: /** * Clean up the default values member. @@ -365,6 +369,7 @@ class Configuration final : public ConfigurationObject std::string mDirectory; std::string mFilename; bool mUseResManager; + bool mUpdated; }; extern Configuration branding; diff --git a/src/defaults.cpp b/src/defaults.cpp index 7a110a539..d5f907696 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -124,6 +124,7 @@ DefaultsData* getConfigDefaults() AddDEF("showChatColorsList", false); AddDEF("customcursor", false); AddDEF("showDidYouKnow", false); + AddDEF("longmouseclick", true); #else AddDEF("screenwidth", defaultScreenWidth); AddDEF("screenheight", defaultScreenHeight); @@ -141,6 +142,7 @@ DefaultsData* getConfigDefaults() AddDEF("customcursor", true); #endif AddDEF("showDidYouKnow", true); + AddDEF("longmouseclick", false); #endif AddDEF("showEmotesButton", true); AddDEF("screen", false); @@ -163,7 +165,7 @@ DefaultsData* getConfigDefaults() AddDEF("leftTolerance", 100); AddDEF("rightTolerance", 100); AddDEF("logNpcInGui", true); - AddDEF("download-music", false); + AddDEF("download-music", true); AddDEF("guialpha", 0.8F); AddDEF("ChatLogLength", 0); AddDEF("enableChatLog", true); @@ -320,15 +322,15 @@ DefaultsData* getConfigDefaults() AddDEF("serverslistupdate", ""); AddDEF("fadeoutmusic", true); AddDEF("screenActionKeyboard", Input::KEY_SHOW_KEYBOARD); - AddDEF("screenActionButton0", Input::KEY_STOP_SIT); + AddDEF("screenActionButton0", Input::KEY_TALK); AddDEF("screenActionButton1", Input::KEY_TARGET_ATTACK); AddDEF("screenActionButton2", Input::KEY_PICKUP); - AddDEF("screenActionButton3", Input::KEY_PATHFIND); - AddDEF("screenActionButton4", Input::KEY_STOP_ATTACK); - AddDEF("screenActionButton5", Input::KEY_TALK); - AddDEF("screenActionButton6", Input::KEY_TARGET_NPC); - AddDEF("screenActionButton7", Input::KEY_TARGET_MONSTER); - AddDEF("screenActionButton8", Input::KEY_WINDOW_CHAT); + AddDEF("screenActionButton3", Input::KEY_STOP_SIT); + AddDEF("screenActionButton4", Input::KEY_TARGET_NPC); + AddDEF("screenActionButton5", Input::KEY_WINDOW_STATUS); + AddDEF("screenActionButton6", Input::KEY_WINDOW_INVENTORY); + AddDEF("screenActionButton7", Input::KEY_WINDOW_SKILL); + AddDEF("screenActionButton8", Input::KEY_WINDOW_SOCIAL); AddDEF("screenActionButton9", Input::KEY_WINDOW_DEBUG); AddDEF("screenActionButton10", Input::KEY_TRADE); AddDEF("screenActionButton11", Input::KEY_DIRECT_DOWN); @@ -346,7 +348,7 @@ DefaultsData* getConfigDefaults() AddDEF("uselonglivesprites", false); AddDEF("uselonglivesounds", true); AddDEF("screenDensity", 0); - AddDEF("cfgver", 6); + AddDEF("cfgver", 7); AddDEF("enableDebugLog", false); AddDEF("doubleClick", true); AddDEF("useDiagonalSpeed", true); @@ -358,6 +360,7 @@ DefaultsData* getConfigDefaults() AddDEF("playMapAnimations", true); AddDEF("usepets", true); AddDEF("scale", 1); + AddDEF("addwatermark", true); return configData; } diff --git a/src/dragdrop.h b/src/dragdrop.h index 99cfb1ee7..3623d548c 100644 --- a/src/dragdrop.h +++ b/src/dragdrop.h @@ -54,14 +54,14 @@ class DragDrop final { public: DragDrop(Item *const item, const DragDropSource source) : - mItem(item ? item->getId() : 0), - mItemColor(item ? item->getColor() : 1), mItemImage(item ? item->getImage() : nullptr), - mSelItem(0), - mSelItemColor(1), - mSource(source), mText(), - mTag(-1) + mSource(source), + mItem(item ? item->getId() : 0), + mSelItem(0), + mTag(-1), + mItemColor(item ? item->getColor() : 1), + mSelItemColor(1) { if (mItemImage) mItemImage->incRef(); @@ -250,14 +250,14 @@ class DragDrop final } private: - int mItem; - uint8_t mItemColor; Image *mItemImage; - int mSelItem; - uint8_t mSelItemColor; - DragDropSource mSource; std::string mText; + DragDropSource mSource; + int mItem; + int mSelItem; int mTag; + uint8_t mItemColor; + uint8_t mSelItemColor; }; extern DragDrop dragDrop; diff --git a/src/events/inputguievent.h b/src/events/inputguievent.h index 2e5136ea2..e42bec27f 100644 --- a/src/events/inputguievent.h +++ b/src/events/inputguievent.h @@ -79,61 +79,14 @@ class InputGuiEvent: public Event * Constructor. * * @param source The source widget of the event. - * @param isShiftPressed True if shift is pressed, false otherwise. - * @param isControlPressed True if control is pressed, false otherwise. - * @param isAltPressed True if alt is pressed, false otherwise. * @param isMetaPressed True if meta is pressed, false otherwise. */ - InputGuiEvent(Widget *const source, - const bool shiftPressed, - const bool controlPressed, - const bool altPressed, - const bool metaPressed) : + explicit InputGuiEvent(Widget *const source) : Event(source), - mShiftPressed(shiftPressed), - mControlPressed(controlPressed), - mAltPressed(altPressed), - mMetaPressed(metaPressed), mIsConsumed(false) { } /** - * Checks if shift is pressed. - * - * @return True if shift was pressed at the same time as the key, - * false otherwise. - */ - bool isShiftPressed() const A_WARN_UNUSED - { return mShiftPressed; } - - /** - * Checks if control is pressed. - * - * @return True if control was pressed at the same time as the key, - * false otherwise. - */ - bool isControlPressed() const A_WARN_UNUSED - { return mControlPressed; } - - /** - * Checks if alt is pressed. - * - * @return True if alt was pressed at the same time as the key, - * false otherwise. - */ - bool isAltPressed() const A_WARN_UNUSED - { return mAltPressed; } - - /** - * Checks whether meta is pressed. - * - * @return True if meta was pressed at the same time as the key, - * false otherwise. - */ - bool isMetaPressed() const A_WARN_UNUSED - { return mMetaPressed; } - - /** * Marks the event as consumed. Input event listeners may discard * consumed input or act on consumed input. An example of a widget * that discards consumed input is the ScrollArea widget that @@ -158,26 +111,6 @@ class InputGuiEvent: public Event protected: /** - * True if shift is pressed, false otherwise. - */ - bool mShiftPressed; - - /** - * True if control is pressed, false otherwise. - */ - bool mControlPressed; - - /** - * True if alt is pressed, false otherwise. - */ - bool mAltPressed; - - /** - * True if meta is pressed, false otherwise. - */ - bool mMetaPressed; - - /** * True if the input event is consumed, * false otherwise. */ diff --git a/src/events/keyevent.h b/src/events/keyevent.h index 360d229d7..16bc707c1 100644 --- a/src/events/keyevent.h +++ b/src/events/keyevent.h @@ -90,36 +90,21 @@ class KeyEvent: public InputGuiEvent * Constructor. * * @param source The source widget of the event. - * @param shiftPressed True if shift is pressed, false otherwise. - * @param controlPressed True if control is pressed, false otherwise. - * @param altPressed True if alt is pressed, false otherwise. - * @param metaPressed True if meta is pressed, false otherwise. * @param type The type of the event. A value from KeyEventType. - * @param numericPad True if the event occured on the numeric pad, * false otherwise. * @param key The key of the event. */ KeyEvent(Widget *const source, - const bool shiftPressed, - const bool controlPressed, - const bool altPressed, - const bool metaPressed, const unsigned int type, - const bool numericPad, const int actionId, const Key &key) : - InputGuiEvent(source, - shiftPressed, - controlPressed, - altPressed, - metaPressed), + InputGuiEvent(source), mKey(key), #ifdef USE_SDL2 mText(), #endif mType(type), - mActionId(actionId), - mIsNumericPad(numericPad) + mActionId(actionId) { } /** @@ -137,16 +122,6 @@ class KeyEvent: public InputGuiEvent { return mType; } /** - * Checks if the key event occured on the numeric pad. - * - * @return True if key event occured on the numeric pad, - * false otherwise. - * - */ - bool isNumericPad() const A_WARN_UNUSED - { return mIsNumericPad; } - - /** * Gets the key of the event. * * @return The key of the event. @@ -181,11 +156,6 @@ class KeyEvent: public InputGuiEvent unsigned int mType; int mActionId; - - /** - * True if the numeric pad was used, false otherwise. - */ - bool mIsNumericPad; }; #endif // EVENTS_KEYEVENT_H diff --git a/src/events/mouseevent.h b/src/events/mouseevent.h index a717980f9..06b51e82a 100644 --- a/src/events/mouseevent.h +++ b/src/events/mouseevent.h @@ -86,10 +86,6 @@ class MouseEvent: public InputGuiEvent * Constructor. * * @param source The source widget of the mouse event. - * @param shiftPressed True if shift is pressed, false otherwise. - * @param controlPressed True if control is pressed, false otherwise. - * @param altPressed True if alt is pressed, false otherwise. - * @param metaPressed True if meta is pressed, false otherwise. * @param type The type of the mouse event. * @param button The button of the mouse event. * @param x The x coordinate of the event relative to the source widget. @@ -98,20 +94,12 @@ class MouseEvent: public InputGuiEvent * It's set to zero if another button is used. */ MouseEvent(Widget *const source, - const bool shiftPressed, - const bool controlPressed, - const bool altPressed, - const bool metaPressed, const unsigned int type, const unsigned int button, const int x, const int y, const int clickCount) : - InputGuiEvent(source, - shiftPressed, - controlPressed, - altPressed, - metaPressed), + InputGuiEvent(source), mType(type), mButton(button), mX(x), @@ -235,7 +223,7 @@ class MouseEvent: public InputGuiEvent * to widget the mouse listener receiving the events have registered * to. */ - friend class gcn::Gui; + friend class Gui; }; #endif // EVENTS_MOUSEEVENT_H diff --git a/src/game.cpp b/src/game.cpp index 253c4bff2..e30b7222e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -48,6 +48,7 @@ #include "input/joystick.h" #include "input/keyboardconfig.h" +#include "gui/font.h" #include "gui/gui.h" #include "gui/viewport.h" #include "gui/windowmenu.h" @@ -165,6 +166,7 @@ BattleTab *battleChatTab = nullptr; GmTab *gmChatTab = nullptr; LangTab *langChatTab = nullptr; +bool mStatsReUpdated = false; const unsigned adjustDelay = 10; /** @@ -390,7 +392,8 @@ Game::Game(): mAdjustPerfomance(config.getBoolValue("adjustPerfomance")), mLowerCounter(0), mPing(0), - mTime(cur_time + 1) + mTime(cur_time + 1), + mTime2(cur_time + 10) { touchManager.setInGame(true); spellManager = new SpellManager; @@ -410,7 +413,7 @@ Game::Game(): viewport->setSize(mainGraphics->mWidth, mainGraphics->mHeight); PlayerInfo::clear(); - gcn::Container *const top = static_cast<gcn::Container*>(gui->getTop()); + BasicContainer2 *const top = static_cast<BasicContainer2*>(gui->getTop()); if (top) top->add(viewport); viewport->requestMoveToBottom(); @@ -477,6 +480,15 @@ Game::~Game() PlayerInfo::gameDestroyed(); } +void Game::addWatermark() +{ + if (!boldFont || !config.getBoolValue("addwatermark")) + return; + mainGraphics->setColorAll(Theme::getThemeColor(Theme::TEXT), + Theme::getThemeColor(Theme::TEXT_OUTLINE)); + boldFont->drawString(mainGraphics, client->getServerName(), 100, 50); +} + bool Game::createScreenshot() { if (!mainGraphics) @@ -489,11 +501,13 @@ bool Game::createScreenshot() mainGraphics->setSecure(true); mainGraphics->prepareScreenshot(); gui->draw(); + addWatermark(); screenshot = mainGraphics->getScreenshot(); mainGraphics->setSecure(false); } else { + addWatermark(); screenshot = mainGraphics->getScreenshot(); } @@ -606,6 +620,9 @@ void Game::slowLogic() const int time = cur_time; if (mTime != time) { + if (valTest(Updated)) + mValidSpeed = false; + mTime = time + 1; if (botCheckerWindow) botCheckerWindow->slowLogic(); @@ -620,6 +637,13 @@ void Game::slowLogic() Being::reReadConfig(); if (killStats) killStats->recalcStats(); + + if (time > mTime2 || mTime2 - time > 10) + { + mTime2 = time + 10; + config.writeUpdated(); + serverConfig.writeUpdated(); + } } if (shopWindow) diff --git a/src/game.h b/src/game.h index 023796290..8f488c6ed 100644 --- a/src/game.h +++ b/src/game.h @@ -116,6 +116,8 @@ class Game final static bool createScreenshot(); + static void addWatermark(); + static bool saveScreenshot(SDL_Surface *const screenshot); void updateHistory(const SDL_Event &event); @@ -135,8 +137,11 @@ class Game final int mLowerCounter; int mPing; int mTime; + int mTime2; static Game *mInstance; }; +extern bool mStatsReUpdated; + #endif // GAME_H diff --git a/src/gui/base/basiccontainer.cpp b/src/gui/base/basiccontainer.cpp deleted file mode 100644 index f323366ad..000000000 --- a/src/gui/base/basiccontainer.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/basiccontainer.hpp" - -#include <algorithm> - -#include "debug.h" - -namespace gcn -{ - BasicContainer::~BasicContainer() - { - clear(); - } - - void BasicContainer::moveToTop(Widget* widget) - { - for (WidgetListIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - if (*iter == widget) - { - mWidgets.erase(iter); - mWidgets.push_back(widget); - return; - } - } - } - - void BasicContainer::moveToBottom(Widget* widget) - { - WidgetListIterator iter; - iter = std::find(mWidgets.begin(), mWidgets.end(), widget); - - if (iter == mWidgets.end()) - return; - - mWidgets.erase(iter); - mWidgets.insert(mWidgets.begin(), widget); - } - - void BasicContainer::death(const Event& event) - { - WidgetListIterator iter; - iter = std::find(mWidgets.begin(), mWidgets.end(), event.getSource()); - - if (iter == mWidgets.end()) - return; - - mWidgets.erase(iter); - } - - Rect BasicContainer::getChildrenArea() - { - return Rect(0, 0, getWidth(), getHeight()); - } - - void BasicContainer::focusNext() - { - WidgetListConstIterator it; - - for (it = mWidgets.begin(); it != mWidgets.end(); ++ it) - { - if ((*it)->isFocused()) - break; - } - - WidgetListConstIterator end = it; - - if (it == mWidgets.end()) - it = mWidgets.begin(); - - ++ it; - - for ( ; it != end; ++ it) - { - if (it == mWidgets.end()) - it = mWidgets.begin(); - - if ((*it)->isFocusable()) - { - (*it)->requestFocus(); - return; - } - } - } - - void BasicContainer::focusPrevious() - { - WidgetListReverseIterator it; - - for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it) - { - if ((*it)->isFocused()) - break; - } - - const WidgetListReverseIterator end = it; - - ++ it; - - if (it == mWidgets.rend()) - it = mWidgets.rbegin(); - - for ( ; it != end; ++ it) - { - if (it == mWidgets.rend()) - it = mWidgets.rbegin(); - - if ((*it)->isFocusable()) - { - (*it)->requestFocus(); - return; - } - } - } - - Widget *BasicContainer::getWidgetAt(int x, int y) - { - const Rect r = getChildrenArea(); - - if (!r.isPointInRect(x, y)) - return nullptr; - - x -= r.x; - y -= r.y; - - for (WidgetListReverseIterator it = mWidgets.rbegin(); - it != mWidgets.rend(); ++ it) - { - if ((*it)->isVisible() && (*it)->getDimension() - .isPointInRect(x, y)) - { - return (*it); - } - } - - return nullptr; - } - - void BasicContainer::logic() - { - BLOCK_START("BasicContainer::logic") - logicChildren(); - BLOCK_END("BasicContainer::logic") - } - - void BasicContainer::_setFocusHandler(FocusHandler* focusHandler) - { - Widget::_setFocusHandler(focusHandler); - - if (mInternalFocusHandler) - return; - - for (WidgetListConstIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - (*iter)->_setFocusHandler(focusHandler); - } - } - - void BasicContainer::add(Widget* widget) - { - mWidgets.push_back(widget); - - if (!mInternalFocusHandler) - widget->_setFocusHandler(_getFocusHandler()); - else - widget->_setFocusHandler(mInternalFocusHandler); - - widget->_setParent(this); - widget->addDeathListener(this); - } - - void BasicContainer::remove(Widget* widget) - { - for (WidgetListIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - if (*iter == widget) - { - mWidgets.erase(iter); - widget->_setFocusHandler(nullptr); - widget->_setParent(nullptr); - widget->removeDeathListener(this); - return; - } - } - } - - void BasicContainer::clear() - { - for (WidgetListConstIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - (*iter)->_setFocusHandler(nullptr); - (*iter)->_setParent(nullptr); - (*iter)->removeDeathListener(this); - } - - mWidgets.clear(); - } - - void BasicContainer::drawChildren(Graphics* graphics) - { - BLOCK_START("BasicContainer::drawChildren") - - graphics->pushClipArea(getChildrenArea()); - - for (WidgetListConstIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - Widget *const widget = *iter; - if (widget->isVisible()) - { - // If the widget has a frame, - // draw it before drawing the widget - if (widget->getFrameSize() > 0) - { - Rect rec = widget->getDimension(); - const int frame = widget->getFrameSize(); - const int frame2 = frame * 2; - rec.x -= frame; - rec.y -= frame; - rec.width += frame2; - rec.height += frame2; - graphics->pushClipArea(rec); - BLOCK_START("BasicContainer::drawChildren 1") - widget->drawFrame(graphics); - BLOCK_END("BasicContainer::drawChildren 1") - graphics->popClipArea(); - } - - graphics->pushClipArea(widget->getDimension()); - BLOCK_START("BasicContainer::drawChildren 2") - widget->draw(graphics); - BLOCK_END("BasicContainer::drawChildren 2") - graphics->popClipArea(); - } - } - - graphics->popClipArea(); - BLOCK_END("BasicContainer::drawChildren") - } - - void BasicContainer::logicChildren() - { - BLOCK_START("BasicContainer::logicChildren") - for (WidgetListConstIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - (*iter)->logic(); - } - BLOCK_END("BasicContainer::logicChildren") - } - - void BasicContainer::showWidgetPart(Widget* widget, Rect area) - { - const Rect widgetArea = getChildrenArea(); - - area.x += widget->getX(); - area.y += widget->getY(); - - if (area.x + area.width > widgetArea.width) - { - widget->setX(widget->getX() - area.x - - area.width + widgetArea.width); - } - - if (area.y + area.height > widgetArea.height) - { - widget->setY(widget->getY() - area.y - - area.height + widgetArea.height); - } - - if (area.x < 0) - widget->setX(widget->getX() - area.x); - - if (area.y < 0) - widget->setY(widget->getY() - area.y); - } - - void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler) - { - Widget::setInternalFocusHandler(focusHandler); - - for (WidgetListConstIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - if (!mInternalFocusHandler) - (*iter)->_setFocusHandler(_getFocusHandler()); - else - (*iter)->_setFocusHandler(mInternalFocusHandler); - } - } - - Widget* BasicContainer::findWidgetById(const std::string& id) - { - for (WidgetListConstIterator iter = mWidgets.begin(); - iter != mWidgets.end(); ++ iter) - { - if ((*iter)->getId() == id) - return (*iter); - - BasicContainer *const basicContainer - = dynamic_cast<BasicContainer *const>(*iter); - - if (basicContainer) - { - Widget *const widget = basicContainer->findWidgetById(id); - - if (widget) - return widget; - } - } - - return nullptr; - } -} // namespace gcn diff --git a/src/gui/base/gui.cpp b/src/gui/base/gui.cpp deleted file mode 100644 index 8985ec062..000000000 --- a/src/gui/base/gui.cpp +++ /dev/null @@ -1,763 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/gui.hpp" - -#include "gui/widgets/widget.h" - -#include "gui/focushandler.h" - -#include "input/mouseinput.h" - -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -#include "debug.h" - -namespace gcn -{ - Gui::Gui() : - mTop(nullptr), - mGraphics(nullptr), - mInput(nullptr), - mFocusHandler(new FocusHandler), - mTabbing(true), - mKeyListeners(), - mShiftPressed(false), - mMetaPressed(false), - mControlPressed(false), - mAltPressed(false), - mLastMousePressButton(0), - mLastMousePressTimeStamp(0), - mLastMouseX(0), - mLastMouseY(0), - mClickCount(1), - mLastMouseDragButton(0), - mWidgetWithMouseQueue() - { - } - - Gui::~Gui() - { - if (Widget::widgetExists(mTop)) - setTop(nullptr); - - delete mFocusHandler; - mFocusHandler = nullptr; - } - - void Gui::setTop(Widget* top) - { - if (mTop) - mTop->_setFocusHandler(nullptr); - if (top) - top->_setFocusHandler(mFocusHandler); - - mTop = top; - } - - Widget* Gui::getTop() const - { - return mTop; - } - - void Gui::setGraphics(Graphics* graphics) - { - mGraphics = graphics; - } - - Graphics* Gui::getGraphics() const - { - return mGraphics; - } - - void Gui::setInput(SDLInput* input) - { - mInput = input; - } - - SDLInput* Gui::getInput() const - { - return mInput; - } - - void Gui::logic() - { - } - - void Gui::draw() - { - } - - void Gui::focusNone() - { - mFocusHandler->focusNone(); - } - - void Gui::setTabbingEnabled(bool tabbing) - { - mTabbing = tabbing; - } - - bool Gui::isTabbingEnabled() - { - return mTabbing; - } - - void Gui::addGlobalKeyListener(KeyListener* keyListener) - { - mKeyListeners.push_back(keyListener); - } - - void Gui::removeGlobalKeyListener(KeyListener* keyListener) - { - mKeyListeners.remove(keyListener); - } - - void Gui::handleMouseInput() - { - } - - void Gui::handleKeyInput() - { - } - - void Gui::handleMouseMoved(const MouseInput& mouseInput) - { - // Check if the mouse leaves the application window. - if (!mWidgetWithMouseQueue.empty() && (mouseInput.getX() < 0 - || mouseInput.getY() < 0 || !mTop->getDimension().isPointInRect( - mouseInput.getX(), mouseInput.getY()))) - { - // Distribute an event to all widgets in the - // "widget with mouse" queue. - while (!mWidgetWithMouseQueue.empty()) - { - Widget *const widget = mWidgetWithMouseQueue.front(); - - if (Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY(), - true, - true); - } - - mWidgetWithMouseQueue.pop_front(); - } - - return; - } - - // Check if there is a need to send mouse exited events by - // traversing the "widget with mouse" queue. - bool widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty(); - while (!widgetWithMouseQueueCheckDone) - { - unsigned int iterations = 0; - for (std::deque<Widget*>::iterator - iter = mWidgetWithMouseQueue.begin(); - iter != mWidgetWithMouseQueue.end(); - ++ iter) - { - Widget *const widget = *iter; - - // If a widget in the "widget with mouse queue" doesn't - // exists anymore it should be removed from the queue. - if (!Widget::widgetExists(widget)) - { - mWidgetWithMouseQueue.erase(iter); - break; - } - else - { - int x, y; - widget->getAbsolutePosition(x, y); - - if (x > mouseInput.getX() - || y > mouseInput.getY() - || x + widget->getWidth() <= mouseInput.getX() - || y + widget->getHeight() <= mouseInput.getY() - || !widget->isVisible()) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY(), - true, - true); - mClickCount = 1; - mLastMousePressTimeStamp = 0; - mWidgetWithMouseQueue.erase(iter); - break; - } - } - - iterations++; - } - - widgetWithMouseQueueCheckDone = - (iterations == mWidgetWithMouseQueue.size()); - } - - // Check all widgets below the mouse to see if they are - // present in the "widget with mouse" queue. If a widget - // is not then it should be added and an entered event should - // be sent to it. - Widget* parent = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - Widget* widget = parent; - - // If a widget has modal mouse input focus then it will - // always be returned from getMouseEventSource, but we only wan't to - // send mouse entered events if the mouse has actually entered the - // widget with modal mouse input focus, hence we need to check if - // that's the case. If it's not we should simply ignore to send any - // mouse entered events. - if (mFocusHandler->getModalMouseInputFocused() - && widget == mFocusHandler->getModalMouseInputFocused() - && Widget::widgetExists(widget)) - { - int x, y; - widget->getAbsolutePosition(x, y); - - if (x > mouseInput.getX() || y > mouseInput.getY() - || x + widget->getWidth() <= mouseInput.getX() - || y + widget->getHeight() <= mouseInput.getY()) - { - parent = nullptr; - } - } - - while (parent) - { - parent = widget->getParent(); - - // Check if the widget is present in the "widget with mouse" queue. - bool widgetIsPresentInQueue = false; - FOR_EACH (std::deque<Widget*>::const_iterator, - iter, mWidgetWithMouseQueue) - { - if (*iter == widget) - { - widgetIsPresentInQueue = true; - break; - } - } - - // Widget is not present, send an entered event and add - // it to the "widget with mouse" queue. - if (!widgetIsPresentInQueue - && Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::ENTERED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY(), - true, - true); - mWidgetWithMouseQueue.push_front(widget); - } - - const Widget *const swap = widget; - widget = parent; - parent = swap->getParent(); - } - - if (mFocusHandler->getDraggedWidget()) - { - distributeMouseEvent(mFocusHandler->getDraggedWidget(), - MouseEvent::DRAGGED, - mLastMouseDragButton, - mouseInput.getX(), - mouseInput.getY()); - } - else - { - Widget *const sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - distributeMouseEvent(sourceWidget, - MouseEvent::MOVED, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - } - } - - void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget()) - sourceWidget = mFocusHandler->getDraggedWidget(); - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::WHEEL_MOVED_DOWN, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - } - - void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput) - { - Widget* sourceWidget = getMouseEventSource( - mouseInput.getX(), mouseInput.getY()); - - if (mFocusHandler->getDraggedWidget()) - sourceWidget = mFocusHandler->getDraggedWidget(); - - int sourceWidgetX, sourceWidgetY; - sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); - - distributeMouseEvent(sourceWidget, - MouseEvent::WHEEL_MOVED_UP, - mouseInput.getButton(), - mouseInput.getX(), - mouseInput.getY()); - } - - Widget* Gui::getWidgetAt(int x, int y) - { - // If the widget's parent has no child then we have found the widget.. - Widget* parent = mTop; - Widget* child = mTop; - - while (child) - { - Widget *const swap = child; - int parentX, parentY; - parent->getAbsolutePosition(parentX, parentY); - child = parent->getWidgetAt(x - parentX, y - parentY); - parent = swap; - } - - return parent; - } - - Widget* Gui::getMouseEventSource(int x, int y) - { - Widget *const widget = getWidgetAt(x, y); - - // +++ possible nullpointer - if (mFocusHandler->getModalMouseInputFocused() - && !widget->isModalMouseInputFocused()) - { - return mFocusHandler->getModalMouseInputFocused(); - } - - return widget; - } - - Widget* Gui::getKeyEventSource() - { - Widget* widget = mFocusHandler->getFocused(); - - // +++ possible nullpointer - while (widget->_getInternalFocusHandler() - && widget->_getInternalFocusHandler()->getFocused()) - { - widget = widget->_getInternalFocusHandler()->getFocused(); - } - - return widget; - } - - void Gui::distributeMouseEvent(Widget* source, - int type, - int button, - int x, - int y, - bool force, - bool toSourceOnly) - { - Widget* parent = source; - Widget* widget = source; - - if (mFocusHandler->getModalFocused() - && !widget->isModalFocused() - && !force) - { - return; - } - - if (mFocusHandler->getModalMouseInputFocused() - && !widget->isModalMouseInputFocused() - && !force) - { - return; - } - - MouseEvent mouseEvent(source, - mShiftPressed, - mControlPressed, - mAltPressed, - mMetaPressed, - type, - button, - x, - y, - mClickCount); - - while (parent) - { - // If the widget has been removed due to input - // cancel the distribution. - if (!Widget::widgetExists(widget)) - break; - - parent = widget->getParent(); - - if (widget->isEnabled() || force) - { - int widgetX, widgetY; - widget->getAbsolutePosition(widgetX, widgetY); - - mouseEvent.mX = x - widgetX; - mouseEvent.mY = y - widgetY; - - std::list<MouseListener*> mouseListeners - = widget->_getMouseListeners(); - - // Send the event to all mouse listeners of the widget. - for (std::list<MouseListener*>::const_iterator - it = mouseListeners.begin(); - it != mouseListeners.end(); - ++it) - { - switch (mouseEvent.getType()) - { - case MouseEvent::ENTERED: - (*it)->mouseEntered(mouseEvent); - break; - case MouseEvent::EXITED: - (*it)->mouseExited(mouseEvent); - break; - case MouseEvent::MOVED: - (*it)->mouseMoved(mouseEvent); - break; - case MouseEvent::PRESSED: - (*it)->mousePressed(mouseEvent); - break; - case MouseEvent::RELEASED: - (*it)->mouseReleased(mouseEvent); - break; - case MouseEvent::WHEEL_MOVED_UP: - (*it)->mouseWheelMovedUp(mouseEvent); - break; - case MouseEvent::WHEEL_MOVED_DOWN: - (*it)->mouseWheelMovedDown(mouseEvent); - break; - case MouseEvent::DRAGGED: - (*it)->mouseDragged(mouseEvent); - break; - case MouseEvent::CLICKED: - (*it)->mouseClicked(mouseEvent); - break; - default: - break; - } - } - - if (toSourceOnly) - break; - } - - const Widget *const swap = widget; - widget = parent; - parent = swap->getParent(); - - // If a non modal focused widget has been reach - // and we have modal focus cancel the distribution. - if (mFocusHandler->getModalFocused() - && !widget->isModalFocused()) - { - break; - } - - // If a non modal mouse input focused widget has been reach - // and we have modal mouse input focus cancel the distribution. - if (mFocusHandler->getModalMouseInputFocused() - && !widget->isModalMouseInputFocused()) - { - break; - } - } - } - - void Gui::distributeKeyEvent(KeyEvent& keyEvent) - { - Widget* parent = keyEvent.getSource(); - Widget* widget = keyEvent.getSource(); - - if (mFocusHandler->getModalFocused() - && !widget->isModalFocused()) - { - return; - } - - if (mFocusHandler->getModalMouseInputFocused() - && !widget->isModalMouseInputFocused()) - { - return; - } - - while (parent) - { - // If the widget has been removed due to input - // cancel the distribution. - if (!Widget::widgetExists(widget)) - break; - - parent = widget->getParent(); - - if (widget->isEnabled()) - { - std::list<KeyListener*> keyListeners - = widget->_getKeyListeners(); - - // Send the event to all key listeners of the source widget. - for (std::list<KeyListener*>::const_iterator - it = keyListeners.begin(); - it != keyListeners.end(); - ++it) - { - switch (keyEvent.getType()) - { - case KeyEvent::PRESSED: - (*it)->keyPressed(keyEvent); - break; - case KeyEvent::RELEASED: - (*it)->keyReleased(keyEvent); - break; - default: - break; - } - } - } - - const Widget *const swap = widget; - widget = parent; - parent = swap->getParent(); - - // If a non modal focused widget has been reach - // and we have modal focus cancel the distribution. - if (mFocusHandler->getModalFocused() - && !widget->isModalFocused()) - { - break; - } - } - } - - void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent) - { - for (KeyListenerListIterator it = mKeyListeners.begin(); - it != mKeyListeners.end(); ++ it) - { - switch (keyEvent.getType()) - { - case KeyEvent::PRESSED: - (*it)->keyPressed(keyEvent); - break; - case KeyEvent::RELEASED: - (*it)->keyReleased(keyEvent); - break; - default: - break; - } - - if (keyEvent.isConsumed()) - break; - } - } - - void Gui::handleModalMouseInputFocus() - { - BLOCK_START("Gui::handleModalMouseInputFocus") - // Check if modal mouse input focus has been gained by a widget. - if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() - != mFocusHandler->getModalMouseInputFocused()) - && (!mFocusHandler->getLastWidgetWithModalMouseInputFocus())) - { - handleModalFocusGained(); - mFocusHandler->setLastWidgetWithModalMouseInputFocus( - mFocusHandler->getModalMouseInputFocused()); - } - // Check if modal mouse input focus has been released. - else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() - != mFocusHandler->getModalMouseInputFocused()) - && (mFocusHandler->getLastWidgetWithModalMouseInputFocus())) - { - handleModalFocusReleased(); - mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr); - } - BLOCK_END("Gui::handleModalMouseInputFocus") - } - - void Gui::handleModalFocus() - { - BLOCK_START("Gui::handleModalFocus") - // Check if modal focus has been gained by a widget. - if ((mFocusHandler->getLastWidgetWithModalFocus() - != mFocusHandler->getModalFocused()) - && (!mFocusHandler->getLastWidgetWithModalFocus())) - { - handleModalFocusGained(); - mFocusHandler->setLastWidgetWithModalFocus( - mFocusHandler->getModalFocused()); - } - // Check if modal focus has been released. - else if ((mFocusHandler->getLastWidgetWithModalFocus() - != mFocusHandler->getModalFocused()) - && (mFocusHandler->getLastWidgetWithModalFocus())) - { - handleModalFocusReleased(); - mFocusHandler->setLastWidgetWithModalFocus(nullptr); - } - BLOCK_END("Gui::handleModalFocus") - } - - void Gui::handleModalFocusGained() - { - // Distribute an event to all widgets in the "widget with mouse" queue. - while (!mWidgetWithMouseQueue.empty()) - { - Widget *const widget = mWidgetWithMouseQueue.front(); - - if (Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::EXITED, - mLastMousePressButton, - mLastMouseX, - mLastMouseY, - true, - true); - } - - mWidgetWithMouseQueue.pop_front(); - } - - mFocusHandler->setLastWidgetWithModalMouseInputFocus( - mFocusHandler->getModalMouseInputFocused()); - } - - void Gui::handleModalFocusReleased() - { - // Check all widgets below the mouse to see if they are - // present in the "widget with mouse" queue. If a widget - // is not then it should be added and an entered event should - // be sent to it. - Widget* widget = getMouseEventSource(mLastMouseX, mLastMouseY); - Widget* parent = widget; - - while (parent) - { - parent = widget->getParent(); - - // Check if the widget is present in the "widget with mouse" queue. - bool widgetIsPresentInQueue = false; - FOR_EACH (std::deque<Widget*>::const_iterator, - iter, mWidgetWithMouseQueue) - { - if (*iter == widget) - { - widgetIsPresentInQueue = true; - break; - } - } - - // Widget is not present, send an entered event and add - // it to the "widget with mouse" queue. - if (!widgetIsPresentInQueue && Widget::widgetExists(widget)) - { - distributeMouseEvent(widget, - MouseEvent::ENTERED, - mLastMousePressButton, - mLastMouseX, - mLastMouseY, - false, - true); - mWidgetWithMouseQueue.push_front(widget); - } - - const Widget *const swap = widget; - widget = parent; - parent = swap->getParent(); - } - } -} // namespace gcn diff --git a/src/gui/base/gui.hpp b/src/gui/base/gui.hpp deleted file mode 100644 index 4ea923400..000000000 --- a/src/gui/base/gui.hpp +++ /dev/null @@ -1,515 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_GUI_HPP -#define GCN_GUI_HPP - -#include <list> -#include <deque> - -#include "localconsts.h" - -class Event; -class FocusHandler; -class Graphics; -class KeyEvent; -class KeyListener; -class MouseInput; -class SDLInput; -class Widget; - -namespace gcn -{ - // The following comment will appear in the doxygen main page. - /** - * @mainpage - * @section Introduction - * This documentation is mostly intended as a reference to the API. - * If you want to get started with Guichan, we suggest you check out - * the programs in the examples directory of the Guichan release. - * @n - * @n - * This documentation is, and will always be, work in progress. - * If you find any errors, typos or inconsistencies, or if you feel - * something needs to be explained in more detail - don't hesitate to - * tell us. - */ - - /** - * Contains a Guichan GUI. This is the core class of Guichan to which - * implementations of back ends are passed, to make Guichan work with - * a specific library, and to where the top widget (root widget of GUI) - * is added. If you want to be able to have more then one widget in your - * GUI, the top widget should be a container. - * - * A Gui object cannot work properly without passing back end - * implementations to it. A Gui object must have an implementation of a - * Graphics and an implementation of Input. - * - * NOTE: A complete GUI also must have the ability to load images. - * Images are loaded with the Image class, so to make Guichan - * able to load images an implementation of ImageLoader must be - * passed to Image. - * - * @see Graphics, Input, Image - */ - class Gui - { - public: - /** - * Constructor. - */ - Gui(); - - A_DELETE_COPY(Gui) - - /** - * Destructor. - */ - virtual ~Gui(); - - /** - * Sets the top widget. The top widget is the root widget - * of the GUI. If you want a GUI to be able to contain more - * than one widget the top widget should be a container. - * - * @param top The top widget. - * @see Container - * @since 0.1.0 - */ - virtual void setTop(Widget* top); - - /** - * Gets the top widget. The top widget is the root widget - * of the GUI. - * - * @return The top widget. NULL if no top widget has been set. - * @since 0.1.0 - */ - virtual Widget* getTop() const A_WARN_UNUSED; - - /** - * Sets the graphics object to use for drawing. - * - * @param graphics The graphics object to use for drawing. - * @see getGraphics, AllegroGraphics, HGEGraphics, - * OpenLayerGraphics, OpenGLGraphics, SDLGraphics - * @since 0.1.0 - */ - virtual void setGraphics(Graphics* graphics); - - /** - * Gets the graphics object used for drawing. - * - * @return The graphics object used for drawing. NULL if no - * graphics object has been set. - * @see setGraphics, AllegroGraphics, HGEGraphics, - * OpenLayerGraphics, OpenGLGraphics, SDLGraphics - * @since 0.1.0 - */ - virtual Graphics* getGraphics() const A_WARN_UNUSED; - - /** - * Sets the input object to use for input handling. - * - * @param input The input object to use for input handling. - * @see getInput, AllegroInput, HGEInput, OpenLayerInput, - * SDLInput - * @since 0.1.0 - */ - virtual void setInput(SDLInput* input); - - /** - * Gets the input object being used for input handling. - * - * @return The input object used for handling input. NULL if no - * input object has been set. - * @see setInput, AllegroInput, HGEInput, OpenLayerInput, - * SDLInput - * @since 0.1.0 - */ - virtual SDLInput* getInput() const A_WARN_UNUSED; - - /** - * Performs logic of the GUI. By calling this function all logic - * functions down in the GUI heirarchy will be called. When logic - * is called for Gui, user input will be handled. - * - * @see Widget::logic - * @since 0.1.0 - */ - virtual void logic(); - - /** - * Draws the GUI. By calling this funcion all draw functions - * down in the GUI hierarchy will be called. When draw is called - * the used Graphics object will be initialised and drawing of - * the top widget will commence. - * - * @see Widget::draw - * @since 0.1.0 - */ - virtual void draw(); - - /** - * Focuses none of the widgets in the Gui. - * - * @since 0.1.0 - */ - virtual void focusNone(); - - /** - * Sets tabbing enabled, or not. Tabbing is the usage of - * changing focus by utilising the tab key. - * - * @param tabbing True if tabbing should be enabled, false - * otherwise. - * @see isTabbingEnabled - * @since 0.1.0 - */ - virtual void setTabbingEnabled(bool tabbing); - - /** - * Checks if tabbing is enabled. - * - * @return True if tabbing is enabled, false otherwise. - * @see setTabbingEnabled - * @since 0.1.0 - */ - virtual bool isTabbingEnabled(); - - /** - * Adds a global key listener to the Gui. A global key listener - * will receive all key events generated from the GUI and global - * key listeners will receive the events before key listeners - * of widgets. - * - * @param keyListener The key listener to add. - * @see removeGlobalKeyListener - * @since 0.5.0 - */ - virtual void addGlobalKeyListener(KeyListener* keyListener); - - /** - * Removes global key listener from the Gui. - * - * @param keyListener The key listener to remove. - * @throws Exception if the key listener hasn't been added. - * @see addGlobalKeyListener - * @since 0.5.0 - */ - virtual void removeGlobalKeyListener(KeyListener* keyListener); - - protected: - /** - * Handles all mouse input. - * - * @since 0.6.0 - */ - virtual void handleMouseInput(); - - /** - * Handles key input. - * - * @since 0.6.0 - */ - virtual void handleKeyInput(); - - /** - * Handles mouse moved input. - * - * @param mouseInput The mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMouseMoved(const MouseInput& mouseInput); - - /** - * - * Handles mouse wheel moved down input. - * - * @param mouseInput The mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMouseWheelMovedDown(const MouseInput& mouseInput); - - /** - * Handles mouse wheel moved up input. - * - * @param mouseInput The mouse input to handle. - * @since 0.6.0 - */ - virtual void handleMouseWheelMovedUp(const MouseInput& mouseInput); - - /** - * Handles modal focus. Modal focus needs to be checked at - * each logic iteration as it might be necessary to distribute - * mouse entered or mouse exited events. - * - * @since 0.8.0 - */ - virtual void handleModalFocus(); - - /** - * Handles modal mouse input focus. Modal mouse input focus needs - * to be checked at each logic iteration as it might be necessary to - * distribute mouse entered or mouse exited events. - * - * @since 0.8.0 - */ - virtual void handleModalMouseInputFocus(); - - /** - * Handles modal focus gained. If modal focus has been gained it might - * be necessary to distribute mouse entered or mouse exited events. - * - * @since 0.8.0 - */ - virtual void handleModalFocusGained(); - - /** - * Handles modal mouse input focus gained. If modal focus has been - * gained it might be necessary to distribute mouse entered or mouse - * exited events. - * - * @since 0.8.0 - */ - virtual void handleModalFocusReleased(); - - /** - * Distributes a mouse event. - * - * @param type The type of the event to distribute, - * @param button The button of the event (if any used) to distribute. - * @param x The x coordinate of the event. - * @param y The y coordinate of the event. - * @param fource indicates whether the distribution should be forced or not. - * A forced distribution distributes the event even if a widget - * is not enabled, not visible, another widget has modal - * focus or another widget has modal mouse input focus. - * Default value is false. - * @param toSourceOnly indicates whether the distribution should be to the - * source widget only or to it's parent's mouse listeners - * as well. - * - * @since 0.6.0 - */ - virtual void distributeMouseEvent(Widget* source, - int type, - int button, - int x, - int y, - bool force = false, - bool toSourceOnly = false); - - /** - * Distributes a key event. - * - * @param keyEvent The key event to distribute. - - * @since 0.6.0 - */ - virtual void distributeKeyEvent(KeyEvent& keyEvent); - - /** - * Distributes a key event to the global key listeners. - * - * @param keyEvent The key event to distribute. - * - * @since 0.6.0 - */ - virtual void distributeKeyEventToGlobalKeyListeners(KeyEvent& - keyEvent); - - /** - * Gets the widget at a certain position. - * - * @return The widget at a certain position. - * @since 0.6.0 - */ - virtual Widget* getWidgetAt(int x, int y) A_WARN_UNUSED; - - /** - * Gets the source of the mouse event. - * - * @return The source widget of the mouse event. - * @since 0.6.0 - */ - virtual Widget* getMouseEventSource(int x, int y) A_WARN_UNUSED; - - /** - * Gets the source of the key event. - * - * @return The source widget of the key event. - * @since 0.6.0 - */ - virtual Widget* getKeyEventSource() A_WARN_UNUSED; - - /** - * Holds the top widget. - */ - Widget* mTop; - - /** - * Holds the graphics implementation used. - */ - Graphics* mGraphics; - - /** - * Holds the input implementation used. - */ - SDLInput* mInput; - - /** - * Holds the focus handler for the Gui. - */ - FocusHandler* mFocusHandler; - - /** - * True if tabbing is enabled, false otherwise. - */ - bool mTabbing; - - /** - * Typedef. - */ - typedef std::list<KeyListener*> KeyListenerList; - - /** - * Typedef. - */ - typedef KeyListenerList::iterator KeyListenerListIterator; - - /** - * Holds the global key listeners of the Gui. - */ - KeyListenerList mKeyListeners; - - /** - * True if shift is pressed, false otherwise. - */ - bool mShiftPressed; - - /** - * True if meta is pressed, false otherwise. - */ - bool mMetaPressed; - - /** - * True if control is pressed, false otherwise. - */ - bool mControlPressed; - - /** - * True if alt is pressed, false otherwise. - */ - bool mAltPressed; - - /** - * Holds the last mouse button pressed. - */ - unsigned int mLastMousePressButton; - - /** - * Holds the last mouse press time stamp. - */ - int mLastMousePressTimeStamp; - - /** - * Holds the last mouse x coordinate. - */ - int mLastMouseX; - - /** - * Holds the last mouse y coordinate. - */ - int mLastMouseY; - - /** - * Holds the current click count. Used to keep track - * of clicks for a the last pressed button. - */ - int mClickCount; - - /** - * Holds the last button used when a drag of a widget - * was initiated. Used to be able to release a drag - * when the same button is released. - */ - int mLastMouseDragButton; - - /** - * Holds a stack with all the widgets with the mouse. - * Used to properly distribute mouse events. - */ - std::deque<Widget*> mWidgetWithMouseQueue; - }; -} // namespace gcn - -#endif // end GCN_GUI_HPP - -/* yakslem - "Women, it's a constant struggle." - * finalman - "Yes, but sometimes they succeed with their guesses." - * yaklsem - "...eh...I was talking about love." - * finalman - "Oh...ok..." - * An awkward silence followed. - */ diff --git a/src/gui/base/widgets/button.cpp b/src/gui/base/widgets/button.cpp deleted file mode 100644 index 2d6afa672..000000000 --- a/src/gui/base/widgets/button.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/button.hpp" - -#include "events/mouseevent.h" - -#include "render/graphics.h" - -#include "debug.h" - -namespace gcn -{ - Button::Button(const Widget2 *const widget) : - Widget(widget), - MouseListener(), - KeyListener(), - FocusListener(), - mCaption(), - mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } - - Button::Button(const Widget2 *const widget, - const std::string& caption) : - Widget(widget), - MouseListener(), - KeyListener(), - FocusListener(), - mCaption(caption), - mHasMouse(false), - mKeyPressed(false), - mMousePressed(false), - mAlignment(Graphics::CENTER), - mSpacing(4) - { - setFocusable(true); - adjustSize(); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - addFocusListener(this); - } - - void Button::setCaption(const std::string& caption) - { - mCaption = caption; - } - - const std::string& Button::getCaption() const - { - return mCaption; - } - - void Button::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } - - Graphics::Alignment Button::getAlignment() const - { - return mAlignment; - } - - void Button::setSpacing(unsigned int spacing) - { - mSpacing = spacing; - } - - unsigned int Button::getSpacing() const - { - return mSpacing; - } - - void Button::adjustSize() - { - } - - bool Button::isPressed() const - { - if (mMousePressed) - return mHasMouse; - else - return mKeyPressed; - } - - void Button::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mMousePressed = true; - mouseEvent.consume(); - } - } - - void Button::mouseExited(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = false; - } - - void Button::mouseEntered(MouseEvent& mouseEvent A_UNUSED) - { - mHasMouse = true; - } - - void Button::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void Button::focusLost(const Event& event A_UNUSED) - { - mMousePressed = false; - mKeyPressed = false; - } -} // namespace gcn diff --git a/src/gui/base/widgets/button.hpp b/src/gui/base/widgets/button.hpp deleted file mode 100644 index 99e5db4f4..000000000 --- a/src/gui/base/widgets/button.hpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_BUTTON_HPP -#define GCN_BUTTON_HPP - -#include <string> - -#include "listeners/focuslistener.h" -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -#include "gui/widgets/widget.h" - -#include "render/graphics.h" - -namespace gcn -{ - /** - * An implementation of a regular clickable button. A button is capable of - * displaying a caption. - * - * If a button is clicked an action event will be sent to all action listener's - * of the button. - * - * @see ImageButton - */ - class Button : public Widget, - public MouseListener, - public KeyListener, - public FocusListener - { - public: - /** - * Constructor. - */ - explicit Button(const Widget2 *const widget); - - /** - * Constructor. The button will be automatically resized - * to fit the caption. - * - * @param caption The caption of the button. - */ - Button(const Widget2 *const widget, - const std::string& caption); - - A_DELETE_COPY(Button) - - /** - * Sets the caption of the button. It's advisable to call - * adjustSize after setting of the caption to adjust the - * button's size to fit the caption. - * - * @param caption The caption of the button. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); - - /** - * Gets the caption of the button. - * - * @return The caption of the button. - */ - const std::string& getCaption() const; - - /** - * Sets the alignment of the caption. The alignment is relative - * to the center of the button. - * - * @param alignment The alignment of the caption. - * @see getAlignment, Graphics - */ - void setAlignment(Graphics::Alignment alignment); - - /** - * Gets the alignment of the caption. - * - * @return The alignment of the caption. - * @see setAlignment, Graphics - */ - Graphics::Alignment getAlignment() const; - - /** - * Sets the spacing between the border of the button and its caption. - * - * @param spacing The default value for spacing is 4 and can be changed - * using this method. - * @see getSpacing - */ - void setSpacing(unsigned int spacing); - - /** - * Gets the spacing between the border of the button and its caption. - * - * @return spacing. - * @see setSpacing - */ - unsigned int getSpacing() const; - - /** - * Adjusts the button's size to fit the caption. - */ - void adjustSize(); - - - // Inherited from FocusListener - - virtual void focusLost(const Event& event); - - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent) override; - - virtual void mouseEntered(MouseEvent& mouseEvent) override; - - virtual void mouseExited(MouseEvent& mouseEvent) override; - - virtual void mouseDragged(MouseEvent& mouseEvent) override; - - protected: - /** - * Checks if the button is pressed. Convenient method to use - * when overloading the draw method of the button. - * - * @return True if the button is pressed, false otherwise. - */ - bool isPressed() const; - - /** - * Holds the caption of the button. - */ - std::string mCaption; - - /** - * True if the mouse is ontop of the button, false otherwise. - */ - bool mHasMouse; - - /** - * True if a key has been pressed, false otherwise. - */ - bool mKeyPressed; - - /** - * True if a mouse has been pressed, false otherwise. - */ - bool mMousePressed; - - /** - * Holds the alignment of the caption. - */ - Graphics::Alignment mAlignment; - - /** - * Holds the spacing between the border and the caption. - */ - unsigned int mSpacing; - }; -} // namespace gcn - -#endif // end GCN_BUTTON_HPP diff --git a/src/gui/base/widgets/checkbox.cpp b/src/gui/base/widgets/checkbox.cpp deleted file mode 100644 index 476fb3c6b..000000000 --- a/src/gui/base/widgets/checkbox.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/checkbox.hpp" - -#include "debug.h" - -namespace gcn -{ - - CheckBox::CheckBox(const Widget2 *const widget) : - Widget(widget), - MouseListener(), - KeyListener(), - mSelected(false), - mCaption() - { - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - CheckBox::CheckBox(const Widget2 *const widget, - const std::string &caption, - bool selected) : - Widget(widget), - MouseListener(), - KeyListener(), - mSelected(selected), - mCaption() - { - setCaption(caption); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - - adjustSize(); - } - - bool CheckBox::isSelected() const - { - return mSelected; - } - - void CheckBox::setSelected(bool selected) - { - mSelected = selected; - } - - const std::string &CheckBox::getCaption() const - { - return mCaption; - } - - void CheckBox::setCaption(const std::string& caption) - { - mCaption = caption; - } - - void CheckBox::keyPressed(KeyEvent& keyEvent A_UNUSED) - { - } - - void CheckBox::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - toggleSelected(); - } - } - - void CheckBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void CheckBox::adjustSize() - { - } - - void CheckBox::toggleSelected() - { - mSelected = !mSelected; - distributeActionEvent(); - } -} // namespace gcn diff --git a/src/gui/base/widgets/checkbox.hpp b/src/gui/base/widgets/checkbox.hpp deleted file mode 100644 index 6fcb04767..000000000 --- a/src/gui/base/widgets/checkbox.hpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_CHECKBOX_HPP -#define GCN_CHECKBOX_HPP - -#include <string> - -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -#include "gui/widgets/widget.h" - -namespace gcn -{ - /** - * An implementation of a check box where a user can select or deselect - * the check box and where the status of the check box is displayed to the user. - * A check box is capable of displaying a caption. - * - * If a check box's state changes an action event will be sent to all action - * listeners of the check box. - */ - class CheckBox : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Contructor. - */ - explicit CheckBox(const Widget2 *const widget); - - /** - * Constructor. The check box will be automatically resized - * to fit the caption. - * - * @param caption The caption of the check box. - * @param marked True if the check box is selected, false otherwise. - */ - CheckBox(const Widget2 *const widget, - const std::string &caption, - bool selected = false); - - A_DELETE_COPY(CheckBox) - - /** - * Destructor. - */ - virtual ~CheckBox() - { } - - /** - * Checks if the check box is selected. - * - * @return True if the check box is selected, false otherwise. - * @see setSelected - */ - bool isSelected() const; - - /** - * Sets the check box to be selected or not. - * - * @param selected True if the check box should be set as selected. - * @see isSelected - */ - void setSelected(bool selected); - - /** - * Gets the caption of the check box. - * - * @return The caption of the check box. - * @see setCaption - */ - const std::string &getCaption() const; - - /** - * Sets the caption of the check box. It's advisable to call - * adjustSize after setting of the caption to adjust the - * check box's size to fit the caption. - * - * @param caption The caption of the check box. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); - - /** - * Adjusts the check box's size to fit the caption. - */ - void adjustSize(); - - // Inherited from KeyListener - - virtual void keyPressed(KeyEvent& keyEvent) override; - - // Inherited from MouseListener - - virtual void mouseClicked(MouseEvent& mouseEvent) override; - - virtual void mouseDragged(MouseEvent& mouseEvent) override; - - - protected: - /** - * Toggles the check box between being selected and - * not being selected. - */ - virtual void toggleSelected(); - - /** - * True if the check box is selected, false otherwise. - */ - bool mSelected; - - /** - * Holds the caption of the check box. - */ - std::string mCaption; - }; -} // namespace gcn - -#endif // end GCN_CHECKBOX_HPP diff --git a/src/gui/base/widgets/container.cpp b/src/gui/base/widgets/container.cpp deleted file mode 100644 index 53a900ec4..000000000 --- a/src/gui/base/widgets/container.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/container.hpp" - - -#include "render/graphics.h" - -#include "debug.h" - -namespace gcn -{ - - Container::Container(const Widget2 *const widget) : - BasicContainer(widget), - mOpaque(true) - { - } - - Container::~Container() - { - } - - void Container::draw(Graphics* graphics) - { - BLOCK_START("Container::draw") - if (isOpaque()) - { - graphics->setColor(getBaseColor()); - graphics->fillRectangle(Rect(0, 0, getWidth(), getHeight())); - } - - drawChildren(graphics); - BLOCK_END("Container::draw") - } - - void Container::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool Container::isOpaque() const - { - return mOpaque; - } - - void Container::add(Widget* widget) - { - BasicContainer::add(widget); - } - - void Container::add(Widget* widget, int x, int y) - { - widget->setPosition(x, y); - BasicContainer::add(widget); - } - - void Container::remove(Widget* widget) - { - BasicContainer::remove(widget); - } - - void Container::clear() - { - BasicContainer::clear(); - } - - Widget* Container::findWidgetById(const std::string &id) - { - return BasicContainer::findWidgetById(id); - } -} // namespace gcn diff --git a/src/gui/base/widgets/label.hpp b/src/gui/base/widgets/label.hpp deleted file mode 100644 index fd0d54f8e..000000000 --- a/src/gui/base/widgets/label.hpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_LABEL_HPP -#define GCN_LABEL_HPP - -#include <string> - -#include "gui/widgets/widget.h" - -#include "render/graphics.h" - -namespace gcn -{ - /** - * Implementation of a label capable of displaying a caption. - */ - class Label: public Widget - { - public: - /** - * Constructor. - */ - explicit Label(const Widget2 *const widget); - - /** - * Constructor. The label will be automatically resized - * to fit the caption. - * - * @param caption The caption of the label. - */ - Label(const Widget2 *const widget, - const std::string& caption); - - A_DELETE_COPY(Label) - - /** - * Gets the caption of the label. - * - * @return The caption of the label. - * @see setCaption - */ - const std::string &getCaption() const; - - /** - * Sets the caption of the label. It's advisable to call - * adjustSize after setting of the caption to adjust the - * label's size to fit the caption. - * - * @param caption The caption of the label. - * @see getCaption, adjustSize - */ - void setCaption(const std::string& caption); - - /** - * Sets the alignment of the caption. The alignment is relative - * to the center of the label. - * - * @param alignemnt The alignment of the caption of the label. - * @see getAlignment, Graphics - */ - void setAlignment(Graphics::Alignment alignment); - - /** - * Gets the alignment of the caption. The alignment is relative to - * the center of the label. - * - * @return The alignment of caption of the label. - * @see setAlignmentm Graphics - */ - Graphics::Alignment getAlignment() const; - - /** - * Adjusts the label's size to fit the caption. - */ - void adjustSize(); - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - protected: - /** - * Holds the caption of the label. - */ - std::string mCaption; - - /** - * Holds the alignment of the caption. - */ - Graphics::Alignment mAlignment; - }; -} // namespace gcn - -#endif // end GCN_LABEL_HPP diff --git a/src/gui/base/widgets/listbox.cpp b/src/gui/base/widgets/listbox.cpp deleted file mode 100644 index 2e9606f0a..000000000 --- a/src/gui/base/widgets/listbox.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/listbox.hpp" - -#include "gui/font.h" - -#include "gui/models/listmodel.h" - -#include "listeners/selectionlistener.h" - -#include "debug.h" - -namespace gcn -{ - ListBox::ListBox(const Widget2 *const widget) : - Widget(widget), - MouseListener(), - KeyListener(), - mSelected(-1), - mListModel(nullptr), - mWrappingEnabled(false), - mSelectionListeners() - { - setWidth(100); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - ListBox::ListBox(const Widget2 *const widget, - ListModel *listModel) : - Widget(widget), - MouseListener(), - KeyListener(), - mSelected(-1), - mListModel(listModel), - mWrappingEnabled(false), - mSelectionListeners() - { - setWidth(100); - adjustSize(); - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - void ListBox::draw(Graphics* graphics A_UNUSED) - { - } - - void ListBox::logic() - { - } - - int ListBox::getSelected() const - { - return mSelected; - } - - void ListBox::setSelected(int selected) - { - if (!mListModel) - { - mSelected = -1; - } - else - { - if (selected < 0) - mSelected = -1; - else if (selected >= mListModel->getNumberOfElements()) - mSelected = mListModel->getNumberOfElements() - 1; - else - mSelected = selected; - } - - Rect scroll; - - if (mSelected < 0) - scroll.y = 0; - else - scroll.y = getRowHeight() * mSelected; - - scroll.height = getRowHeight(); - showPart(scroll); - - distributeValueChangedEvent(); - } - - void ListBox::keyPressed(KeyEvent &keyEvent A_UNUSED) - { - } - - void ListBox::mousePressed(MouseEvent &mouseEvent A_UNUSED) - { - } - - void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (isFocused()) - { - if (getSelected() > 0 ) - setSelected(getSelected() - 1); - - mouseEvent.consume(); - } - } - - void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (isFocused()) - { - setSelected(getSelected() + 1); - - mouseEvent.consume(); - } - } - - void ListBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void ListBox::setListModel(ListModel *listModel) - { - mSelected = -1; - mListModel = listModel; - adjustSize(); - } - - ListModel* ListBox::getListModel() - { - return mListModel; - } - - void ListBox::adjustSize() - { - } - - bool ListBox::isWrappingEnabled() const - { - return mWrappingEnabled; - } - - void ListBox::setWrappingEnabled(bool wrappingEnabled) - { - mWrappingEnabled = wrappingEnabled; - } - - void ListBox::addSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.push_back(selectionListener); - } - - void ListBox::removeSelectionListener(SelectionListener* selectionListener) - { - mSelectionListeners.remove(selectionListener); - } - - void ListBox::distributeValueChangedEvent() - { - for (SelectionListenerIterator iter = mSelectionListeners.begin(); - iter != mSelectionListeners.end(); - ++ iter) - { - SelectionEvent event(this); - (*iter)->valueChanged(event); - } - } - - unsigned int ListBox::getRowHeight() const - { - return getFont()->getHeight(); - } -} // namespace gcn diff --git a/src/gui/base/widgets/listbox.hpp b/src/gui/base/widgets/listbox.hpp deleted file mode 100644 index 079e5a7d5..000000000 --- a/src/gui/base/widgets/listbox.hpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_LISTBOX_HPP -#define GCN_LISTBOX_HPP - -#include <list> - -#include "gui/widgets/widget.h" - -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -class ListModel; -class SelectionListener; - -namespace gcn -{ - /** - * An implementation of a list box where an item can be selected. - * - * To be able display a list the list box uses a user provided list model. - * A list model can be any class that implements the ListModel interface. - * - * If an item is selected in the list box a select event will be sent to - * all selection listeners of the list box. If an item is selected by using - * a mouse click or by using the enter or space key an action event will be - * sent to all action listeners of the list box. - */ - class ListBox : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - explicit ListBox(const Widget2 *const widget); - - /** - * Constructor. - * - * @param listModel the list model to use. - */ - ListBox(const Widget2 *const widget, - ListModel *listModel); - - A_DELETE_COPY(ListBox) - - /** - * Destructor. - */ - virtual ~ListBox() - { } - - /** - * Gets the selected item as an index in the list model. - * - * @return the selected item as an index in the list model. - * @see setSelected - */ - int getSelected() const; - - /** - * Sets the selected item. The selected item is represented by - * an index from the list model. - * - * @param selected the selected item as an index from the list model. - * @see getSelected - */ - void setSelected(int selected); - - /** - * Sets the list model to use. - * - * @param listModel the list model to use. - * @see getListModel - */ - void setListModel(ListModel *listModel); - - /** - * Gets the list model used. - * - * @return the list model used. - * @see setListModel - */ - ListModel *getListModel(); - - /** - * Adjusts the size of the list box to fit it's list model. - */ - void adjustSize(); - - /** - * Checks whether the list box wraps when selecting items with a - * keyboard. - * - * Wrapping means that the selection of items will be wrapped. That is, - * if the first item is selected and up is pressed, the last item will - * get selected. If the last item is selected and down is pressed, the - * first item will get selected. - * - * @return true if wrapping is enabled, fasle otherwise. - * @see setWrappingEnabled - */ - bool isWrappingEnabled() const; - - /** - * Sets the list box to wrap or not when selecting items with a - * keyboard. - * - * Wrapping means that the selection of items will be wrapped. That is, - * if the first item is selected and up is pressed, the last item will - * get selected. If the last item is selected and down is pressed, the - * first item will get selected. - * - * @see isWrappingEnabled - */ - void setWrappingEnabled(bool wrappingEnabled); - - /** - * Adds a selection listener to the list box. When the selection - * changes an event will be sent to all selection listeners of the - * list box. - * - * If you delete your selection listener, be sure to also remove it - * using removeSelectionListener(). - * - * @param selectionListener The selection listener to add. - * @since 0.8.0 - */ - void addSelectionListener(SelectionListener* selectionListener); - - /** - * Removes a selection listener from the list box. - * - * @param selectionListener The selection listener to remove. - * @since 0.8.0 - */ - void removeSelectionListener(SelectionListener* selectionListener); - - /** - * Gets the height of a row. Should be overridden if another row - * height than the font height is preferred. - * - * @return The height of a row. - * @since 0.8.0 - */ - virtual unsigned int getRowHeight() const; - - - // Inherited from Widget - - virtual void draw(Graphics* graphics); - - virtual void logic(); - - - // Inherited from KeyListener - - virtual void keyPressed(KeyEvent& keyEvent) override; - - - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent) override; - - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) override; - - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) override; - - virtual void mouseDragged(MouseEvent& mouseEvent) override; - - - protected: - /** - * Distributes a value changed event to all selection listeners - * of the list box. - * - * @since 0.8.0 - */ - void distributeValueChangedEvent(); - - /** - * The selected item as an index in the list model. - */ - int mSelected; - - /** - * The list model to use. - */ - ListModel *mListModel; - - /** - * True if wrapping is enabled, false otherwise. - */ - bool mWrappingEnabled; - - /** - * Typdef. - */ - typedef std::list<SelectionListener*> SelectionListenerList; - - /** - * The selection listeners of the list box. - */ - SelectionListenerList mSelectionListeners; - - /** - * Typedef. - */ - typedef SelectionListenerList::iterator SelectionListenerIterator; - }; -} // namespace gcn - -#endif // end GCN_LISTBOX_HPP diff --git a/src/gui/base/widgets/radiobutton.cpp b/src/gui/base/widgets/radiobutton.cpp deleted file mode 100644 index f9d68555a..000000000 --- a/src/gui/base/widgets/radiobutton.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/radiobutton.hpp" - -#include "debug.h" - -namespace gcn -{ - RadioButton::GroupMap RadioButton::mGroupMap; - - RadioButton::RadioButton(const Widget2 *const widget) : - Widget(widget), - MouseListener(), - KeyListener(), - mSelected(false), - mCaption(), - mGroup() - { - setSelected(false); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - } - - RadioButton::RadioButton(const Widget2 *const widget, - const std::string &caption, - const std::string &group, - bool selected) : - Widget(widget), - MouseListener(), - KeyListener(), - mSelected(false), - mCaption(), - mGroup() - { - setCaption(caption); - setGroup(group); - setSelected(selected); - - setFocusable(true); - addMouseListener(this); - addKeyListener(this); - - adjustSize(); - } - - RadioButton::~RadioButton() - { - // Remove us from the group list - setGroup(""); - } - - bool RadioButton::isSelected() const - { - return mSelected; - } - - void RadioButton::setSelected(bool selected) - { - if (selected && mGroup != "") - { - for (GroupIterator iter = mGroupMap.lower_bound(mGroup), - iterEnd = mGroupMap.upper_bound(mGroup); - iter != iterEnd; - ++ iter) - { - if (iter->second->isSelected()) - iter->second->setSelected(false); - } - } - - mSelected = selected; - } - - const std::string &RadioButton::getCaption() const - { - return mCaption; - } - - void RadioButton::setCaption(const std::string &caption) - { - mCaption = caption; - } - - void RadioButton::keyPressed(KeyEvent& keyEvent A_UNUSED) - { - } - - void RadioButton::mouseClicked(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - setSelected(true); - distributeActionEvent(); - } - } - - void RadioButton::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void RadioButton::setGroup(const std::string &group) - { - if (mGroup != "") - { - for (GroupIterator iter = mGroupMap.lower_bound(mGroup), - iterEnd = mGroupMap.upper_bound(mGroup); - iter != iterEnd; - ++ iter) - { - if (iter->second == this) - { - mGroupMap.erase(iter); - break; - } - } - } - - if (group != "") - { - mGroupMap.insert( - std::pair<std::string, RadioButton *>(group, this)); - } - - mGroup = group; - } - - const std::string &RadioButton::getGroup() const - { - return mGroup; - } - - void RadioButton::adjustSize() - { - } -} // namespace gcn diff --git a/src/gui/base/widgets/radiobutton.hpp b/src/gui/base/widgets/radiobutton.hpp deleted file mode 100644 index a86a4eed3..000000000 --- a/src/gui/base/widgets/radiobutton.hpp +++ /dev/null @@ -1,228 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_RADIOBUTTON_HPP -#define GCN_RADIOBUTTON_HPP - -#include <map> -#include <string> - -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -#include "gui/widgets/widget.h" - -namespace gcn -{ - /** - * An implementation of a radio button where a user can select or deselect - * the radio button and where the status of the radio button is displayed to the user. - * A radio button can belong to a group and when a radio button belongs to a - * group only one radio button can be selected in the group. A radio button is - * capable of displaying a caption. - * - * If a radio button's state changes an action event will be sent to all action - * listeners of the check box. - */ - class RadioButton : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - explicit RadioButton(const Widget2 *const widget); - - /** - * Constructor. The radio button will be automatically resized - * to fit the caption. - * - * @param caption The caption of the radio button. - * @param group The group the radio button should belong to. - * @param selected True if the radio button should be selected. - */ - RadioButton(const Widget2 *const widget, - const std::string &caption, - const std::string &group, - bool selected = false); - - A_DELETE_COPY(RadioButton) - - /** - * Destructor. - */ - virtual ~RadioButton(); - - /** - * Checks if the radio button is selected. - * - * @return True if the radio button is selecte, false otherwise. - * @see setSelected - */ - bool isSelected() const; - - /** - * Sets the radio button to selected or not. - * - * @param selected True if the radio button should be selected, - * false otherwise. - * @see isSelected - */ - void setSelected(bool selected); - - /** - * Gets the caption of the radio button. - * - * @return The caption of the radio button. - * @see setCaption - */ - const std::string &getCaption() const; - - /** - * Sets the caption of the radio button. It's advisable to call - * adjustSize after setting of the caption to adjust the - * radio button's size to fit the caption. - * - * @param caption The caption of the radio button. - * @see getCaption, adjustSize - */ - void setCaption(const std::string &caption); - - /** - * Sets the group the radio button should belong to. Note that - * a radio button group is unique per application, not per Gui object - * as the group is stored in a static map. - * - * @param group The name of the group. - * @see getGroup - */ - void setGroup(const std::string &group); - - /** - * Gets the group the radio button belongs to. - * - * @return The group the radio button belongs to. - * @see setGroup - */ - const std::string &getGroup() const; - - /** - * Adjusts the radio button's size to fit the caption. - */ - void adjustSize(); - - - // Inherited from KeyListener - - virtual void keyPressed(KeyEvent& keyEvent) override; - - - // Inherited from MouseListener - - virtual void mouseClicked(MouseEvent& mouseEvent) override; - - virtual void mouseDragged(MouseEvent& mouseEvent) override; - - protected: - /** - * Draws the box. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBox(Graphics *graphics) = 0; - - /** - * True if the radio button is selected, false otherwise. - */ - bool mSelected; - - /** - * Holds the caption of the radio button. - */ - std::string mCaption; - - /** - * Holds the group of the radio button. - */ - std::string mGroup; - - /** - * Typdef. - */ - typedef std::multimap<std::string, RadioButton *> GroupMap; - - /** - * Typdef. - */ - typedef GroupMap::iterator GroupIterator; - - /** - * Holds all available radio button groups. - */ - static GroupMap mGroupMap; - }; -} // namespace gcn - -#endif // end GCN_RADIOBUTTON_HPP diff --git a/src/gui/base/widgets/scrollarea.cpp b/src/gui/base/widgets/scrollarea.cpp deleted file mode 100644 index 665830ce4..000000000 --- a/src/gui/base/widgets/scrollarea.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/scrollarea.hpp" - -#include "debug.h" - -namespace gcn -{ - ScrollArea::ScrollArea(const Widget2 *const widget) : - gcn::BasicContainer(widget), - MouseListener(), - mVScroll(0), - mHScroll(0), - mScrollbarWidth(12), - mHPolicy(SHOW_AUTO), - mVPolicy(SHOW_AUTO), - mVBarVisible(false), - mHBarVisible(false), - mUpButtonPressed(false), - mDownButtonPressed(false), - mLeftButtonPressed(false), - mRightButtonPressed(false), - mUpButtonScrollAmount(10), - mDownButtonScrollAmount(10), - mLeftButtonScrollAmount(10), - mRightButtonScrollAmount(10), - mIsVerticalMarkerDragged(false), - mIsHorizontalMarkerDragged(false), - mHorizontalMarkerDragOffset(0), - mVerticalMarkerDragOffset(0), - mOpaque(true) - { - addMouseListener(this); - } - - ScrollArea::ScrollArea(const Widget2 *const widget, - Widget *const content) : - gcn::BasicContainer(widget), - MouseListener(), - mVScroll(0), - mHScroll(0), - mScrollbarWidth(12), - mHPolicy(SHOW_AUTO), - mVPolicy(SHOW_AUTO), - mVBarVisible(false), - mHBarVisible(false), - mUpButtonPressed(false), - mDownButtonPressed(false), - mLeftButtonPressed(false), - mRightButtonPressed(false), - mUpButtonScrollAmount(10), - mDownButtonScrollAmount(10), - mLeftButtonScrollAmount(10), - mRightButtonScrollAmount(10), - mIsVerticalMarkerDragged(false), - mIsHorizontalMarkerDragged(false), - mHorizontalMarkerDragOffset(0), - mVerticalMarkerDragOffset(0), - mOpaque(true) - { - setContent(content); - addMouseListener(this); - } - - ScrollArea::ScrollArea(const Widget2 *const widget, - Widget *content, - ScrollPolicy hPolicy, - ScrollPolicy vPolicy) : - gcn::BasicContainer(widget), - MouseListener(), - mVScroll(0), - mHScroll(0), - mScrollbarWidth(12), - mHPolicy(hPolicy), - mVPolicy(vPolicy), - mVBarVisible(false), - mHBarVisible(false), - mUpButtonPressed(false), - mDownButtonPressed(false), - mLeftButtonPressed(false), - mRightButtonPressed(false), - mUpButtonScrollAmount(10), - mDownButtonScrollAmount(10), - mLeftButtonScrollAmount(10), - mRightButtonScrollAmount(10), - mIsVerticalMarkerDragged(false), - mIsHorizontalMarkerDragged(false), - mHorizontalMarkerDragOffset(0), - mVerticalMarkerDragOffset(0), - mOpaque(true) - { - setContent(content); - addMouseListener(this); - } - - ScrollArea::~ScrollArea() - { - setContent(nullptr); - } - - void ScrollArea::setContent(Widget* widget) - { - if (widget) - { - clear(); - add(widget); - widget->setPosition(0, 0); - } - else - { - clear(); - } - - checkPolicies(); - } - - Widget* ScrollArea::getContent() - { - if (!mWidgets.empty()) - return *mWidgets.begin(); - - return nullptr; - } - - void ScrollArea::setHorizontalScrollPolicy(ScrollPolicy hPolicy) - { - mHPolicy = hPolicy; - checkPolicies(); - } - - ScrollArea::ScrollPolicy ScrollArea::getHorizontalScrollPolicy() const - { - return mHPolicy; - } - - void ScrollArea::setVerticalScrollPolicy(ScrollPolicy vPolicy) - { - mVPolicy = vPolicy; - checkPolicies(); - } - - ScrollArea::ScrollPolicy ScrollArea::getVerticalScrollPolicy() const - { - return mVPolicy; - } - - void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy, - ScrollPolicy vPolicy) - { - mHPolicy = hPolicy; - mVPolicy = vPolicy; - checkPolicies(); - } - - void ScrollArea::setVerticalScrollAmount(int vScroll) - { - const int max = getVerticalMaxScroll(); - - mVScroll = vScroll; - - if (vScroll > max) - mVScroll = max; - - if (vScroll < 0) - mVScroll = 0; - } - - int ScrollArea::getVerticalScrollAmount() const - { - return mVScroll; - } - - void ScrollArea::setHorizontalScrollAmount(int hScroll) - { - const int max = getHorizontalMaxScroll(); - - mHScroll = hScroll; - - if (hScroll > max) - mHScroll = max; - else if (hScroll < 0) - mHScroll = 0; - } - - int ScrollArea::getHorizontalScrollAmount() const - { - return mHScroll; - } - - void ScrollArea::setScrollAmount(int hScroll, int vScroll) - { - setHorizontalScrollAmount(hScroll); - setVerticalScrollAmount(vScroll); - } - - int ScrollArea::getHorizontalMaxScroll() - { - checkPolicies(); - - const Widget *const content = getContent(); - if (!content) - return 0; - - const int value = content->getWidth() - getChildrenArea().width + - 2 * content->getFrameSize(); - - if (value < 0) - return 0; - - return value; - } - - int ScrollArea::getVerticalMaxScroll() - { - checkPolicies(); - - const Widget *const content = getContent(); - if (!content) - return 0; - - int value; - - value = content->getHeight() - getChildrenArea().height + - 2 * content->getFrameSize(); - - if (value < 0) - return 0; - - return value; - } - - void ScrollArea::setScrollbarWidth(int width) - { - if (width > 0) - mScrollbarWidth = width; - } - - int ScrollArea::getScrollbarWidth() const - { - return mScrollbarWidth; - } - - void ScrollArea::mouseReleased(MouseEvent& mouseEvent) - { - mUpButtonPressed = false; - mDownButtonPressed = false; - mLeftButtonPressed = false; - mRightButtonPressed = false; - mIsHorizontalMarkerDragged = false; - mIsVerticalMarkerDragged = false; - - mouseEvent.consume(); - } - - void ScrollArea::draw(Graphics *graphics A_UNUSED) - { - } - - void ScrollArea::drawHBar(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawVBar(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawBackground(Graphics *graphics A_UNUSED) - { - } - - void ScrollArea::drawUpButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawDownButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawLeftButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawRightButton(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawVMarker(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::drawHMarker(Graphics* graphics A_UNUSED) - { - } - - void ScrollArea::logic() - { - BLOCK_START("ScrollArea::logic") - checkPolicies(); - - setVerticalScrollAmount(getVerticalScrollAmount()); - setHorizontalScrollAmount(getHorizontalScrollAmount()); - - Widget *const content = getContent(); - if (content) - { - const int frameSize = content->getFrameSize(); - content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize); - content->logic(); - } - BLOCK_END("ScrollArea::logic") - } - - void ScrollArea::checkPolicies() - { - const int w = getWidth(); - const int h = getHeight(); - - mHBarVisible = false; - mVBarVisible = false; - - const Widget *const content = getContent(); - if (!content) - { - mHBarVisible = (mHPolicy == SHOW_ALWAYS); - mVBarVisible = (mVPolicy == SHOW_ALWAYS); - return; - } - - if (mHPolicy == SHOW_AUTO && - mVPolicy == SHOW_AUTO) - { - if (content->getWidth() <= w - && content->getHeight() <= h) - { - mHBarVisible = false; - mVBarVisible = false; - } - - if (content->getWidth() > w) - { - mHBarVisible = true; - } - - if ((content->getHeight() > h) - || (mHBarVisible && content->getHeight() - > h - mScrollbarWidth)) - { - mVBarVisible = true; - } - - if (mVBarVisible && content->getWidth() > w - mScrollbarWidth) - mHBarVisible = true; - - return; - } - - switch (mHPolicy) - { - case SHOW_NEVER: - mHBarVisible = false; - break; - - case SHOW_ALWAYS: - mHBarVisible = true; - break; - - case SHOW_AUTO: - if (mVPolicy == SHOW_NEVER) - { - mHBarVisible = (content->getWidth() > w); - } - else // (mVPolicy == SHOW_ALWAYS) - { - mHBarVisible = (content->getWidth() - > w - mScrollbarWidth); - } - break; - - default: - break; - } - - switch (mVPolicy) - { - case SHOW_NEVER: - mVBarVisible = false; - break; - - case SHOW_ALWAYS: - mVBarVisible = true; - break; - - case SHOW_AUTO: - if (mHPolicy == SHOW_NEVER) - { - mVBarVisible = (content->getHeight() > h); - } - else // (mHPolicy == SHOW_ALWAYS) - { - mVBarVisible = (content->getHeight() - > h - mScrollbarWidth); - } - break; - default: - break; - } - } - - Rect ScrollArea::getChildrenArea() - { - const Rect area = Rect(0, 0, - mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(), - mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight()); - - if (area.width < 0 || area.height < 0) - return Rect(); - - return area; - } - - void ScrollArea::showWidgetPart(Widget* widget, Rect area) - { - const Widget *const content = getContent(); - if (widget != content) - return; - - BasicContainer::showWidgetPart(widget, area); - - setHorizontalScrollAmount(content->getFrameSize() - - content->getX()); - setVerticalScrollAmount(content->getFrameSize() - - content->getY()); - } - - Widget *ScrollArea::getWidgetAt(int x, int y) - { - if (getChildrenArea().isPointInRect(x, y)) - return getContent(); - - return nullptr; - } - - void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - return; - - setVerticalScrollAmount(getVerticalScrollAmount() - - getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - if (mouseEvent.isConsumed()) - return; - - setVerticalScrollAmount(getVerticalScrollAmount() - + getChildrenArea().height / 8); - - mouseEvent.consume(); - } - - void ScrollArea::setWidth(int width) - { - Widget::setWidth(width); - checkPolicies(); - } - - void ScrollArea::setHeight(int height) - { - Widget::setHeight(height); - checkPolicies(); - } - - void ScrollArea::setDimension(const Rect& dimension) - { - Widget::setDimension(dimension); - checkPolicies(); - } - - void ScrollArea::setLeftButtonScrollAmount(int amount) - { - mLeftButtonScrollAmount = amount; - } - - void ScrollArea::setRightButtonScrollAmount(int amount) - { - mRightButtonScrollAmount = amount; - } - - void ScrollArea::setUpButtonScrollAmount(int amount) - { - mUpButtonScrollAmount = amount; - } - - void ScrollArea::setDownButtonScrollAmount(int amount) - { - mDownButtonScrollAmount = amount; - } - - int ScrollArea::getLeftButtonScrollAmount() const - { - return mLeftButtonScrollAmount; - } - - int ScrollArea::getRightButtonScrollAmount() const - { - return mRightButtonScrollAmount; - } - - int ScrollArea::getUpButtonScrollAmount() const - { - return mUpButtonScrollAmount; - } - - int ScrollArea::getDownButtonScrollAmount() const - { - return mDownButtonScrollAmount; - } - - void ScrollArea::setOpaque(bool opaque) - { - mOpaque = opaque; - } - - bool ScrollArea::isOpaque() const - { - return mOpaque; - } -} // namespace gcn diff --git a/src/gui/base/widgets/scrollarea.hpp b/src/gui/base/widgets/scrollarea.hpp deleted file mode 100644 index 879792019..000000000 --- a/src/gui/base/widgets/scrollarea.hpp +++ /dev/null @@ -1,549 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_SCROLLAREA_HPP -#define GCN_SCROLLAREA_HPP - -#include "gui/base/basiccontainer.hpp" -#include "listeners/mouselistener.h" - -namespace gcn -{ - /** - * Implementation if a scrollable area used to view widgets larger than the scroll area. - * A scroll area can be customized to always show scroll bars or to show them only when - * necessary. - */ - class ScrollArea: - public BasicContainer, - public MouseListener - { - public: - /** - * Scrollpolicies for the horizontal and vertical scrollbar. - * The policies are: - * - * SHOW_ALWAYS - Always show the scrollbars no matter what. - * SHOW_NEVER - Never show the scrollbars no matter waht. - * SHOW_AUTO - Show the scrollbars only when needed. That is if the - * content grows larger then the ScrollArea. - */ - enum ScrollPolicy - { - SHOW_ALWAYS = 0, - SHOW_NEVER, - SHOW_AUTO - }; - - /** - * Constructor. - */ - explicit ScrollArea(const Widget2 *const widget); - - /** - * Constructor. - * - * @param content The content of the scroll area. - */ - ScrollArea(const Widget2 *const widget, - Widget *const content); - - /** - * Constructor. - * - * @param content The content of the scroll area. - * @param hPolicy The policy for the horizontal scrollbar. See enum with - * policies. - * @param vPolicy The policy for the vertical scrollbar. See enum with - * policies. - */ - ScrollArea(const Widget2 *const widget, - Widget *content, - ScrollPolicy hPolicy, - ScrollPolicy vPolicy); - - A_DELETE_COPY(ScrollArea) - - /** - * Destructor. - */ - virtual ~ScrollArea(); - - /** - * Sets the content. - * - * @param widget The content of the scroll area. - */ - void setContent(Widget* widget); - - /** - * Gets the content. - * - * @return The content of the scroll area. - */ - Widget* getContent(); - - /** - * Sets the horizontal scrollbar policy. See enum with policies. - * - * @param hPolicy The policy for the horizontal scrollbar. - * @see getHorizontalScrollPolicy - */ - void setHorizontalScrollPolicy(ScrollPolicy hPolicy); - - /** - * Gets the horizontal scrollbar policy. See enum with policies. - * - * @return The policy for the horizontal scrollbar policy. - * @see setHorizontalScrollPolicy, setScrollPolicy - */ - ScrollPolicy getHorizontalScrollPolicy() const; - - /** - * Sets the vertical scrollbar policy. See enum with policies. - * - * @param vPolicy The policy for the vertical scrollbar. - * @see getVerticalScrollPolicy - */ - void setVerticalScrollPolicy(ScrollPolicy vPolicy); - - /** - * Gets the vertical scrollbar policy. See enum with policies. - * - * @return The policy for the vertical scrollbar. - * @see setVerticalScrollPolicy, setScrollPolicy - */ - ScrollPolicy getVerticalScrollPolicy() const; - - /** - * Sets the horizontal and vertical scrollbar policy. - * - * @param hPolicy The policy for the horizontal scrollbar. - * @param vPolicy The policy for the vertical scrollbar. - * @see getVerticalScrollPolicy, getHorizontalScrollPolicy - */ - void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy); - - /** - * Sets the amount to scroll vertically. - * - * @param vScroll The amount to scroll. - * @see getVerticalScrollAmount - */ - void setVerticalScrollAmount(int vScroll); - - /** - * Gets the amount that is scrolled vertically. - * - * @return The scroll amount on vertical scroll. - * @see setVerticalScrollAmount, setScrollAmount - */ - int getVerticalScrollAmount() const; - - /** - * Sets the amount to scroll horizontally. - * - * @param hScroll The amount to scroll. - * @see getHorizontalScrollAmount - */ - void setHorizontalScrollAmount(int hScroll); - - /** - * Gets the amount that is scrolled horizontally. - * - * @return The scroll amount on horizontal scroll. - * @see setHorizontalScrollAmount, setScrollAmount - */ - int getHorizontalScrollAmount() const; - - /** - * Sets the amount to scroll horizontally and vertically. - * - * @param hScroll The amount to scroll on horizontal scroll. - * @param vScroll The amount to scroll on vertical scroll. - * @see getHorizontalScrollAmount, getVerticalScrollAmount - */ - void setScrollAmount(int hScroll, int vScroll); - - /** - * Gets the maximum amount of horizontal scroll. - * - * @return The horizontal max scroll. - */ - int getHorizontalMaxScroll(); - - /** - * Gets the maximum amount of vertical scroll. - * - * @return The vertical max scroll. - */ - int getVerticalMaxScroll(); - - /** - * Sets the width of the scroll bars. - * - * @param width The width of the scroll bars. - * @see getScrollbarWidth - */ - void setScrollbarWidth(int width); - - /** - * Gets the width of the scroll bars. - * - * @return the width of the ScrollBar. - * @see setScrollbarWidth - */ - int getScrollbarWidth() const; - - /** - * Sets the amount to scroll in pixels when the left scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getLeftButtonScrollAmount - */ - void setLeftButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the right scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getRightButtonScrollAmount - */ - void setRightButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the up scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getUpButtonScrollAmount - */ - void setUpButtonScrollAmount(int amount); - - /** - * Sets the amount to scroll in pixels when the down scroll button is - * pushed. - * - * @param amount The amount to scroll in pixels. - * @see getDownButtonScrollAmount - */ - void setDownButtonScrollAmount(int amount); - - /** - * Gets the amount to scroll in pixels when the left scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setLeftButtonScrollAmount - */ - int getLeftButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the right scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setRightButtonScrollAmount - */ - int getRightButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the up scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setUpButtonScrollAmount - */ - int getUpButtonScrollAmount() const; - - /** - * Gets the amount to scroll in pixels when the down scroll button is - * pushed. - * - * @return The amount to scroll in pixels. - * @see setDownButtonScrollAmount - */ - int getDownButtonScrollAmount() const; - - /** - * Sets the scroll area to be opaque, that is sets the scoll area - * to display its background. - * - * @param opaque True if the scoll area should be opaque, false otherwise. - */ - void setOpaque(bool opaque); - - /** - * Checks if the scroll area is opaque, that is if the scroll area - * displays its background. - * - * @return True if the scroll area is opaque, false otherwise. - */ - bool isOpaque() const; - - // Inherited from BasicContainer - - virtual void showWidgetPart(Widget* widget, Rect area); - - virtual Rect getChildrenArea(); - - virtual Widget *getWidgetAt(int x, int y); - - - // Inherited from Widget - - virtual void draw(Graphics *graphics); - - virtual void logic(); - - void setWidth(int width); - - void setHeight(int height); - - void setDimension(const Rect& dimension); - - - // Inherited from MouseListener - - virtual void mouseReleased(MouseEvent& mouseEvent) override; - - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) override; - - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) override; - - protected: - /** - * Draws the background of the scroll area, that is - * the area behind the content. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawBackground(Graphics *graphics); - - /** - * Draws the up button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawUpButton(Graphics *graphics); - - /** - * Draws the down button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawDownButton(Graphics *graphics); - - /** - * Draws the left button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawLeftButton(Graphics *graphics); - - /** - * Draws the right button. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawRightButton(Graphics *graphics); - - /** - * Draws the vertical scroll bar. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawVBar(Graphics* graphics); - - /** - * Draws the horizontal scroll bar. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawHBar(Graphics* graphics); - - /** - * Draws the vertical marker. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawVMarker(Graphics* graphics); - - /** - * Draws the horizontal marker. - * - * @param graphics a Graphics object to draw with. - */ - virtual void drawHMarker(Graphics* graphics); - - /** - * Checks the policies for the scroll bars. - */ - virtual void checkPolicies(); - - /** - * Holds the vertical scroll amount. - */ - int mVScroll; - - /** - * Holds the horizontal scroll amount. - */ - int mHScroll; - - /** - * Holds the width of the scroll bars. - */ - int mScrollbarWidth; - - /** - * Holds the horizontal scroll bar policy. - */ - ScrollPolicy mHPolicy; - - /** - * Holds the vertical scroll bar policy. - */ - ScrollPolicy mVPolicy; - - /** - * True if the vertical scroll bar is visible, false otherwise. - */ - bool mVBarVisible; - - /** - * True if the horizontal scroll bar is visible, false otherwise. - */ - bool mHBarVisible; - - /** - * True if the up button is pressed, false otherwise. - */ - bool mUpButtonPressed; - - /** - * True if the down button is pressed, false otherwise. - */ - bool mDownButtonPressed; - - /** - * True if the left button is pressed, false otherwise. - */ - bool mLeftButtonPressed; - - /** - * True if the right button is pressed, false otherwise. - */ - bool mRightButtonPressed; - - /** - * Holds the up button scroll amount. - */ - int mUpButtonScrollAmount; - - /** - * Holds the down button scroll amount. - */ - int mDownButtonScrollAmount; - - /** - * Holds the left button scroll amount. - */ - int mLeftButtonScrollAmount; - - /** - * Holds the right button scroll amount. - */ - int mRightButtonScrollAmount; - - /** - * True if the vertical marked is dragged. - */ - bool mIsVerticalMarkerDragged; - - /** - * True if the horizontal marked is dragged. - */ - bool mIsHorizontalMarkerDragged; - - /** - * Holds the horizontal markers drag offset. - */ - int mHorizontalMarkerDragOffset; - - /** - * Holds the vertical markers drag offset. - */ - int mVerticalMarkerDragOffset; - - /** - * True if the scroll area should be opaque (that is - * display its background), false otherwise. - */ - bool mOpaque; - }; -} // namespace gcn - -#endif // end GCN_SCROLLAREA_HPP diff --git a/src/gui/base/widgets/slider.cpp b/src/gui/base/widgets/slider.cpp deleted file mode 100644 index 40c73ceb5..000000000 --- a/src/gui/base/widgets/slider.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/slider.hpp" - -#include "debug.h" - -namespace gcn -{ - Slider::Slider(const Widget2 *const widget, - const double scaleEnd) : - Widget(widget), - MouseListener(), - KeyListener(), - mDragged(false), - mValue(0), - mStepLength(scaleEnd / 10), - mMarkerLength(10), - mScaleStart(0), - mScaleEnd(scaleEnd), - mOrientation(HORIZONTAL) - { - setFocusable(true); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - } - - Slider::Slider(const Widget2 *const widget, - const double scaleStart, - const double scaleEnd) : - Widget(widget), - MouseListener(), - KeyListener(), - mDragged(false), - mValue(scaleStart), - mStepLength((scaleEnd - scaleStart) / 10), - mMarkerLength(10), - mScaleStart(scaleStart), - mScaleEnd(scaleEnd), - mOrientation(HORIZONTAL) - { - setFocusable(true); - setFrameSize(1); - - addMouseListener(this); - addKeyListener(this); - } - - void Slider::setScale(double scaleStart, double scaleEnd) - { - mScaleStart = scaleStart; - mScaleEnd = scaleEnd; - } - - double Slider::getScaleStart() const - { - return mScaleStart; - } - - void Slider::setScaleStart(double scaleStart) - { - mScaleStart = scaleStart; - } - - double Slider::getScaleEnd() const - { - return mScaleEnd; - } - - void Slider::setScaleEnd(double scaleEnd) - { - mScaleEnd = scaleEnd; - } - - void Slider::setValue(double value) - { - if (value > getScaleEnd()) - { - mValue = getScaleEnd(); - return; - } - - if (value < getScaleStart()) - { - mValue = getScaleStart(); - return; - } - - mValue = value; - } - - double Slider::getValue() const - { - return mValue; - } - - int Slider::getMarkerLength() const - { - return mMarkerLength; - } - - void Slider::setMarkerLength(int length) - { - mMarkerLength = length; - } - - void Slider::setOrientation(Slider::Orientation orientation) - { - mOrientation = orientation; - } - - Slider::Orientation Slider::getOrientation() const - { - return mOrientation; - } - - double Slider::markerPositionToValue(int v) const - { - int w; - if (getOrientation() == HORIZONTAL) - w = getWidth(); - else - w = getHeight(); - - const double pos = v / (static_cast<double>(w) - getMarkerLength()); - return (1.0 - pos) * getScaleStart() + pos * getScaleEnd(); - } - - int Slider::valueToMarkerPosition(double value) const - { - int v; - if (getOrientation() == HORIZONTAL) - v = getWidth(); - else - v = getHeight(); - - const int w = static_cast<int>((v - getMarkerLength()) - * (value - getScaleStart()) - / (getScaleEnd() - getScaleStart())); - - if (w < 0) - return 0; - - if (w > v - getMarkerLength()) - return v - getMarkerLength(); - - return w; - } - - void Slider::setStepLength(double length) - { - mStepLength = length; - } - - double Slider::getStepLength() const - { - return mStepLength; - } - - int Slider::getMarkerPosition() const - { - return valueToMarkerPosition(getValue()); - } -} // namespace gcn diff --git a/src/gui/base/widgets/slider.hpp b/src/gui/base/widgets/slider.hpp deleted file mode 100644 index 9d5adc6d8..000000000 --- a/src/gui/base/widgets/slider.hpp +++ /dev/null @@ -1,297 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_SLIDER_HPP -#define GCN_SLIDER_HPP - -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -#include "gui/widgets/widget.h" - -namespace gcn -{ - /** - * An implementation of a slider where a user can select different values by - * sliding between a start value and an end value of a scale. - * - * If the selected value is changed an action event will be sent to all - * action listeners of the slider. - */ - class Slider : - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Draw orientations for the slider. A slider can be drawn vertically or - * horizontally. - */ - enum Orientation - { - HORIZONTAL = 0, - VERTICAL - }; - - /** - * Constructor. The default start value of the slider scale is zero. - * - * @param scaleEnd The end value of the slider scale. - */ - explicit Slider(const Widget2 *const widget, - const double scaleEnd = 1.0); - - /** - * Constructor. - * - * @param scaleStart The start value of the slider scale. - * @param scaleEnd The end value of the slider scale. - */ - Slider(const Widget2 *const widget, - const double scaleStart, - const double scaleEnd); - - A_DELETE_COPY(Slider) - - /** - * Destructor. - */ - virtual ~Slider() - { } - - /** - * Sets the scale of the slider. - * - * @param scaleStart The start value of the scale. - * @param scaleEnd tThe end of value the scale. - * @see getScaleStart, getScaleEnd - */ - void setScale(double scaleStart, double scaleEnd); - - /** - * Gets the start value of the scale. - * - * @return The start value of the scale. - * @see setScaleStart, setScale - */ - double getScaleStart() const; - - /** - * Sets the start value of the scale. - * - * @param scaleStart The start value of the scale. - * @see getScaleStart - */ - void setScaleStart(double scaleStart); - - /** - * Gets the end value of the scale. - * - * @return The end value of the scale. - * @see setScaleEnd, setScale - */ - double getScaleEnd() const; - - /** - * Sets the end value of the scale. - * - * @param scaleEnd The end value of the scale. - * @see getScaleEnd - */ - void setScaleEnd(double scaleEnd); - - /** - * Gets the current selected value. - * - * @return The current selected value. - * @see setValue - */ - double getValue() const; - - /** - * Sets the current selected value. - * - * @param value The current selected value. - * @see getValue - */ - void setValue(double value); - - /** - * Sets the length of the marker. - * - * @param length The length for the marker. - * @see getMarkerLength - */ - void setMarkerLength(int length); - - /** - * Gets the length of the marker. - * - * @return The length of the marker. - * @see setMarkerLength - */ - int getMarkerLength() const; - - /** - * Sets the orientation of the slider. A slider can be drawn vertically - * or horizontally. - * - * @param orientation The orientation of the slider. - * @see getOrientation - */ - void setOrientation(Orientation orientation); - - /** - * Gets the orientation of the slider. A slider can be drawn vertically - * or horizontally. - * - * @return The orientation of the slider. - * @see setOrientation - */ - Orientation getOrientation() const; - - /** - * Sets the step length. The step length is used when the keys LEFT - * and RIGHT are pressed to step in the scale. - * - * @param length The step length. - * @see getStepLength - */ - void setStepLength(double length); - - /** - * Gets the step length. The step length is used when the keys LEFT - * and RIGHT are pressed to step in the scale. - * - * @return the step length. - * @see setStepLength - */ - double getStepLength() const; - - protected: - /** - * Converts a marker position to a value in the scale. - * - * @param position The position to convert. - * @return A scale value corresponding to the position. - * @see valueToMarkerPosition - */ - virtual double markerPositionToValue(int position) const; - - /** - * Converts a value to a marker position. - * - * @param value The value to convert. - * @return A marker position corresponding to the value. - * @see markerPositionToValue - */ - virtual int valueToMarkerPosition(double value) const; - - /** - * Gets the marker position of the current selected value. - * - * @return The marker position of the current selected value. - */ - virtual int getMarkerPosition() const; - - /** - * True if the slider is dragged, false otherwise. - */ - bool mDragged; - - /** - * Holds the current selected value. - */ - double mValue; - - /** - * Holds the step length. The step length is used when the keys LEFT - * and RIGHT are pressed to step in the scale. - */ - double mStepLength; - - /** - * Holds the length of the marker. - */ - int mMarkerLength; - - /** - * Holds the start value of the scale. - */ - double mScaleStart; - - /** - * Holds the end value of the scale. - */ - double mScaleEnd; - - /** - * Holds the orientation of the slider. A slider can be drawn - * vertically or horizontally. - */ - Orientation mOrientation; - }; -} // namespace gcn - -#endif // end GCN_SLIDER_HPP diff --git a/src/gui/base/widgets/textbox.cpp b/src/gui/base/widgets/textbox.cpp deleted file mode 100644 index f74db9a29..000000000 --- a/src/gui/base/widgets/textbox.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/textbox.hpp" - -#include "gui/font.h" - -#include "render/graphics.h" - -#include "debug.h" - -namespace gcn -{ - TextBox::TextBox(const Widget2 *const widget) : - Widget(widget), - MouseListener(), - KeyListener(), - mTextRows(), - mCaretColumn(0), - mCaretRow(0), - mEditable(true), - mOpaque(true) - { - setText(""); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - } - - TextBox::TextBox(const Widget2 *const widget, - const std::string& text) : - Widget(widget), - MouseListener(), - KeyListener(), - mTextRows(), - mCaretColumn(0), - mCaretRow(0), - mEditable(true), - mOpaque(true) - { - setText(text); - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - adjustSize(); - } - - void TextBox::setText(const std::string& text) - { - mCaretColumn = 0; - mCaretRow = 0; - - mTextRows.clear(); - - size_t pos, lastPos = 0; - int length; - do - { - pos = text.find("\n", lastPos); - - if (pos != std::string::npos) - length = static_cast<int>(pos - lastPos); - else - length = static_cast<int>(text.size() - lastPos); - std::string sub = text.substr(lastPos, length); - mTextRows.push_back(sub); - lastPos = pos + 1; - } while (pos != std::string::npos); - - adjustSize(); - } - -/* - void TextBox::draw(Graphics* graphics) - { - } -*/ - - void TextBox::drawCaret(Graphics* graphics, int x, int y) - { - graphics->setColor(mForegroundColor); - graphics->drawLine(x, getFont()->getHeight() + y, x, y); - } - - void TextBox::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - - const int sz = static_cast<int>(mTextRows.size()); - if (mCaretRow >= sz) - mCaretRow = sz - 1; - - mCaretColumn = getFont()->getStringIndexAt( - mTextRows[mCaretRow], mouseEvent.getX()); - } - } - - void TextBox::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextBox::keyPressed(KeyEvent& keyEvent A_UNUSED) - { - } - - void TextBox::adjustSize() - { - int width = 0; - for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i) - { - const int w = getFont()->getWidth(mTextRows[i]); - if (width < w) - width = w; - } - - setWidth(width + 1); - setHeight(static_cast<int>(getFont()->getHeight() * mTextRows.size())); - } - - void TextBox::setCaretPosition(unsigned int position) - { - for (int row = 0, sz = static_cast<int>(mTextRows.size()); - row < sz; row ++) - { - if (position <= mTextRows[row].size()) - { - mCaretRow = row; - mCaretColumn = position; - return; // we are done - } - else - { - position--; - } - } - - // position beyond end of text - mCaretRow = static_cast<int>(mTextRows.size() - 1); - mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size()); - } - - unsigned int TextBox::getCaretPosition() const - { - int pos = 0, row; - - for (row = 0; row < mCaretRow; row++) - pos += static_cast<int>(mTextRows[row].size()); - - return pos + mCaretColumn; - } - - void TextBox::setCaretRowColumn(int row, int column) - { - setCaretRow(row); - setCaretColumn(column); - } - - void TextBox::setCaretRow(int row) - { - mCaretRow = row; - - const int sz = static_cast<int>(mTextRows.size()); - if (mCaretRow >= sz) - mCaretRow = sz - 1; - - if (mCaretRow < 0) - mCaretRow = 0; - - setCaretColumn(mCaretColumn); - } - - unsigned int TextBox::getCaretRow() const - { - return mCaretRow; - } - - void TextBox::setCaretColumn(int column) - { - mCaretColumn = column; - - const int sz = static_cast<int>(mTextRows[mCaretRow].size()); - if (mCaretColumn > sz) - mCaretColumn = sz; - - if (mCaretColumn < 0) - mCaretColumn = 0; - } - - unsigned int TextBox::getCaretColumn() const - { - return mCaretColumn; - } - - const std::string& TextBox::getTextRow(int row) const - { - return mTextRows[row]; - } - - void TextBox::setTextRow(int row, const std::string& text) - { - mTextRows[row] = text; - - if (mCaretRow == row) - setCaretColumn(mCaretColumn); - - adjustSize(); - } - - unsigned int TextBox::getNumberOfRows() const - { - return static_cast<int>(mTextRows.size()); - } - - std::string TextBox::getText() const - { - if (mTextRows.empty()) - return std::string(""); - - int i; - std::string text; - - const int sz = static_cast<int>(mTextRows.size()); - for (i = 0; i < sz - 1; ++ i) - text.append(mTextRows[i]).append("\n"); - text.append(mTextRows[i]); - - return text; - } - - void TextBox::fontChanged() - { - adjustSize(); - } - - void TextBox::scrollToCaret() - { - Rect scroll; - scroll.x = getFont()->getWidth( - mTextRows[mCaretRow].substr(0, mCaretColumn)); - scroll.y = getFont()->getHeight() * mCaretRow; - scroll.width = getFont()->getWidth(" "); - - // add 2 for some extra space - scroll.height = getFont()->getHeight() + 2; - - showPart(scroll); - } - - void TextBox::setEditable(bool editable) - { - mEditable = editable; - } - - bool TextBox::isEditable() const - { - return mEditable; - } - - void TextBox::addRow(const std::string &row) - { - mTextRows.push_back(row); - adjustSize(); - } - - bool TextBox::isOpaque() - { - return mOpaque; - } - - void TextBox::setOpaque(bool opaque) - { - mOpaque = opaque; - } -} // namespace gcn diff --git a/src/gui/base/widgets/textbox.hpp b/src/gui/base/widgets/textbox.hpp deleted file mode 100644 index 148b4f007..000000000 --- a/src/gui/base/widgets/textbox.hpp +++ /dev/null @@ -1,311 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_TEXTBOX_HPP -#define GCN_TEXTBOX_HPP - -#include <string> -#include <vector> - -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -#include "gui/widgets/widget.h" - -namespace gcn -{ - /** - * An implementation of a text box where a user can enter text that contains of many lines. - */ - class TextBox: - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - explicit TextBox(const Widget2 *const widget); - - /** - * Constructor. - * - * @param text The default text of the text box. - */ - TextBox(const Widget2 *const widget, - const std::string& text); - - A_DELETE_COPY(TextBox) - - /** - * Sets the text of the text box. - * - * @param text The text of the text box. - * @see getText - */ - void setText(const std::string& text); - - /** - * Gets the text of the text box. - * - * @return The text of the text box. - * @see setText - */ - std::string getText() const; - - /** - * Gets a certain row from the text. - * - * @param row The number of the row to get from the text. - * @return A row from the text of the text box. - * @see setTextRow - */ - const std::string& getTextRow(int row) const; - - /** - * Sets the text of a certain row of the text. - * - * @param row The number of the row to set in the text. - * @param text The text to set in the given row number. - * @see getTextRow - */ - void setTextRow(int row, const std::string& text); - - /** - * Gets the number of rows in the text. - * - * @return The number of rows in the text. - */ - unsigned int getNumberOfRows() const; - - /** - * Gets the caret position in the text. - * - * @return The caret position in the text. - * @see setCaretPosition - */ - unsigned int getCaretPosition() const; - - /** - * Sets the position of the caret in the text. - * - * @param position the positon of the caret. - * @see getCaretPosition - */ - void setCaretPosition(unsigned int position); - - /** - * Gets the row number where the caret is currently located. - * - * @return The row number where the caret is currently located. - * @see setCaretRow - */ - unsigned int getCaretRow() const; - - /** - * Sets the row where the caret should be currently located. - * - * @param The row where the caret should be currently located. - * @see getCaretRow - */ - void setCaretRow(int row); - - /** - * Gets the column where the caret is currently located. - * - * @return The column where the caret is currently located. - * @see setCaretColumn - */ - unsigned int getCaretColumn() const; - - /** - * Sets the column where the caret should be currently located. - * - * @param The column where the caret should be currently located. - * @see getCaretColumn - */ - void setCaretColumn(int column); - - /** - * Sets the row and the column where the caret should be curretly - * located. - * - * @param row The row where the caret should be currently located. - * @param column The column where the caret should be currently located. - * @see getCaretRow, getCaretColumn - */ - void setCaretRowColumn(int row, int column); - - /** - * Scrolls the text to the caret if the text box is in a scroll area. - * - * @see ScrollArea - */ - virtual void scrollToCaret(); - - /** - * Checks if the text box is editable. - * - * @return True it the text box is editable, false otherwise. - * @see setEditable - */ - bool isEditable() const; - - /** - * Sets the text box to be editable or not. - * - * @param editable True if the text box should be editable, false otherwise. - */ - void setEditable(bool editable); - - /** - * Adds a row of text to the end of the text. - * - * @param row The row to add. - */ - virtual void addRow(const std::string &row); - - /** - * Checks if the text box is opaque. An opaque text box will draw - * it's background and it's text. A non opaque text box only draw it's - * text making it transparent. - * - * @return True if the text box is opaque, false otherwise. - * @see setOpaque - */ - bool isOpaque(); - - /** - * Sets the text box to be opaque or not. An opaque text box will draw - * it's background and it's text. A non opaque text box only draw it's - * text making it transparent. - * - * @param opaque True if the text box should be opaque, false otherwise. - * @see isOpaque - */ - void setOpaque(bool opaque); - - - // Inherited from Widget - -// virtual void draw(Graphics* graphics); - - virtual void fontChanged(); - - - // Inherited from KeyListener - - virtual void keyPressed(KeyEvent& keyEvent) override; - - - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent) override; - - virtual void mouseDragged(MouseEvent& mouseEvent) override; - - protected: - /** - * Draws the caret. Overloaded this method if you want to - * change the style of the caret. - * - * @param graphics a Graphics object to draw with. - * @param x the x position. - * @param y the y position. - */ - virtual void drawCaret(Graphics* graphics, int x, int y); - - /** - * Adjusts the text box's size to fit the text. - */ - virtual void adjustSize(); - - /** - * Holds all the rows of the text. - */ - std::vector<std::string> mTextRows; - - /** - * Holds the current column of the caret. - */ - int mCaretColumn; - - /** - * Holds the current row of the caret. - */ - int mCaretRow; - - /** - * True if the text box is editable, false otherwise. - */ - bool mEditable; - - /** - * True if the text box is editable, false otherwise. - */ - bool mOpaque; - }; -} // namespace gcn - -#endif // end GCN_TEXTBOX_HPP diff --git a/src/gui/base/widgets/textfield.cpp b/src/gui/base/widgets/textfield.cpp deleted file mode 100644 index c2cead500..000000000 --- a/src/gui/base/widgets/textfield.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * For comments regarding functions please see the header file. - */ - -#include "gui/base/widgets/textfield.hpp" - -#include "gui/font.h" - -#include "debug.h" - -namespace gcn -{ - TextField::TextField(const Widget2 *const widget) : - Widget(widget), - MouseListener(), - KeyListener(), - mText(), - mCaretPosition(0), - mXScroll(0) - { - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - TextField::TextField(const Widget2 *const widget, - const std::string& text) : - Widget(widget), - MouseListener(), - KeyListener(), - mText(text), - mCaretPosition(0), - mXScroll(0) - { - adjustSize(); - - setFocusable(true); - - addMouseListener(this); - addKeyListener(this); - } - - void TextField::setText(const std::string& text) - { - const size_t sz = text.size(); - if (sz < mCaretPosition) - mCaretPosition = sz; - mText = text; - } - - void TextField::drawCaret(Graphics* graphics A_UNUSED, int x A_UNUSED) - { - } - - void TextField::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == MouseEvent::LEFT) - { - mCaretPosition = getFont()->getStringIndexAt( - mText, mouseEvent.getX() + mXScroll); - fixScroll(); - } - } - - void TextField::mouseDragged(MouseEvent& mouseEvent) - { - mouseEvent.consume(); - } - - void TextField::adjustSize() - { - } - - void TextField::adjustHeight() - { - } - - void TextField::fixScroll() - { - } - - void TextField::setCaretPosition(unsigned int position A_UNUSED) - { - } - - unsigned int TextField::getCaretPosition() const - { - return mCaretPosition; - } - - const std::string& TextField::getText() const - { - return mText; - } - - void TextField::fontChanged() - { - } -} // namespace gcn diff --git a/src/gui/base/widgets/textfield.hpp b/src/gui/base/widgets/textfield.hpp deleted file mode 100644 index e9df238ba..000000000 --- a/src/gui/base/widgets/textfield.hpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* _______ __ __ __ ______ __ __ _______ __ __ - * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ - * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / - * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / - * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / - * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / - * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ - * - * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson - * - * - * Per Larsson a.k.a finalman - * Olof Naessén a.k.a jansem/yakslem - * - * Visit: http://guichan.sourceforge.net - * - * License: (BSD) - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name of Guichan nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GCN_TEXTFIELD_HPP -#define GCN_TEXTFIELD_HPP - -#include "listeners/keylistener.h" -#include "listeners/mouselistener.h" - -#include "gui/widgets/widget.h" - -#include <string> - -namespace gcn -{ - /** - * An implementation of a text field where a user can enter a line of text. - */ - class TextField: - public Widget, - public MouseListener, - public KeyListener - { - public: - /** - * Constructor. - */ - explicit TextField(const Widget2 *const widget); - - /** - * Constructor. The text field will be automatically resized - * to fit the text. - * - * @param text The default text of the text field. - */ - TextField(const Widget2 *const widget, - const std::string& text); - - A_DELETE_COPY(TextField) - - /** - * Sets the text of the text field. - * - * @param text The text of the text field. - * @see getText - */ - void setText(const std::string& text); - - /** - * Gets the text of the text field. - * - * @return The text of the text field. - * @see setText - */ - const std::string& getText() const; - - /** - * Adjusts the size of the text field to fit the text. - */ - void adjustSize(); - - /** - * Adjusts the height of the text field to fit caption. - */ - void adjustHeight(); - - /** - * Sets the caret position. As there is only one line of text - * in a text field the position is the caret's x coordinate. - * - * @param position The caret position. - * @see getCaretPosition - */ - void setCaretPosition(unsigned int position); - - /** - * Gets the caret position. As there is only one line of text - * in a text field the position is the caret's x coordinate. - * - * @return The caret position. - * @see setCaretPosition - */ - unsigned int getCaretPosition() const; - - - // Inherited from Widget - - virtual void fontChanged(); - - // Inherited from MouseListener - - virtual void mousePressed(MouseEvent& mouseEvent) override; - - virtual void mouseDragged(MouseEvent& mouseEvent) override; - - protected: - /** - * Draws the caret. Overloaded this method if you want to - * change the style of the caret. - * - * @param graphics the Graphics object to draw with. - * @param x the caret's x-position. - */ - virtual void drawCaret(Graphics* graphics, int x); - - /** - * Scrolls the text horizontally so that the caret shows if needed. - * The method is used any time a user types in the text field so the - * caret always will be shown. - */ - void fixScroll(); - - /** - * Holds the text of the text box. - */ - std::string mText; - - /** - * Holds the caret position. - */ - unsigned int mCaretPosition; - - /** - * Holds the amount scrolled in x. If a user types more characters than - * the text field can display, due to the text field being to small, the - * text needs to scroll in order to show the last type character. - */ - int mXScroll; - }; -} // namespace gcn - -#endif // end GCN_TEXTFIELD_HPP diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 5914e43d9..deed890ae 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -20,6 +20,49 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/gui.h" #include "gui/focushandler.h" @@ -29,8 +72,6 @@ #include "gui/theme.h" #include "gui/viewport.h" -#include "events/mouseevent.h" - #include "gui/widgets/window.h" #include "client.h" @@ -41,7 +82,10 @@ #include "events/keyevent.h" #include "listeners/focuslistener.h" +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" +#include "input/inputmanager.h" #include "input/keydata.h" #include "input/keyinput.h" #include "input/mouseinput.h" @@ -91,7 +135,18 @@ class GuiConfigListener final : public ConfigListener }; Gui::Gui() : - gcn::Gui(), + mTop(nullptr), + mGraphics(nullptr), + mInput(nullptr), + mFocusHandler(new FocusHandler), + mKeyListeners(), + mLastMousePressButton(0), + mLastMousePressTimeStamp(0), + mLastMouseX(0), + mLastMouseY(0), + mClickCount(1), + mLastMouseDragButton(0), + mWidgetWithMouseQueue(), mConfigListener(new GuiConfigListener(this)), mGuiFont(), mInfoParticleFont(), @@ -262,6 +317,12 @@ Gui::~Gui() guiInput = nullptr; Theme::deleteInstance(); + + if (Widget::widgetExists(mTop)) + setTop(nullptr); + + delete mFocusHandler; + mFocusHandler = nullptr; } void Gui::logic() @@ -345,32 +406,25 @@ void Gui::clearFonts() bool Gui::handleInput() { if (mInput) - return handleKeyInput2(); + return handleKeyInput(); else return false; } -bool Gui::handleKeyInput2() +bool Gui::handleKeyInput() { if (!guiInput) return false; - BLOCK_START("Gui::handleKeyInput2") + BLOCK_START("Gui::handleKeyInput") bool consumed(false); while (!mInput->isKeyQueueEmpty()) { - const KeyInput keyInput = guiInput->dequeueKeyInput2(); - - // Save modifiers state - mShiftPressed = keyInput.isShiftPressed(); - mMetaPressed = keyInput.isMetaPressed(); - mControlPressed = keyInput.isControlPressed(); - mAltPressed = keyInput.isAltPressed(); + const KeyInput keyInput = guiInput->dequeueKeyInput(); KeyEvent keyEventToGlobalKeyListeners(nullptr, - mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, - keyInput.getType(), keyInput.isNumericPad(), + keyInput.getType(), keyInput.getActionId(), keyInput.getKey()); #ifdef USE_SDL2 @@ -397,8 +451,7 @@ bool Gui::handleKeyInput2() if (mFocusHandler->getFocused()) { KeyEvent keyEvent(getKeyEventSource(), - mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, - keyInput.getType(), keyInput.isNumericPad(), + keyInput.getType(), keyInput.getActionId(), keyInput.getKey()); #ifdef USE_SDL2 if (!keyInput.getText().empty()) @@ -418,18 +471,18 @@ bool Gui::handleKeyInput2() // If the key event hasn't been consumed and // tabbing is enable check for tab press and // change focus. - if (!keyEventConsumed && mTabbing && keyInput.getActionId() + if (!keyEventConsumed && keyInput.getActionId() == static_cast<int>(Input::KEY_GUI_TAB) && keyInput.getType() == KeyInput::PRESSED) { - if (keyInput.isShiftPressed()) + if (inputManager.isActionActive(Input::KEY_GUI_MOD)) mFocusHandler->tabPrevious(); else mFocusHandler->tabNext(); } } } // end while - BLOCK_END("Gui::handleKeyInput2") + BLOCK_END("Gui::handleKeyInput") return consumed; } @@ -527,7 +580,171 @@ void Gui::setUseCustomCursor(const bool customCursor) void Gui::handleMouseMoved(const MouseInput &mouseInput) { - gcn::Gui::handleMouseMoved(mouseInput); + // Check if the mouse leaves the application window. + if (!mWidgetWithMouseQueue.empty() && (mouseInput.getX() < 0 + || mouseInput.getY() < 0 || !mTop->getDimension().isPointInRect( + mouseInput.getX(), mouseInput.getY()))) + { + // Distribute an event to all widgets in the + // "widget with mouse" queue. + while (!mWidgetWithMouseQueue.empty()) + { + Widget *const widget = mWidgetWithMouseQueue.front(); + + if (Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::EXITED, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY(), + true, + true); + } + + mWidgetWithMouseQueue.pop_front(); + } + + mMouseInactivityTimer = 0; + return; + } + + // Check if there is a need to send mouse exited events by + // traversing the "widget with mouse" queue. + bool widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty(); + while (!widgetWithMouseQueueCheckDone) + { + unsigned int iterations = 0; + for (std::deque<Widget*>::iterator + iter = mWidgetWithMouseQueue.begin(); + iter != mWidgetWithMouseQueue.end(); + ++ iter) + { + Widget *const widget = *iter; + + // If a widget in the "widget with mouse queue" doesn't + // exists anymore it should be removed from the queue. + if (!Widget::widgetExists(widget)) + { + mWidgetWithMouseQueue.erase(iter); + break; + } + else + { + int x, y; + widget->getAbsolutePosition(x, y); + + if (x > mouseInput.getX() + || y > mouseInput.getY() + || x + widget->getWidth() <= mouseInput.getX() + || y + widget->getHeight() <= mouseInput.getY() + || !widget->isVisible()) + { + distributeMouseEvent(widget, + MouseEvent::EXITED, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY(), + true, + true); + mClickCount = 1; + mLastMousePressTimeStamp = 0; + mWidgetWithMouseQueue.erase(iter); + break; + } + } + + iterations++; + } + + widgetWithMouseQueueCheckDone = + (iterations == mWidgetWithMouseQueue.size()); + } + + // Check all widgets below the mouse to see if they are + // present in the "widget with mouse" queue. If a widget + // is not then it should be added and an entered event should + // be sent to it. + Widget* parent = getMouseEventSource( + mouseInput.getX(), mouseInput.getY()); + Widget* widget = parent; + + // If a widget has modal mouse input focus then it will + // always be returned from getMouseEventSource, but we only wan't to + // send mouse entered events if the mouse has actually entered the + // widget with modal mouse input focus, hence we need to check if + // that's the case. If it's not we should simply ignore to send any + // mouse entered events. + if (mFocusHandler->getModalMouseInputFocused() + && widget == mFocusHandler->getModalMouseInputFocused() + && Widget::widgetExists(widget)) + { + int x, y; + widget->getAbsolutePosition(x, y); + + if (x > mouseInput.getX() || y > mouseInput.getY() + || x + widget->getWidth() <= mouseInput.getX() + || y + widget->getHeight() <= mouseInput.getY()) + { + parent = nullptr; + } + } + + while (parent) + { + parent = widget->getParent(); + + // Check if the widget is present in the "widget with mouse" queue. + bool widgetIsPresentInQueue = false; + FOR_EACH (std::deque<Widget*>::const_iterator, + iter, mWidgetWithMouseQueue) + { + if (*iter == widget) + { + widgetIsPresentInQueue = true; + break; + } + } + + // Widget is not present, send an entered event and add + // it to the "widget with mouse" queue. + if (!widgetIsPresentInQueue + && Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::ENTERED, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY(), + true, + true); + mWidgetWithMouseQueue.push_front(widget); + } + + const Widget *const swap = widget; + widget = parent; + parent = swap->getParent(); + } + + if (mFocusHandler->getDraggedWidget()) + { + distributeMouseEvent(mFocusHandler->getDraggedWidget(), + MouseEvent::DRAGGED, + mLastMouseDragButton, + mouseInput.getX(), + mouseInput.getY()); + } + else + { + Widget *const sourceWidget = getMouseEventSource( + mouseInput.getX(), mouseInput.getY()); + + distributeMouseEvent(sourceWidget, + MouseEvent::MOVED, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY()); + } mMouseInactivityTimer = 0; } @@ -622,8 +839,8 @@ void Gui::distributeMouseEvent(Widget* source, int type, int button, return; } - MouseEvent mouseEvent(source, mShiftPressed, mControlPressed, - mAltPressed, mMetaPressed, type, button, + MouseEvent mouseEvent(source, + type, button, x, y, mClickCount); Widget* parent = source; @@ -735,8 +952,8 @@ MouseEvent *Gui::createMouseEvent(Window *const widget) getAbsolutePosition(widget, x, y); getMouseState(&mouseX, &mouseY); - return new MouseEvent(widget, mShiftPressed, - mControlPressed, mAltPressed, mMetaPressed, 0, 0, + return new MouseEvent(widget, + 0, 0, mouseX - x, mouseY - y, mClickCount); } @@ -758,7 +975,7 @@ void Gui::handleMouseInput() BLOCK_START("Gui::handleMouseInput") while (!mInput->isMouseQueueEmpty()) { - const MouseInput mouseInput = guiInput->dequeueMouseInput2(); + const MouseInput mouseInput = guiInput->dequeueMouseInput(); if (touchManager.processEvent(mouseInput)) { @@ -893,3 +1110,339 @@ uint32_t Gui::getMouseState(int *const x, int *const y) (*y) /= scale; return res; } + +void Gui::setTop(Widget *const top) +{ + if (mTop) + mTop->_setFocusHandler(nullptr); + if (top) + top->_setFocusHandler(mFocusHandler); + + mTop = top; +} + +void Gui::setGraphics(Graphics *const graphics) +{ + mGraphics = graphics; +} + +Graphics* Gui::getGraphics() const +{ + return mGraphics; +} + +void Gui::setInput(SDLInput *const input) +{ + mInput = input; +} + +SDLInput* Gui::getInput() const +{ + return mInput; +} + +void Gui::addGlobalKeyListener(KeyListener *const keyListener) +{ + mKeyListeners.push_back(keyListener); +} + +void Gui::removeGlobalKeyListener(KeyListener *const keyListener) +{ + mKeyListeners.remove(keyListener); +} + +void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput) +{ + Widget* sourceWidget = getMouseEventSource( + mouseInput.getX(), mouseInput.getY()); + + if (mFocusHandler->getDraggedWidget()) + sourceWidget = mFocusHandler->getDraggedWidget(); + + int sourceWidgetX = 0; + int sourceWidgetY = 0; + sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); + + distributeMouseEvent(sourceWidget, + MouseEvent::WHEEL_MOVED_DOWN, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY()); +} + +void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput) +{ + Widget* sourceWidget = getMouseEventSource( + mouseInput.getX(), mouseInput.getY()); + + if (mFocusHandler->getDraggedWidget()) + sourceWidget = mFocusHandler->getDraggedWidget(); + + int sourceWidgetX, sourceWidgetY; + sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); + + distributeMouseEvent(sourceWidget, + MouseEvent::WHEEL_MOVED_UP, + mouseInput.getButton(), + mouseInput.getX(), + mouseInput.getY()); +} + +Widget* Gui::getWidgetAt(int x, int y) +{ + // If the widget's parent has no child then we have found the widget.. + Widget* parent = mTop; + Widget* child = mTop; + + while (child) + { + Widget *const swap = child; + int parentX, parentY; + parent->getAbsolutePosition(parentX, parentY); + child = parent->getWidgetAt(x - parentX, y - parentY); + parent = swap; + } + + return parent; +} + +Widget* Gui::getMouseEventSource(int x, int y) +{ + Widget *const widget = getWidgetAt(x, y); + if (!widget) + return nullptr; + + if (mFocusHandler && mFocusHandler->getModalMouseInputFocused() + && !widget->isModalMouseInputFocused()) + { + return mFocusHandler->getModalMouseInputFocused(); + } + + return widget; +} + +Widget* Gui::getKeyEventSource() +{ + Widget* widget = mFocusHandler->getFocused(); + + while (widget && widget->_getInternalFocusHandler() + && widget->_getInternalFocusHandler()->getFocused()) + { + widget = widget->_getInternalFocusHandler()->getFocused(); + } + + return widget; +} + +void Gui::distributeKeyEvent(KeyEvent& keyEvent) const +{ + Widget* parent = keyEvent.getSource(); + Widget* widget = keyEvent.getSource(); + + if (mFocusHandler->getModalFocused() + && !widget->isModalFocused()) + { + return; + } + + if (mFocusHandler->getModalMouseInputFocused() + && !widget->isModalMouseInputFocused()) + { + return; + } + + while (parent) + { + // If the widget has been removed due to input + // cancel the distribution. + if (!Widget::widgetExists(widget)) + break; + + parent = widget->getParent(); + + if (widget->isEnabled()) + { + std::list<KeyListener*> keyListeners + = widget->_getKeyListeners(); + + // Send the event to all key listeners of the source widget. + for (std::list<KeyListener*>::const_iterator + it = keyListeners.begin(); + it != keyListeners.end(); + ++ it) + { + switch (keyEvent.getType()) + { + case KeyEvent::PRESSED: + (*it)->keyPressed(keyEvent); + break; + case KeyEvent::RELEASED: + (*it)->keyReleased(keyEvent); + break; + default: + break; + } + } + } + + const Widget *const swap = widget; + widget = parent; + parent = swap->getParent(); + + // If a non modal focused widget has been reach + // and we have modal focus cancel the distribution. + if (mFocusHandler->getModalFocused() + && !widget->isModalFocused()) + { + break; + } + } +} + +void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent) +{ + for (KeyListenerListIterator it = mKeyListeners.begin(); + it != mKeyListeners.end(); ++ it) + { + switch (keyEvent.getType()) + { + case KeyEvent::PRESSED: + (*it)->keyPressed(keyEvent); + break; + case KeyEvent::RELEASED: + (*it)->keyReleased(keyEvent); + break; + default: + break; + } + + if (keyEvent.isConsumed()) + break; + } +} + +void Gui::handleModalMouseInputFocus() +{ + BLOCK_START("Gui::handleModalMouseInputFocus") + // Check if modal mouse input focus has been gained by a widget. + if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() + != mFocusHandler->getModalMouseInputFocused()) + && (!mFocusHandler->getLastWidgetWithModalMouseInputFocus())) + { + handleModalFocusGained(); + mFocusHandler->setLastWidgetWithModalMouseInputFocus( + mFocusHandler->getModalMouseInputFocused()); + } + // Check if modal mouse input focus has been released. + else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus() + != mFocusHandler->getModalMouseInputFocused()) + && (mFocusHandler->getLastWidgetWithModalMouseInputFocus())) + { + handleModalFocusReleased(); + mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr); + } + BLOCK_END("Gui::handleModalMouseInputFocus") +} + +void Gui::handleModalFocus() +{ + BLOCK_START("Gui::handleModalFocus") + // Check if modal focus has been gained by a widget. + if ((mFocusHandler->getLastWidgetWithModalFocus() + != mFocusHandler->getModalFocused()) + && (!mFocusHandler->getLastWidgetWithModalFocus())) + { + handleModalFocusGained(); + mFocusHandler->setLastWidgetWithModalFocus( + mFocusHandler->getModalFocused()); + } + // Check if modal focus has been released. + else if ((mFocusHandler->getLastWidgetWithModalFocus() + != mFocusHandler->getModalFocused()) + && (mFocusHandler->getLastWidgetWithModalFocus())) + { + handleModalFocusReleased(); + mFocusHandler->setLastWidgetWithModalFocus(nullptr); + } + BLOCK_END("Gui::handleModalFocus") +} + +void Gui::handleModalFocusGained() +{ + // Distribute an event to all widgets in the "widget with mouse" queue. + while (!mWidgetWithMouseQueue.empty()) + { + Widget *const widget = mWidgetWithMouseQueue.front(); + + if (Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::EXITED, + mLastMousePressButton, + mLastMouseX, + mLastMouseY, + true, + true); + } + + mWidgetWithMouseQueue.pop_front(); + } + + mFocusHandler->setLastWidgetWithModalMouseInputFocus( + mFocusHandler->getModalMouseInputFocused()); +} + +void Gui::handleModalFocusReleased() +{ + // Check all widgets below the mouse to see if they are + // present in the "widget with mouse" queue. If a widget + // is not then it should be added and an entered event should + // be sent to it. + Widget* widget = getMouseEventSource(mLastMouseX, mLastMouseY); + Widget* parent = widget; + + while (parent) + { + parent = widget->getParent(); + + // Check if the widget is present in the "widget with mouse" queue. + bool widgetIsPresentInQueue = false; + FOR_EACH (std::deque<Widget*>::const_iterator, + iter, mWidgetWithMouseQueue) + { + if (*iter == widget) + { + widgetIsPresentInQueue = true; + break; + } + } + + // Widget is not present, send an entered event and add + // it to the "widget with mouse" queue. + if (!widgetIsPresentInQueue && Widget::widgetExists(widget)) + { + distributeMouseEvent(widget, + MouseEvent::ENTERED, + mLastMousePressButton, + mLastMouseX, + mLastMouseY, + false, + true); + mWidgetWithMouseQueue.push_front(widget); + } + + const Widget *const swap = widget; + widget = parent; + parent = swap->getParent(); + } +} + +int Gui::getMousePressLength() const +{ + if (!mLastMousePressTimeStamp) + return 0; + int ticks = SDL_GetTicks(); + if (ticks > mLastMousePressTimeStamp) + return ticks - mLastMousePressTimeStamp; + return mLastMousePressTimeStamp - ticks; +} diff --git a/src/gui/gui.h b/src/gui/gui.h index 4038bbec4..8805f2518 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -20,23 +20,72 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_GUI_H #define GUI_GUI_H #include "gui/color.h" -#include "gui/base/gui.hpp" +#include <deque> +#include <list> #include "localconsts.h" +class Event; +class FocusHandler; class FocusListener; class Graphics; class GuiConfigListener; class ImageSet; +class KeyEvent; +class KeyListener; class MouseEvent; class MouseInput; class Font; class SDLInput; +class Widget; class Window; /** @@ -52,7 +101,7 @@ class Window; * * \ingroup GUI */ -class Gui final : public gcn::Gui +class Gui final { public: /** @@ -142,7 +191,7 @@ class Gui final : public gcn::Gui bool handleInput(); - bool handleKeyInput2(); + bool handleKeyInput(); void resetClickCount(); @@ -168,6 +217,96 @@ class Gui final : public gcn::Gui static uint32_t getMouseState(int *const x, int *const y); + /** + * Sets the top widget. The top widget is the root widget + * of the GUI. If you want a GUI to be able to contain more + * than one widget the top widget should be a container. + * + * @param top The top widget. + * @see Container + * @since 0.1.0 + */ + void setTop(Widget *const top); + + /** + * Gets the top widget. The top widget is the root widget + * of the GUI. + * + * @return The top widget. NULL if no top widget has been set. + * @since 0.1.0 + */ + Widget* getTop() const A_WARN_UNUSED + { return mTop; } + + /** + * Sets the graphics object to use for drawing. + * + * @param graphics The graphics object to use for drawing. + * @see getGraphics, AllegroGraphics, HGEGraphics, + * OpenLayerGraphics, OpenGLGraphics, SDLGraphics + * @since 0.1.0 + */ + void setGraphics(Graphics *const graphics); + + /** + * Gets the graphics object used for drawing. + * + * @return The graphics object used for drawing. NULL if no + * graphics object has been set. + * @see setGraphics, AllegroGraphics, HGEGraphics, + * OpenLayerGraphics, OpenGLGraphics, SDLGraphics + * @since 0.1.0 + */ + Graphics* getGraphics() const A_WARN_UNUSED; + + /** + * Sets the input object to use for input handling. + * + * @param input The input object to use for input handling. + * @see getInput, AllegroInput, HGEInput, OpenLayerInput, + * SDLInput + * @since 0.1.0 + */ + void setInput(SDLInput *const input); + + /** + * Gets the input object being used for input handling. + * + * @return The input object used for handling input. NULL if no + * input object has been set. + * @see setInput, AllegroInput, HGEInput, OpenLayerInput, + * SDLInput + * @since 0.1.0 + */ + SDLInput* getInput() const A_WARN_UNUSED; + + /** + * Adds a global key listener to the Gui. A global key listener + * will receive all key events generated from the GUI and global + * key listeners will receive the events before key listeners + * of widgets. + * + * @param keyListener The key listener to add. + * @see removeGlobalKeyListener + * @since 0.5.0 + */ + void addGlobalKeyListener(KeyListener *const keyListener); + + /** + * Removes global key listener from the Gui. + * + * @param keyListener The key listener to remove. + * @throws Exception if the key listener hasn't been added. + * @see addGlobalKeyListener + * @since 0.5.0 + */ + void removeGlobalKeyListener(KeyListener *const keyListener); + + bool isLongPress() const + { return getMousePressLength() > 250; } + + int getMousePressLength() const; + protected: void handleMouseMoved(const MouseInput &mouseInput); @@ -181,7 +320,175 @@ class Gui final : public gcn::Gui int x, int y, bool force = false, bool toSourceOnly = false); + /** + * + * Handles mouse wheel moved down input. + * + * @param mouseInput The mouse input to handle. + * @since 0.6.0 + */ + void handleMouseWheelMovedDown(const MouseInput& mouseInput); + + /** + * Handles mouse wheel moved up input. + * + * @param mouseInput The mouse input to handle. + * @since 0.6.0 + */ + void handleMouseWheelMovedUp(const MouseInput& mouseInput); + + /** + * Gets the widget at a certain position. + * + * @return The widget at a certain position. + * @since 0.6.0 + */ + Widget* getWidgetAt(int x, int y) A_WARN_UNUSED; + + /** + * Gets the source of the mouse event. + * + * @return The source widget of the mouse event. + * @since 0.6.0 + */ + Widget* getMouseEventSource(int x, int y) A_WARN_UNUSED; + + /** + * Gets the source of the key event. + * + * @return The source widget of the key event. + * @since 0.6.0 + */ + Widget* getKeyEventSource() A_WARN_UNUSED; + + /** + * Distributes a key event. + * + * @param keyEvent The key event to distribute. + + * @since 0.6.0 + */ + void distributeKeyEvent(KeyEvent& keyEvent) const; + + /** + * Distributes a key event to the global key listeners. + * + * @param keyEvent The key event to distribute. + * + * @since 0.6.0 + */ + void distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent); + + /** + * Handles modal mouse input focus. Modal mouse input focus needs + * to be checked at each logic iteration as it might be necessary to + * distribute mouse entered or mouse exited events. + * + * @since 0.8.0 + */ + void handleModalMouseInputFocus(); + + /** + * Handles modal focus. Modal focus needs to be checked at + * each logic iteration as it might be necessary to distribute + * mouse entered or mouse exited events. + * + * @since 0.8.0 + */ + void handleModalFocus(); + + /** + * Handles modal focus gained. If modal focus has been gained it might + * be necessary to distribute mouse entered or mouse exited events. + * + * @since 0.8.0 + */ + void handleModalFocusGained(); + + /** + * Handles modal mouse input focus gained. If modal focus has been + * gained it might be necessary to distribute mouse entered or mouse + * exited events. + * + * @since 0.8.0 + */ + void handleModalFocusReleased(); + private: + /** + * Holds the top widget. + */ + Widget* mTop; + + /** + * Holds the graphics implementation used. + */ + Graphics* mGraphics; + + /** + * Holds the input implementation used. + */ + SDLInput* mInput; + + /** + * Holds the focus handler for the Gui. + */ + FocusHandler* mFocusHandler; + + /** + * Typedef. + */ + typedef std::list<KeyListener*> KeyListenerList; + + /** + * Typedef. + */ + typedef KeyListenerList::iterator KeyListenerListIterator; + + /** + * Holds the global key listeners of the Gui. + */ + KeyListenerList mKeyListeners; + + /** + * Holds the last mouse button pressed. + */ + unsigned int mLastMousePressButton; + + /** + * Holds the last mouse press time stamp. + */ + int mLastMousePressTimeStamp; + + /** + * Holds the last mouse x coordinate. + */ + int mLastMouseX; + + /** + * Holds the last mouse y coordinate. + */ + int mLastMouseY; + + /** + * Holds the current click count. Used to keep track + * of clicks for a the last pressed button. + */ + int mClickCount; + + /** + * Holds the last button used when a drag of a widget + * was initiated. Used to be able to release a drag + * when the same button is released. + */ + int mLastMouseDragButton; + + /** + * Holds a stack with all the widgets with the mouse. + * Used to properly distribute mouse events. + */ + std::deque<Widget*> mWidgetWithMouseQueue; + GuiConfigListener *mConfigListener; Font *mGuiFont; /**< The global GUI font */ Font *mInfoParticleFont; /**< Font for Info Particles */ diff --git a/src/gui/models/beingslistmodel.h b/src/gui/models/beingslistmodel.h index 9f3c48bcc..f774321e9 100644 --- a/src/gui/models/beingslistmodel.h +++ b/src/gui/models/beingslistmodel.h @@ -24,6 +24,10 @@ #include "gui/models/avatarlistmodel.h" +#include "utils/dtor.h" + +#include <vector> + class BeingsListModel final : public AvatarListModel { public: diff --git a/src/gui/models/playerrelationlistmodel.h b/src/gui/models/playerrelationlistmodel.h index bc343de02..84531852d 100644 --- a/src/gui/models/playerrelationlistmodel.h +++ b/src/gui/models/playerrelationlistmodel.h @@ -25,6 +25,8 @@ #include "being/playerrelations.h" +#include "gui/models/listmodel.h" + #include "utils/gettext.h" static const char *const RELATION_NAMES[PlayerRelation::RELATIONS_NR] = diff --git a/src/gui/models/serverslistmodel.h b/src/gui/models/serverslistmodel.h index 630d9664e..5c7e73387 100644 --- a/src/gui/models/serverslistmodel.h +++ b/src/gui/models/serverslistmodel.h @@ -25,17 +25,18 @@ #include "net/serverinfo.h" +#include "gui/font.h" +#include "gui/gui.h" + +#include "gui/windows/serverdialog.h" + #include "utils/mutex.h" #include "gui/models/listmodel.h" -#include "net/serverinfo.h" - #include <string> #include <vector> -class ServerDialog; - /** * Server and Port List Model */ diff --git a/src/gui/models/worldlistmodel.h b/src/gui/models/worldlistmodel.h index 7d9dc322c..6913e1c69 100644 --- a/src/gui/models/worldlistmodel.h +++ b/src/gui/models/worldlistmodel.h @@ -25,6 +25,8 @@ #include "gui/models/listmodel.h" +#include "utils/stringutils.h" + #include "net/worldinfo.h" /** diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index ffb90a883..c1e02e9b2 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -103,7 +103,7 @@ bool SDLInput::isKeyQueueEmpty() const return mKeyInputQueue.empty(); } -KeyInput SDLInput::dequeueKeyInput2() +KeyInput SDLInput::dequeueKeyInput() { if (mKeyInputQueue.empty()) return KeyInput(); @@ -132,19 +132,6 @@ MouseInput SDLInput::dequeueMouseInput() return mouseInput; } -MouseInput SDLInput::dequeueMouseInput2() -{ - MouseInput mouseInput; - - if (mMouseInputQueue.empty()) - return MouseInput(); - - mouseInput = mMouseInputQueue.front(); - mMouseInputQueue.pop(); - - return mouseInput; -} - void SDLInput::pushInput(const SDL_Event &event) { KeyInput keyInput; @@ -316,18 +303,6 @@ void SDLInput::pushInput(const SDL_Event &event) void SDLInput::convertKeyEventToKey(const SDL_Event &event, KeyInput &keyInput) { keyInput.setKey(Key(convertKeyCharacter(event))); - keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); - keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); - keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); - keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); -#ifdef USE_SDL2 - const int code = event.key.keysym.scancode; - keyInput.setNumericPad((code >= SDL_SCANCODE_KP_DIVIDE - && code <= SDL_SCANCODE_KP_PERIOD) || code == SDL_SCANCODE_KP_EQUALS); -#else - const int code = event.key.keysym.sym; - keyInput.setNumericPad(code >= SDLK_KP0 && code <= SDLK_KP_EQUALS); -#endif const int actionId = inputManager.getActionByKey(event); if (actionId >= 0) keyInput.setActionId(actionId); diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h index 8197aa110..6102de743 100644 --- a/src/gui/sdlinput.h +++ b/src/gui/sdlinput.h @@ -107,10 +107,7 @@ public: */ void pushInput(const SDL_Event &event); - KeyInput dequeueKeyInput2() A_WARN_UNUSED; - - KeyInput dequeueKeyInput() A_WARN_UNUSED - { return KeyInput(); } + KeyInput dequeueKeyInput() A_WARN_UNUSED; // Inherited from SDLInput @@ -120,8 +117,6 @@ public: MouseInput dequeueMouseInput() A_WARN_UNUSED; - MouseInput dequeueMouseInput2() A_WARN_UNUSED; - void simulateMouseClick(const int x, const int y, const unsigned int button); diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h index 1b767516d..d146a334f 100644 --- a/src/gui/setupactiondata.h +++ b/src/gui/setupactiondata.h @@ -366,6 +366,12 @@ static SetupActionData setupActionData2[] = }, { // TRANSLATORS: input action name + N_("About Window"), + Input::KEY_WINDOW_ABOUT, + "", + }, + { + // TRANSLATORS: input action name N_("Help Window"), Input::KEY_WINDOW_HELP, "", @@ -1232,6 +1238,67 @@ static SetupActionData setupActionData5[] = "", }, { + // TRANSLATORS: input action name + N_("Show smiles"), + Input::KEY_GUI_F1, + "", + }, + { + "F2", + Input::KEY_GUI_F2, + "", + }, + { + "F3", + Input::KEY_GUI_F3, + "", + }, + { + "F4", + Input::KEY_GUI_F4, + "", + }, + { + "F5", + Input::KEY_GUI_F5, + "", + }, + { + "F6", + Input::KEY_GUI_F6, + "", + }, + { + "F7", + Input::KEY_GUI_F7, + "", + }, + { + "F8", + Input::KEY_GUI_F8, + "", + }, + { + "F9", + Input::KEY_GUI_F9, + "", + }, + { + "F10", + Input::KEY_GUI_F10, + "", + }, + { + "F11", + Input::KEY_GUI_F11, + "", + }, + { + "F12", + Input::KEY_GUI_F12, + "", + }, + { "", Input::KEY_NO_VALUE, "" diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 96760f8c7..c2000b562 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -53,30 +53,34 @@ Viewport::Viewport() : WindowContainer(nullptr), MouseListener(), mMap(nullptr), + mPopupMenu(new PopupMenu), + mHoverBeing(nullptr), + mHoverItem(nullptr), + mHoverSign(nullptr), + mBeingPopup(new BeingPopup), + mTextPopup(new TextPopup), mScrollRadius(config.getIntValue("ScrollRadius")), mScrollLaziness(config.getIntValue("ScrollLaziness")), - mShowBeingPopup(config.getBoolValue("showBeingPopup")), - mSelfMouseHeal(config.getBoolValue("selfMouseHeal")), - mEnableLazyScrolling(config.getBoolValue("enableLazyScrolling")), mScrollCenterOffsetX(config.getIntValue("ScrollCenterOffsetX")), mScrollCenterOffsetY(config.getIntValue("ScrollCenterOffsetY")), - mMouseDirectionMove(config.getBoolValue("mouseDirectionMove")), mMouseX(0), mMouseY(0), + mMousePressX(0), + mMousePressY(0), mPixelViewX(0), mPixelViewY(0), - mShowDebugPath(false), + mShowDebugPath(Map::MAP_NORMAL), mCameraMode(0), - mPlayerFollowMouse(false), mLocalWalkTime(-1), - mPopupMenu(new PopupMenu), - mHoverBeing(nullptr), - mHoverItem(nullptr), - mHoverSign(nullptr), - mBeingPopup(new BeingPopup), - mTextPopup(new TextPopup), mCameraRelativeX(0), - mCameraRelativeY(0) + mCameraRelativeY(0), + mShowBeingPopup(config.getBoolValue("showBeingPopup")), + mSelfMouseHeal(config.getBoolValue("selfMouseHeal")), + mEnableLazyScrolling(config.getBoolValue("enableLazyScrolling")), + mMouseDirectionMove(config.getBoolValue("mouseDirectionMove")), + mLongMouseClick(config.getBoolValue("longmouseclick")), + mMouseClicked(false), + mPlayerFollowMouse(false) { mBeingPopup->postInit(); mPopupMenu->postInit(); @@ -91,6 +95,7 @@ Viewport::Viewport() : config.addListener("selfMouseHeal", this); config.addListener("enableLazyScrolling", this); config.addListener("mouseDirectionMove", this); + config.addListener("longmouseclick", this); setFocusable(true); } @@ -281,17 +286,13 @@ void Viewport::_followMouse() { // We create a mouse event and send it to mouseDragged. MouseEvent mouseEvent(nullptr, - 0, - false, - false, - false, MouseEvent::DRAGGED, MouseEvent::LEFT, mMouseX, mMouseY, 0); - mouseDragged(mouseEvent); + walkByMouse(mouseEvent); } } @@ -360,151 +361,170 @@ void Viewport::_drawPath(Graphics *const graphics, const Path &path, } } -void Viewport::mousePressed(MouseEvent &event) +bool Viewport::openContextMenu(const MouseEvent &event) { - if (event.getSource() != this) - return; - - // Check if we are alive and kickin' - if (!mMap || !player_node) - return; - - // Check if we are busy - // if commented, allow context menu if npc dialog open - if (PlayerInfo::isTalking()) - return; - + mPlayerFollowMouse = false; const int eventX = event.getX(); const int eventY = event.getY(); - const unsigned int eventButton = event.getButton(); - const int pixelX = eventX + mPixelViewX; - const int pixelY = eventY + mPixelViewY; - - // Right click might open a popup - if (eventButton == MouseEvent::RIGHT) + if (mHoverBeing) { - mPlayerFollowMouse = false; - if (mHoverBeing) - { - validateSpeed(); - if (actorManager) - { - std::vector<ActorSprite*> beings; - const int x = mMouseX + mPixelViewX; - const int y = mMouseY + mPixelViewY; - actorManager->findBeingsByPixel(beings, x, y, true); - if (beings.size() > 1) - { - mPopupMenu->showPopup(eventX, eventY, beings); - return; - } - else - { - mPopupMenu->showPopup(eventX, eventY, mHoverBeing); - return; - } - } - } - else if (mHoverItem) - { - validateSpeed(); - mPopupMenu->showPopup(eventX, eventY, mHoverItem); - return; - } - else if (mHoverSign) - { - validateSpeed(); - mPopupMenu->showPopup(eventX, eventY, mHoverSign); - return; - } - else if (mCameraMode) + validateSpeed(); + if (actorManager) { - mPopupMenu->showMapPopup(eventX, eventY, - (mMouseX + mPixelViewX) / mMap->getTileWidth(), - (mMouseY + mPixelViewY) / mMap->getTileHeight()); - return; + std::vector<ActorSprite*> beings; + const int x = mMouseX + mPixelViewX; + const int y = mMouseY + mPixelViewY; + actorManager->findBeingsByPixel(beings, x, y, true); + if (beings.size() > 1) + mPopupMenu->showPopup(eventX, eventY, beings); + else + mPopupMenu->showPopup(eventX, eventY, mHoverBeing); + return true; } } - - // If a popup is active, just remove it - if (mPopupMenu->isPopupVisible()) + else if (mHoverItem) { - mPlayerFollowMouse = false; - mPopupMenu->setVisible(false); - return; + validateSpeed(); + mPopupMenu->showPopup(eventX, eventY, mHoverItem); + return true; + } + else if (mHoverSign) + { + validateSpeed(); + mPopupMenu->showPopup(eventX, eventY, mHoverSign); + return true; + } + else if (mCameraMode) + { + mPopupMenu->showMapPopup(eventX, eventY, + (mMouseX + mPixelViewX) / mMap->getTileWidth(), + (mMouseY + mPixelViewY) / mMap->getTileHeight()); + return true; } + return false; +} - // Left click can cause different actions - if (eventButton == MouseEvent::LEFT) +bool Viewport::leftMouseAction() +{ + // Interact with some being + if (mHoverBeing) { - // Interact with some being - if (mHoverBeing) - { - if (!mHoverBeing->isAlive()) - return; + if (!mHoverBeing->isAlive()) + return true; - if (mHoverBeing->canTalk()) + if (mHoverBeing->canTalk()) + { + validateSpeed(); + mHoverBeing->talkTo(); + return true; + } + else + { + const ActorSprite::Type type = mHoverBeing->getType(); + if (type == ActorSprite::PLAYER) { validateSpeed(); - mHoverBeing->talkTo(); - return; - } - else - { - if (mHoverBeing->getType() == ActorSprite::PLAYER) + if (actorManager) { - validateSpeed(); - if (actorManager) - { - if (player_node != mHoverBeing || mSelfMouseHeal) - actorManager->heal(mHoverBeing); - if (player_node == mHoverBeing && mHoverItem) - player_node->pickUp(mHoverItem); - return; - } + if (player_node != mHoverBeing || mSelfMouseHeal) + actorManager->heal(mHoverBeing); + if (player_node == mHoverBeing && mHoverItem) + player_node->pickUp(mHoverItem); + return true; } - else if (player_node->withinAttackRange(mHoverBeing) || - inputManager.isActionActive(static_cast<int>( - Input::KEY_ATTACK))) + } + else if (type == ActorSprite::MONSTER || type == ActorSprite::NPC) + { + if (player_node->withinAttackRange(mHoverBeing) || + inputManager.isActionActive(static_cast<int>( + Input::KEY_ATTACK))) { validateSpeed(); - if (player_node != mHoverBeing) + if (!mStatsReUpdated && player_node != mHoverBeing) { player_node->attack(mHoverBeing, !inputManager.isActionActive( static_cast<int>(Input::KEY_STOP_ATTACK))); - return; + return true; } } else if (!inputManager.isActionActive(static_cast<int>( Input::KEY_ATTACK))) { validateSpeed(); - if (player_node != mHoverBeing) + if (!mStatsReUpdated && player_node != mHoverBeing) { player_node->setGotoTarget(mHoverBeing); - return; + return true; } } } } - // Picks up a item if we clicked on one - if (mHoverItem) - { - validateSpeed(); - player_node->pickUp(mHoverItem); - } - // Just walk around - else if (!inputManager.isActionActive(static_cast<int>( - Input::KEY_ATTACK))) - { - validateSpeed(); - player_node->stopAttack(); - player_node->cancelFollow(); - mPlayerFollowMouse = true; + } + // Picks up a item if we clicked on one + if (mHoverItem) + { + validateSpeed(); + player_node->pickUp(mHoverItem); + } + // Just walk around + else if (!inputManager.isActionActive(static_cast<int>( + Input::KEY_ATTACK))) + { + validateSpeed(); + player_node->stopAttack(); + player_node->cancelFollow(); + mPlayerFollowMouse = true; - // Make the player go to the mouse position - _followMouse(); + // Make the player go to the mouse position + _followMouse(); + } + return false; +} + +void Viewport::mousePressed(MouseEvent &event) +{ + if (event.getSource() != this || event.isConsumed()) + return; + + mMouseClicked = true; + // Check if we are alive and kickin' + if (!mMap || !player_node) + return; + + // Check if we are busy + // if commented, allow context menu if npc dialog open + if (PlayerInfo::isTalking()) + return; + + mMousePressX = event.getX(); + mMousePressY = event.getY(); + const unsigned int eventButton = event.getButton(); + const int pixelX = mMousePressX + mPixelViewX; + const int pixelY = mMousePressY + mPixelViewY; + + // Right click might open a popup + if (eventButton == MouseEvent::RIGHT) + { + if (openContextMenu(event)) + return; + } + + // If a popup is active, just remove it + if (mPopupMenu->isPopupVisible()) + { + mPlayerFollowMouse = false; + mPopupMenu->setVisible(false); + return; + } + + // Left click can cause different actions + if (!mLongMouseClick && eventButton == MouseEvent::LEFT) + { + if (leftMouseAction()) + { + mPlayerFollowMouse = false; + return; } } else if (eventButton == MouseEvent::MIDDLE) @@ -523,15 +543,16 @@ void Viewport::mousePressed(MouseEvent &event) } } -void Viewport::mouseDragged(MouseEvent &event) +void Viewport::walkByMouse(const MouseEvent &event) { if (!mMap || !player_node) return; - if (mPlayerFollowMouse && !inputManager.isActionActive( Input::KEY_STOP_ATTACK) && !inputManager.isActionActive( Input::KEY_UNTARGET)) { + if (!mMouseDirectionMove) + mPlayerFollowMouse = false; if (mLocalWalkTime != player_node->getActionTime()) { mLocalWalkTime = cur_time; @@ -644,10 +665,51 @@ void Viewport::mouseDragged(MouseEvent &event) } } -void Viewport::mouseReleased(MouseEvent &event A_UNUSED) +void Viewport::mouseDragged(MouseEvent &event) +{ + if (event.getSource() != this || event.isConsumed()) + return; + if (mMouseClicked) + { + if (abs(event.getX() - mMousePressX) > 32 + || abs(event.getY() - mMousePressY) > 32) + { + mPlayerFollowMouse = true; + } + } + + walkByMouse(event); +} + +void Viewport::mouseReleased(MouseEvent &event) { mPlayerFollowMouse = false; mLocalWalkTime = -1; + if (mLongMouseClick && mMouseClicked) + { + mMouseClicked = false; + if (event.getSource() != this || event.isConsumed()) + return; + const unsigned int eventButton = event.getButton(); + if (eventButton == MouseEvent::LEFT) + { + // long button press + if (gui && gui->isLongPress()) + { + if (openContextMenu(event)) + { + gui->resetClickCount(); + return; + } + } + else + { + if (leftMouseAction()) + return; + } + walkByMouse(event); + } + } } void Viewport::showPopup(Window *const parent, const int x, const int y, @@ -794,6 +856,8 @@ void Viewport::optionChanged(const std::string &name) mEnableLazyScrolling = config.getBoolValue("enableLazyScrolling"); else if (name == "mouseDirectionMove") mMouseDirectionMove = config.getBoolValue("mouseDirectionMove"); + else if (name == "longmouseclick") + mLongMouseClick = config.getBoolValue("longmouseclick"); } void Viewport::mouseMoved(MouseEvent &event A_UNUSED) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 16d0e4e34..c98350744 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -300,6 +300,12 @@ class Viewport final : public WindowContainer, void _drawPath(Graphics *const graphics, const Path &path, const Color &color = Color(255, 0, 0)) const; + bool leftMouseAction(); + + bool openContextMenu(const MouseEvent &event); + + void walkByMouse(const MouseEvent &event); + /** * Make the player go to the mouse position. */ @@ -307,34 +313,38 @@ class Viewport final : public WindowContainer, Map *mMap; /**< The current map. */ + PopupMenu *mPopupMenu; /**< Popup menu. */ + Being *mHoverBeing; /**< Being mouse is currently over. */ + FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */ + MapItem *mHoverSign; /**< Map sign mouse is currently over. */ + BeingPopup *mBeingPopup; /**< Being information popup. */ + TextPopup *mTextPopup; /**< Map Item information popup. */ + int mScrollRadius; int mScrollLaziness; - bool mShowBeingPopup; - bool mSelfMouseHeal; - bool mEnableLazyScrolling; int mScrollCenterOffsetX; int mScrollCenterOffsetY; - bool mMouseDirectionMove; int mMouseX; /**< Current mouse position in pixels. */ int mMouseY; /**< Current mouse position in pixels. */ + int mMousePressX; + int mMousePressY; int mPixelViewX; /**< Current viewpoint in pixels. */ int mPixelViewY; /**< Current viewpoint in pixels. */ int mShowDebugPath; /**< Show a path from player to pointer. */ int mCameraMode; /**< Camera mode. */ - bool mPlayerFollowMouse; - int mLocalWalkTime; /**< Timestamp before the next walk can be sent. */ - PopupMenu *mPopupMenu; /**< Popup menu. */ - Being *mHoverBeing; /**< Being mouse is currently over. */ - FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */ - MapItem *mHoverSign; /**< Map sign mouse is currently over. */ - BeingPopup *mBeingPopup; /**< Being information popup. */ - TextPopup *mTextPopup; /**< Map Item information popup. */ - int mCameraRelativeX; int mCameraRelativeY; + + bool mShowBeingPopup; + bool mSelfMouseHeal; + bool mEnableLazyScrolling; + bool mMouseDirectionMove; + bool mLongMouseClick; + bool mMouseClicked; + bool mPlayerFollowMouse; }; extern Viewport *viewport; /**< The viewport. */ diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp new file mode 100644 index 000000000..d3dd62fc7 --- /dev/null +++ b/src/gui/widgets/basiccontainer.cpp @@ -0,0 +1,377 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gui/widgets/basiccontainer.h" + +#include <algorithm> + +#include "debug.h" + +BasicContainer::~BasicContainer() +{ + clear(); +} + +void BasicContainer::moveToTop(Widget* widget) +{ + for (WidgetListIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + if (*iter == widget) + { + mWidgets.erase(iter); + mWidgets.push_back(widget); + return; + } + } +} + +void BasicContainer::moveToBottom(Widget* widget) +{ + WidgetListIterator iter; + iter = std::find(mWidgets.begin(), mWidgets.end(), widget); + + if (iter == mWidgets.end()) + return; + + mWidgets.erase(iter); + mWidgets.insert(mWidgets.begin(), widget); +} + +void BasicContainer::death(const Event& event) +{ + WidgetListIterator iter; + iter = std::find(mWidgets.begin(), mWidgets.end(), event.getSource()); + + if (iter == mWidgets.end()) + return; + + mWidgets.erase(iter); +} + +Rect BasicContainer::getChildrenArea() +{ + return Rect(0, 0, getWidth(), getHeight()); +} + +void BasicContainer::focusNext() +{ + WidgetListConstIterator it; + + for (it = mWidgets.begin(); it != mWidgets.end(); ++ it) + { + if ((*it)->isFocused()) + break; + } + + WidgetListConstIterator end = it; + + if (it == mWidgets.end()) + it = mWidgets.begin(); + + ++ it; + + for ( ; it != end; ++ it) + { + if (it == mWidgets.end()) + it = mWidgets.begin(); + + if ((*it)->isFocusable()) + { + (*it)->requestFocus(); + return; + } + } +} + +void BasicContainer::focusPrevious() +{ + WidgetListReverseIterator it; + + for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it) + { + if ((*it)->isFocused()) + break; + } + + const WidgetListReverseIterator end = it; + + ++ it; + + if (it == mWidgets.rend()) + it = mWidgets.rbegin(); + + for ( ; it != end; ++ it) + { + if (it == mWidgets.rend()) + it = mWidgets.rbegin(); + + if ((*it)->isFocusable()) + { + (*it)->requestFocus(); + return; + } + } +} + +Widget *BasicContainer::getWidgetAt(int x, int y) +{ + const Rect r = getChildrenArea(); + + if (!r.isPointInRect(x, y)) + return nullptr; + + x -= r.x; + y -= r.y; + + for (WidgetListReverseIterator it = mWidgets.rbegin(); + it != mWidgets.rend(); ++ it) + { + if ((*it)->isVisible() && (*it)->getDimension() + .isPointInRect(x, y)) + { + return (*it); + } + } + + return nullptr; +} + +void BasicContainer::logic() +{ + BLOCK_START("BasicContainer::logic") + logicChildren(); + BLOCK_END("BasicContainer::logic") +} + +void BasicContainer::_setFocusHandler(FocusHandler* focusHandler) +{ + Widget::_setFocusHandler(focusHandler); + + if (mInternalFocusHandler) + return; + + for (WidgetListConstIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + (*iter)->_setFocusHandler(focusHandler); + } +} + +void BasicContainer::add(Widget* widget) +{ + mWidgets.push_back(widget); + + if (!mInternalFocusHandler) + widget->_setFocusHandler(_getFocusHandler()); + else + widget->_setFocusHandler(mInternalFocusHandler); + + widget->_setParent(this); + widget->addDeathListener(this); +} + +void BasicContainer::remove(Widget* widget) +{ + for (WidgetListIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + if (*iter == widget) + { + mWidgets.erase(iter); + widget->_setFocusHandler(nullptr); + widget->_setParent(nullptr); + widget->removeDeathListener(this); + return; + } + } +} + +void BasicContainer::clear() +{ + for (WidgetListConstIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + (*iter)->_setFocusHandler(nullptr); + (*iter)->_setParent(nullptr); + (*iter)->removeDeathListener(this); + } + + mWidgets.clear(); +} + +void BasicContainer::drawChildren(Graphics* graphics) +{ + BLOCK_START("BasicContainer::drawChildren") + + graphics->pushClipArea(getChildrenArea()); + + for (WidgetListConstIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + Widget *const widget = *iter; + if (widget->isVisible()) + { + // If the widget has a frame, + // draw it before drawing the widget + if (widget->getFrameSize() > 0) + { + Rect rec = widget->getDimension(); + const int frame = widget->getFrameSize(); + const int frame2 = frame * 2; + rec.x -= frame; + rec.y -= frame; + rec.width += frame2; + rec.height += frame2; + graphics->pushClipArea(rec); + BLOCK_START("BasicContainer::drawChildren 1") + widget->drawFrame(graphics); + BLOCK_END("BasicContainer::drawChildren 1") + graphics->popClipArea(); + } + + graphics->pushClipArea(widget->getDimension()); + BLOCK_START("BasicContainer::drawChildren 2") + widget->draw(graphics); + BLOCK_END("BasicContainer::drawChildren 2") + graphics->popClipArea(); + } + } + + graphics->popClipArea(); + BLOCK_END("BasicContainer::drawChildren") +} + +void BasicContainer::logicChildren() +{ + BLOCK_START("BasicContainer::logicChildren") + for (WidgetListConstIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + (*iter)->logic(); + } + BLOCK_END("BasicContainer::logicChildren") +} + +void BasicContainer::showWidgetPart(Widget *const widget, Rect area) +{ + const Rect widgetArea = getChildrenArea(); + + area.x += widget->getX(); + area.y += widget->getY(); + + if (area.x + area.width > widgetArea.width) + { + widget->setX(widget->getX() - area.x + - area.width + widgetArea.width); + } + + if (area.y + area.height > widgetArea.height) + { + widget->setY(widget->getY() - area.y + - area.height + widgetArea.height); + } + + if (area.x < 0) + widget->setX(widget->getX() - area.x); + + if (area.y < 0) + widget->setY(widget->getY() - area.y); +} + +void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler) +{ + Widget::setInternalFocusHandler(focusHandler); + + for (WidgetListConstIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + if (!mInternalFocusHandler) + (*iter)->_setFocusHandler(_getFocusHandler()); + else + (*iter)->_setFocusHandler(mInternalFocusHandler); + } +} + +Widget* BasicContainer::findWidgetById(const std::string& id) +{ + for (WidgetListConstIterator iter = mWidgets.begin(); + iter != mWidgets.end(); ++ iter) + { + if ((*iter)->getId() == id) + return (*iter); + + BasicContainer *const basicContainer + = dynamic_cast<BasicContainer *const>(*iter); + + if (basicContainer) + { + Widget *const widget = basicContainer->findWidgetById(id); + + if (widget) + return widget; + } + } + + return nullptr; +} diff --git a/src/gui/base/basiccontainer.hpp b/src/gui/widgets/basiccontainer.h index e1947c652..6e753a445 100644 --- a/src/gui/base/basiccontainer.hpp +++ b/src/gui/widgets/basiccontainer.h @@ -61,8 +61,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GCN_BASICCONTAINER_HPP -#define GCN_BASICCONTAINER_HPP +#ifndef GUI_WIDGETS_BASICCONTAINER_H +#define GUI_WIDGETS_BASICCONTAINER_H #include <vector> @@ -70,19 +70,17 @@ #include "listeners/deathlistener.h" -namespace gcn +/** + * A base class for containers. The class implements the most + * common things for a container. If you are implementing a + * container, consider inheriting from this class. + * + * @see Container + * @since 0.6.0 + */ +class BasicContainer : public Widget, + public DeathListener { - /** - * A base class for containers. The class implements the most - * common things for a container. If you are implementing a - * container, consider inheriting from this class. - * - * @see Container - * @since 0.6.0 - */ - class BasicContainer : public Widget, - public DeathListener - { public: explicit BasicContainer(const Widget2 *const widget) : Widget(widget), @@ -93,22 +91,22 @@ namespace gcn A_DELETE_COPY(BasicContainer) /** - * Destructor - */ + * Destructor + */ virtual ~BasicContainer(); /** - * Shows a certain part of a widget in the basic container. - * Used when widgets want a specific part to be visible in - * its parent. An example is a TextArea that wants a specific - * part of its text to be visible when a TextArea is a child - * of a ScrollArea. - * - * @param widget The widget whom wants a specific part of - * itself to be visible. - * @param rectangle The rectangle to be visible. - */ - virtual void showWidgetPart(Widget* widget, Rect area); + * Shows a certain part of a widget in the basic container. + * Used when widgets want a specific part to be visible in + * its parent. An example is a TextArea that wants a specific + * part of its text to be visible when a TextArea is a child + * of a ScrollArea. + * + * @param widget The widget whom wants a specific part of + * itself to be visible. + * @param rectangle The rectangle to be visible. + */ + virtual void showWidgetPart(Widget *const widget, Rect area); // Inherited from Widget @@ -137,82 +135,81 @@ namespace gcn protected: /** - * Adds a widget to the basic container. - * - * @param widget The widget to add. - * @see remove, clear - */ + * Adds a widget to the basic container. + * + * @param widget The widget to add. + * @see remove, clear + */ void add(Widget* widget); /** - * Removes a widget from the basic container. - * - * @param widget The widget to remove. - * @see add, clear - */ + * Removes a widget from the basic container. + * + * @param widget The widget to remove. + * @see add, clear + */ virtual void remove(Widget* widget); /** - * Clears the basic container from all widgets. - * - * @see remove, clear - */ + * Clears the basic container from all widgets. + * + * @see remove, clear + */ virtual void clear(); /** - * Draws the children widgets of the basic container. - * - * @param graphics A graphics object to draw with. - */ + * Draws the children widgets of the basic container. + * + * @param graphics A graphics object to draw with. + */ virtual void drawChildren(Graphics* graphics); /** - * Calls logic for the children widgets of the basic - * container. - */ + * Calls logic for the children widgets of the basic + * container. + */ virtual void logicChildren(); /** - * Finds a widget given an id. This function can be useful - * when implementing a GUI generator for Guichan, such as - * the ability to create a Guichan GUI from an XML file. - * - * @param id The id to find a widget by. - * @return The widget with the corrosponding id, - NULL of no widget is found. - */ + * Finds a widget given an id. This function can be useful + * when implementing a GUI generator for Guichan, such as + * the ability to create a Guichan GUI from an XML file. + * + * @param id The id to find a widget by. + * @return The widget with the corrosponding id, + NULL of no widget is found. + */ virtual Widget* findWidgetById(const std::string& id) A_WARN_UNUSED; /** - * Typedef. - */ + * Typedef. + */ typedef std::vector<Widget *> WidgetList; - /** - * Typedef. - */ + /** + * Typedef. + */ typedef WidgetList::iterator WidgetListIterator; - /** - * Typedef. - */ + /** + * Typedef. + */ typedef WidgetList::const_iterator WidgetListConstIterator; /** - * Typedef. - */ + * Typedef. + */ typedef WidgetList::reverse_iterator WidgetListReverseIterator; /** - * Typedef. - */ + * Typedef. + */ typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator; /** - * Holds all widgets of the basic container. - */ + * Holds all widgets of the basic container. + */ WidgetList mWidgets; - }; -} // namespace gcn +}; -#endif // end GCN_BASICCONTAINER_HPP +#endif // GUI_WIDGETS_BASICCONTAINER_H diff --git a/src/gui/base/widgets/label.cpp b/src/gui/widgets/basiccontainer2.cpp index d2293a957..9bd4d1593 100644 --- a/src/gui/base/widgets/label.cpp +++ b/src/gui/widgets/basiccontainer2.cpp @@ -65,58 +65,65 @@ * For comments regarding functions please see the header file. */ -#include "gui/base/widgets/label.hpp" +#include "gui/widgets/basiccontainer2.h" -#include "gui/font.h" +#include "debug.h" -#include "render/graphics.h" +BasicContainer2::BasicContainer2(const Widget2 *const widget) : + BasicContainer(widget), + mOpaque(true) +{ +} -#include "debug.h" +BasicContainer2::~BasicContainer2() +{ +} -namespace gcn +void BasicContainer2::draw(Graphics* graphics) { - Label::Label(const Widget2 *const widget) : - Widget(widget), - mCaption(), - mAlignment(Graphics::LEFT) + BLOCK_START("BasicContainer2::draw") + if (isOpaque()) { + graphics->setColor(getBaseColor()); + graphics->fillRectangle(Rect(0, 0, getWidth(), getHeight())); } - Label::Label(const Widget2 *const widget, - const std::string& caption) : - Widget(widget), - mCaption(caption), - mAlignment(Graphics::LEFT) - { - setWidth(getFont()->getWidth(caption)); - setHeight(getFont()->getHeight()); - } + drawChildren(graphics); + BLOCK_END("BasicContainer2::draw") +} - const std::string &Label::getCaption() const - { - return mCaption; - } +void BasicContainer2::setOpaque(bool opaque) +{ + mOpaque = opaque; +} - void Label::setCaption(const std::string& caption) - { - mCaption = caption; - } +bool BasicContainer2::isOpaque() const +{ + return mOpaque; +} - void Label::setAlignment(Graphics::Alignment alignment) - { - mAlignment = alignment; - } +void BasicContainer2::add(Widget* widget) +{ + BasicContainer::add(widget); +} - Graphics::Alignment Label::getAlignment() const - { - return mAlignment; - } +void BasicContainer2::add(Widget* widget, int x, int y) +{ + widget->setPosition(x, y); + BasicContainer::add(widget); +} - void Label::draw(Graphics* graphics A_UNUSED) - { - } +void BasicContainer2::remove(Widget* widget) +{ + BasicContainer::remove(widget); +} - void Label::adjustSize() - { - } -} // namespace gcn +void BasicContainer2::clear() +{ + BasicContainer::clear(); +} + +Widget* BasicContainer2::findWidgetById(const std::string &id) +{ + return BasicContainer::findWidgetById(id); +} diff --git a/src/gui/base/widgets/container.hpp b/src/gui/widgets/basiccontainer2.h index 3e6c0a587..c6f1d996b 100644 --- a/src/gui/base/widgets/container.hpp +++ b/src/gui/widgets/basiccontainer2.h @@ -61,104 +61,102 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GCN_CONTAINER_HPP -#define GCN_CONTAINER_HPP - -#include "gui/base/basiccontainer.hpp" - -namespace gcn +#ifndef GUI_WIDGETS_BASICCONTAINER2_H +#define GUI_WIDGETS_BASICCONTAINER2_H + +#include "gui/widgets/basiccontainer.h" + +/** + * An implementation of a container able to contain other widgets. A widget's + * position in the container is relative to the container itself and not the screen. + * A container is the most common widget to use as the Gui's top widget as makes the Gui + * able to contain more than one widget. + * + * @see Gui::setTop + */ +class BasicContainer2: public BasicContainer { - /** - * An implementation of a container able to contain other widgets. A widget's - * position in the container is relative to the container itself and not the screen. - * A container is the most common widget to use as the Gui's top widget as makes the Gui - * able to contain more than one widget. - * - * @see Gui::setTop - */ - class Container: public BasicContainer - { public: /** - * Constructor. A container is opauqe as default, if you want a - * none opaque container call setQpaque(false). - * - * @see setOpaque, isOpaque - */ - explicit Container(const Widget2 *const widget); + * Constructor. A container is opauqe as default, if you want a + * none opaque container call setQpaque(false). + * + * @see setOpaque, isOpaque + */ + explicit BasicContainer2(const Widget2 *const widget); /** - * Destructor. - */ - virtual ~Container(); + * Destructor. + */ + virtual ~BasicContainer2(); /** - * Sets the container to be opaque or not. If the container - * is opaque its background will be drawn, if it's not opaque - * its background will not be drawn, and thus making the container - * completely transparent. - * - * NOTE: This is not the same as to set visibility. A non visible - * container will not itself nor will it draw its content. - * - * @param opaque True if the container should be opaque, false otherwise. - * @see isOpaque - */ + * Sets the container to be opaque or not. If the container + * is opaque its background will be drawn, if it's not opaque + * its background will not be drawn, and thus making the container + * completely transparent. + * + * NOTE: This is not the same as to set visibility. A non visible + * container will not itself nor will it draw its content. + * + * @param opaque True if the container should be opaque, false otherwise. + * @see isOpaque + */ void setOpaque(bool opaque); /** - * Checks if the container is opaque or not. - * - * @return True if the container is opaque, false otherwise. - * @see setOpaque - */ + * Checks if the container is opaque or not. + * + * @return True if the container is opaque, false otherwise. + * @see setOpaque + */ bool isOpaque() const; /** - * Adds a widget to the container. - * - * @param widget The widget to add. - * @see remove, clear - */ + * Adds a widget to the container. + * + * @param widget The widget to add. + * @see remove, clear + */ virtual void add(Widget* widget); /** - * Adds a widget to the container and also specifies the widget's - * position in the container. The position is relative to the container - * and not relative to the screen. - * - * @param widget The widget to add. - * @param x The x coordinate for the widget. - * @param y The y coordinate for the widget. - * @see remove, clear - */ + * Adds a widget to the container and also specifies the widget's + * position in the container. The position is relative to the container + * and not relative to the screen. + * + * @param widget The widget to add. + * @param x The x coordinate for the widget. + * @param y The y coordinate for the widget. + * @see remove, clear + */ virtual void add(Widget* widget, int x, int y); /** - * Removes a widget from the Container. - * - * @param widget The widget to remove. - * @throws Exception when the widget has not been added to the - * container. - * @see add, clear - */ + * Removes a widget from the Container. + * + * @param widget The widget to remove. + * @throws Exception when the widget has not been added to the + * container. + * @see add, clear + */ virtual void remove(Widget* widget); /** - * Clears the container of all widgets. - * - * @see add, remove - */ + * Clears the container of all widgets. + * + * @see add, remove + */ virtual void clear(); /** - * Finds a widget given an id. - * - * @param id The id to find a widget by. - * @return A widget with a corrosponding id, NULL if no widget - * is found. - * @see Widget::setId - */ + * Finds a widget given an id. + * + * @param id The id to find a widget by. + * @return A widget with a corrosponding id, NULL if no widget + * is found. + * @see Widget::setId + */ virtual Widget* findWidgetById(const std::string &id); @@ -168,10 +166,9 @@ namespace gcn protected: /** - * True if the container is opaque, false otherwise. - */ + * True if the container is opaque, false otherwise. + */ bool mOpaque; - }; -} // namespace gcn +}; -#endif // end GCN_CONTAINER_HPP +#endif // GUI_WIDGETS_BASICCONTAINER2_H diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 3cb6d823d..308c75413 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -20,6 +20,49 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/button.h" #include "client.h" @@ -53,8 +96,17 @@ static std::string const data[Button::BUTTON_COUNT] = Skin *Button::button[BUTTON_COUNT]; Button::Button(const Widget2 *const widget) : - gcn::Button(widget), + Widget(widget), + MouseListener(), + KeyListener(), + FocusListener(), WidgetListener(), + mCaption(), + mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4), mDescription(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(Theme::BUTTON)), @@ -86,8 +138,17 @@ Button::Button(const Widget2 *const widget, const std::string &restrict caption, const std::string &restrict actionEventId, ActionListener *const listener) : - gcn::Button(widget, caption), + Widget(widget), + MouseListener(), + KeyListener(), + FocusListener(), WidgetListener(), + mCaption(caption), + mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4), mDescription(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(Theme::BUTTON)), @@ -125,8 +186,17 @@ Button::Button(const Widget2 *const widget, const int imageWidth, const int imageHeight, const std::string &restrict actionEventId, ActionListener *const listener) : - gcn::Button(widget, caption), + Widget(widget), + MouseListener(), + KeyListener(), + FocusListener(), WidgetListener(), + mCaption(caption), + mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4), mDescription(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(Theme::BUTTON)), @@ -164,8 +234,17 @@ Button::Button(const Widget2 *const widget, const int imageWidth, const int imageHeight, const std::string &restrict actionEventId, ActionListener *const listener) : - gcn::Button(widget), + Widget(widget), + MouseListener(), + KeyListener(), + FocusListener(), WidgetListener(), + mCaption(), + mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4), mDescription(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(Theme::BUTTON)), @@ -203,8 +282,17 @@ Button::Button(const Widget2 *const widget, const std::string &restrict imageName, const std::string &restrict actionEventId, ActionListener *const listener) : - gcn::Button(widget, caption), + Widget(widget), + MouseListener(), + KeyListener(), + FocusListener(), WidgetListener(), + mCaption(caption), + mHasMouse(false), + mKeyPressed(false), + mMousePressed(false), + mAlignment(Graphics::CENTER), + mSpacing(4), mDescription(), mVertexes2(new ImageCollection), mEnabledColor(getThemeColor(Theme::BUTTON)), @@ -239,10 +327,14 @@ Button::Button(const Widget2 *const widget, void Button::init() { - setFrameSize(0); - + addMouseListener(this); + addKeyListener(this); + addFocusListener(this); addWidgetListener(this); + setFocusable(true); + setFrameSize(0); + if (mInstances == 0) { if (Theme::instance()) @@ -584,11 +676,6 @@ void Button::adjustSize() } } -void Button::setCaption(const std::string& caption) -{ - mCaption = caption; -} - void Button::keyPressed(KeyEvent& keyEvent) { const int action = keyEvent.getActionId(); @@ -614,8 +701,45 @@ void Button::keyReleased(KeyEvent& keyEvent) } } - bool Button::isPressed2() const { return (mPressed || isPressed()); } + +bool Button::isPressed() const +{ + if (mMousePressed) + return mHasMouse; + else + return mKeyPressed; +} + +void Button::focusLost(const Event& event A_UNUSED) +{ + mMousePressed = false; + mKeyPressed = false; +} + +void Button::mousePressed(MouseEvent& mouseEvent) +{ + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + mMousePressed = true; + mouseEvent.consume(); + } +} + +void Button::mouseEntered(MouseEvent& mouseEvent A_UNUSED) +{ + mHasMouse = true; +} + +void Button::mouseExited(MouseEvent& mouseEvent A_UNUSED) +{ + mHasMouse = false; +} + +void Button::mouseDragged(MouseEvent& mouseEvent) +{ + mouseEvent.consume(); +} diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index 039475150..6eba9b3c0 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -20,10 +20,57 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_BUTTON_H #define GUI_WIDGETS_BUTTON_H -#include "gui/base/widgets/button.hpp" +#include "gui/widgets/widget.h" + +#include "listeners/focuslistener.h" +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" #include "listeners/widgetlistener.h" #include "localconsts.h" @@ -40,7 +87,10 @@ const std::string BUTTON_PLAY = "buttonplay.png"; * * \ingroup GUI */ -class Button final : public gcn::Button, +class Button final : public Widget, + public MouseListener, + public KeyListener, + public FocusListener, public WidgetListener { public: @@ -139,14 +189,79 @@ class Button final : public gcn::Button, void adjustSize(); - void setCaption(const std::string& caption); - void keyPressed(KeyEvent &keyEvent) override final; void keyReleased(KeyEvent &keyEvent) override final; bool isPressed2() const A_WARN_UNUSED; + /** + * Sets the caption of the button. It's advisable to call + * adjustSize after setting of the caption to adjust the + * button's size to fit the caption. + * + * @param caption The caption of the button. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption) + { mCaption = caption; } + + /** + * Gets the caption of the button. + * + * @return The caption of the button. + */ + const std::string& getCaption() const + { return mCaption; } + + /** + * Sets the alignment of the caption. The alignment is relative + * to the center of the button. + * + * @param alignment The alignment of the caption. + * @see getAlignment, Graphics + */ + void setAlignment(Graphics::Alignment alignment) + { mAlignment = alignment; } + + /** + * Gets the alignment of the caption. + * + * @return The alignment of the caption. + * @see setAlignment, Graphics + */ + Graphics::Alignment getAlignment() const + { return mAlignment; } + + /** + * Sets the spacing between the border of the button and its caption. + * + * @param spacing The default value for spacing is 4 and can be changed + * using this method. + * @see getSpacing + */ + void setSpacing(unsigned int spacing) + { mSpacing = spacing; } + + /** + * Gets the spacing between the border of the button and its caption. + * + * @return spacing. + * @see setSpacing + */ + unsigned int getSpacing() const + { return mSpacing; } + + void focusLost(const Event& event) override final; + + void mousePressed(MouseEvent& mouseEvent) override final; + + void mouseEntered(MouseEvent& mouseEvent) override final; + + void mouseExited(MouseEvent& mouseEvent) override final; + + void mouseDragged(MouseEvent& mouseEvent) override final; + enum { BUTTON_STANDARD = 0, // 0 @@ -157,12 +272,50 @@ class Button final : public gcn::Button, }; private: + /** + * Checks if the button is pressed. Convenient method to use + * when overloading the draw method of the button. + * + * @return True if the button is pressed, false otherwise. + */ + bool isPressed() const; + void init(); static Skin *button[BUTTON_COUNT]; /**< Button state graphics */ static int mInstances; /**< Number of button instances */ static float mAlpha; + /** + * Holds the caption of the button. + */ + std::string mCaption; + + /** + * True if the mouse is ontop of the button, false otherwise. + */ + bool mHasMouse; + + /** + * True if a key has been pressed, false otherwise. + */ + bool mKeyPressed; + + /** + * True if a mouse has been pressed, false otherwise. + */ + bool mMousePressed; + + /** + * Holds the alignment of the caption. + */ + Graphics::Alignment mAlignment; + + /** + * Holds the spacing between the border and the caption. + */ + unsigned int mSpacing; + std::string mDescription; ImageCollection *mVertexes2; Color mEnabledColor; diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 9fb63b2e8..f01495bcf 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -20,12 +20,53 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/checkbox.h" #include "client.h" -#include "events/keyevent.h" - #include "input/keydata.h" #include "resources/image.h" @@ -44,7 +85,11 @@ CheckBox::CheckBox(const Widget2 *const widget, const bool selected, ActionListener *const listener, const std::string &restrict eventId) : - gcn::CheckBox(widget, caption, selected), + Widget(widget), + MouseListener(), + KeyListener(), + mSelected(selected), + mCaption(), mPadding(0), mImagePadding(0), mImageSize(9), @@ -52,6 +97,12 @@ CheckBox::CheckBox(const Widget2 *const widget, mHasMouse(false), mDrawBox(true) { + setCaption(caption); + + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + mForegroundColor2 = getThemeColor(Theme::CHECKBOX_OUTLINE); if (instances == 0) { @@ -200,3 +251,20 @@ void CheckBox::adjustSize() setWidth(mImagePadding + mImageSize + mSpacing + getFont()->getWidth(mCaption) + mPadding); } + +void CheckBox::mouseClicked(MouseEvent& mouseEvent) +{ + if (mouseEvent.getButton() == MouseEvent::LEFT) + toggleSelected(); +} + +void CheckBox::mouseDragged(MouseEvent& mouseEvent) +{ + mouseEvent.consume(); +} + +void CheckBox::toggleSelected() +{ + mSelected = !mSelected; + distributeActionEvent(); +} diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h index 28eadb75c..5711e766f 100644 --- a/src/gui/widgets/checkbox.h +++ b/src/gui/widgets/checkbox.h @@ -20,10 +20,56 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_CHECKBOX_H #define GUI_WIDGETS_CHECKBOX_H -#include "gui/base/widgets/checkbox.hpp" +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" + +#include "gui/widgets/widget.h" #include "localconsts.h" @@ -34,7 +80,9 @@ class Skin; * * \ingroup GUI */ -class CheckBox final : public gcn::CheckBox +class CheckBox final : public Widget, + public MouseListener, + public KeyListener { public: /** @@ -82,7 +130,61 @@ class CheckBox final : public gcn::CheckBox void adjustSize(); + /** + * Checks if the check box is selected. + * + * @return True if the check box is selected, false otherwise. + * @see setSelected + */ + bool isSelected() const + { return mSelected; } + + /** + * Sets the check box to be selected or not. + * + * @param selected True if the check box should be set as selected. + * @see isSelected + */ + void setSelected(const bool selected) + { mSelected = selected; } + + /** + * Gets the caption of the check box. + * + * @return The caption of the check box. + * @see setCaption + */ + const std::string &getCaption() const + { return mCaption; } + + /** + * Sets the caption of the check box. It's advisable to call + * adjustSize after setting of the caption to adjust the + * check box's size to fit the caption. + * + * @param caption The caption of the check box. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption) + { mCaption = caption; } + + void mouseClicked(MouseEvent& mouseEvent) override final; + + void mouseDragged(MouseEvent& mouseEvent) override final; + private: + void toggleSelected(); + + /** + * True if the check box is selected, false otherwise. + */ + bool mSelected; + + /** + * Holds the caption of the check box. + */ + std::string mCaption; + int mPadding; int mImagePadding; int mImageSize; diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index 93d74dc8d..52d11c4e8 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -27,7 +27,7 @@ #include "debug.h" Container::Container(const Widget2 *const widget) : - gcn::Container(widget) + BasicContainer2(widget) { setOpaque(false); } diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h index 17d6b2af4..262d7327a 100644 --- a/src/gui/widgets/container.h +++ b/src/gui/widgets/container.h @@ -23,7 +23,7 @@ #ifndef GUI_WIDGETS_CONTAINER_H #define GUI_WIDGETS_CONTAINER_H -#include "gui/base/widgets/container.hpp" +#include "gui/widgets/basiccontainer2.h" /** * A widget container. @@ -34,7 +34,7 @@ * * This container is also non-opaque by default. */ -class Container : public gcn::Container +class Container : public BasicContainer2 { public: explicit Container(const Widget2 *const widget); diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index a77516c62..0ff1b17c9 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -24,7 +24,9 @@ #include "configuration.h" #include "main.h" -#include "gui/widgets/label.h" +#include "gui/widgets/browserbox.h" + +#include "input/inputmanager.h" #include "resources/image.h" #include "resources/imagehelper.h" @@ -35,9 +37,11 @@ Desktop::Desktop(const Widget2 *const widget) : Container(widget), + LinkHandler(), WidgetListener(), mWallpaper(nullptr), - mVersionLabel(nullptr), + mVersionLabel(new BrowserBox(this, BrowserBox::AUTO_WRAP, false, + "browserbox.xml")), mSkin(nullptr), mBackgroundColor(getThemeColor(Theme::BACKGROUND, 128)), mBackgroundGrayColor(getThemeColor(Theme::BACKGROUND_GRAY)), @@ -57,15 +61,16 @@ Desktop::Desktop(const Widget2 *const widget) : const std::string appName = branding.getValue("appName", std::string()); if (appName.empty()) { - mVersionLabel = new Label(this, FULL_VERSION); + mVersionLabel->addRow(FULL_VERSION); } else { - mVersionLabel = new Label(this, strprintf("%s (%s)", FULL_VERSION, + mVersionLabel->addRow(strprintf("%s (%s)", FULL_VERSION, appName.c_str())); } - - mVersionLabel->setBackgroundColor(getThemeColor(Theme::BACKGROUND, 128)); + mVersionLabel->addRow("copyright", + "(C) ManaPlus developers, http://manaplus.org"); + mVersionLabel->setLinkHandler(this); } Desktop::~Desktop() @@ -100,6 +105,7 @@ void Desktop::reloadWallpaper() void Desktop::widgetResized(const Event &event A_UNUSED) { + mVersionLabel->setSize(getWidth(), getHeight()); setBestFittingWallpaper(); } @@ -138,10 +144,6 @@ void Desktop::draw(Graphics *graphics) graphics->fillRectangle(Rect(0, 0, width, height)); } - // Draw a thin border under the application version... - graphics->setColor(mBackgroundColor); - graphics->fillRectangle(Rect(mVersionLabel->getDimension())); - Container::draw(graphics); BLOCK_END("Desktop::draw") } @@ -198,3 +200,9 @@ void Desktop::setBestFittingWallpaper() logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str()); } } + +void Desktop::handleLink(const std::string &link, MouseEvent *event A_UNUSED) +{ + if (link == "copyright") + inputManager.executeAction(Input::KEY_WINDOW_ABOUT); +} diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h index f0fd500ea..f3b0cd371 100644 --- a/src/gui/widgets/desktop.h +++ b/src/gui/widgets/desktop.h @@ -24,12 +24,14 @@ #include "gui/widgets/container.h" +#include "gui/widgets/linkhandler.h" + #include "listeners/widgetlistener.h" #include "localconsts.h" +class BrowserBox; class Image; -class Label; class Skin; /** @@ -46,7 +48,8 @@ class Skin; * \ingroup GUI */ class Desktop final : public Container, - private WidgetListener + public LinkHandler, + public WidgetListener { public: explicit Desktop(const Widget2 *const widget); @@ -66,11 +69,13 @@ class Desktop final : public Container, void postInit(); + void handleLink(const std::string &link, + MouseEvent *event) override final; private: void setBestFittingWallpaper(); Image *mWallpaper; - Label *mVersionLabel; + BrowserBox *mVersionLabel; Skin *mSkin; Color mBackgroundColor; Color mBackgroundGrayColor; diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index dfc17e17b..b1a3c4ac1 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -60,7 +60,7 @@ DropDown::DropDown(const Widget2 *const widget, ActionListener *const listener, const std::string &eventId): ActionListener(), - gcn::BasicContainer(widget), + BasicContainer(widget), KeyListener(), MouseListener(), FocusListener(), diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 8e463a2c1..2208880b3 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -23,7 +23,7 @@ #ifndef GUI_WIDGETS_DROPDOWN_H #define GUI_WIDGETS_DROPDOWN_H -#include "gui/base/basiccontainer.hpp" +#include "gui/widgets/basiccontainer.h" #include "listeners/actionlistener.h" #include "listeners/focuslistener.h" @@ -46,7 +46,7 @@ class Skin; * your list. */ class DropDown final : public ActionListener, - public gcn::BasicContainer, + public BasicContainer, public KeyListener, public MouseListener, public FocusListener, diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index 70ebb77d6..128281fe9 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -101,7 +101,7 @@ GuiTable::GuiTable(const Widget2 *const widget, KeyListener(), mModel(nullptr), mTopWidget(nullptr), - mActionListeners(), + mActionListeners2(), mHighlightColor(getThemeColor(Theme::HIGHLIGHT)), mSelectedRow(-1), mSelectedColumn(-1), @@ -266,8 +266,8 @@ void GuiTable::setSelectedColumn(const int selected) void GuiTable::uninstallActionListeners() { - delete_all(mActionListeners); - mActionListeners.clear(); + delete_all(mActionListeners2); + mActionListeners2.clear(); } void GuiTable::installActionListeners() @@ -285,7 +285,7 @@ void GuiTable::installActionListeners() Widget *const widget = mModel->getElementAt(row, column); if (widget) { - mActionListeners.push_back(new GuiTableActionListener( + mActionListeners2.push_back(new GuiTableActionListener( this, widget, row, column)); } } diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h index fb0c34784..7cec854a8 100644 --- a/src/gui/widgets/guitable.h +++ b/src/gui/widgets/guitable.h @@ -183,7 +183,7 @@ private: Widget *mTopWidget; /** Vector for compactness; used as a list in practice. */ - std::vector<GuiTableActionListener *> mActionListeners; + std::vector<GuiTableActionListener *> mActionListeners2; /** * Holds the background color of the table. diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 56c949964..b500ec7bb 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -19,6 +19,49 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/label.h" #include "gui/font.h" @@ -30,7 +73,9 @@ Skin *Label::mSkin = nullptr; int Label::mInstances = 0; Label::Label(const Widget2 *const widget) : - gcn::Label(widget), + Widget(widget), + mCaption(), + mAlignment(Graphics::LEFT), mPadding(0) { init(); @@ -38,9 +83,17 @@ Label::Label(const Widget2 *const widget) : Label::Label(const Widget2 *const widget, const std::string &caption) : - gcn::Label(widget, caption), + Widget(widget), + mCaption(caption), + mAlignment(Graphics::LEFT), mPadding(0) { + const Font *const font = getFont(); + if (font) + { + setWidth(font->getWidth(caption)); + setHeight(font->getHeight()); + } init(); } diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h index 616f6cc79..d205ed77b 100644 --- a/src/gui/widgets/label.h +++ b/src/gui/widgets/label.h @@ -19,10 +19,53 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_LABEL_H #define GUI_WIDGETS_LABEL_H -#include "gui/base/widgets/label.hpp" +#include "gui/widgets/widget.h" #include "localconsts.h" @@ -34,7 +77,7 @@ class Skin; * * \ingroup GUI */ -class Label final : public gcn::Label +class Label final : public Widget { public: /** @@ -69,11 +112,61 @@ class Label final : public gcn::Label void resizeTo(const int maxSize, const int minSize); + /** + * Gets the caption of the label. + * + * @return The caption of the label. + * @see setCaption + */ + const std::string &getCaption() const + { return mCaption; } + + /** + * Sets the caption of the label. It's advisable to call + * adjustSize after setting of the caption to adjust the + * label's size to fit the caption. + * + * @param caption The caption of the label. + * @see getCaption, adjustSize + */ + void setCaption(const std::string& caption) + { mCaption = caption; } + + /** + * Sets the alignment of the caption. The alignment is relative + * to the center of the label. + * + * @param alignemnt The alignment of the caption of the label. + * @see getAlignment, Graphics + */ + void setAlignment(Graphics::Alignment alignment) + { mAlignment = alignment; } + + /** + * Gets the alignment of the caption. The alignment is relative to + * the center of the label. + * + * @return The alignment of caption of the label. + * @see setAlignmentm Graphics + */ + Graphics::Alignment getAlignment() const + { return mAlignment; } + static Skin *mSkin; static int mInstances; private: + /** + * Holds the caption of the label. + */ + std::string mCaption; + + /** + * Holds the alignment of the caption. + */ + Graphics::Alignment mAlignment; + int mPadding; }; diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 24722510b..668334fd5 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -24,7 +24,7 @@ #include "logger.h" -#include "gui/base/widgets/container.hpp" +#include "gui/widgets/basiccontainer2.h" #include <cassert> diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 288c282a0..27af0840d 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -27,13 +27,8 @@ #include <vector> +class BasicContainer2; class LayoutCell; - -namespace gcn -{ - class Container; -} - class Widget; /** @@ -42,7 +37,7 @@ class Widget; class ContainerPlacer final { public: - explicit ContainerPlacer(gcn::Container *c = nullptr, + explicit ContainerPlacer(BasicContainer2 *c = nullptr, LayoutCell *lc = nullptr) : mContainer(c), mCell(lc) {} @@ -66,7 +61,7 @@ class ContainerPlacer final const int w = 1, const int h = 1); private: - gcn::Container *mContainer; + BasicContainer2 *mContainer; LayoutCell *mCell; }; diff --git a/src/gui/widgets/layouthelper.cpp b/src/gui/widgets/layouthelper.cpp index c225c7543..a8cf28bea 100644 --- a/src/gui/widgets/layouthelper.cpp +++ b/src/gui/widgets/layouthelper.cpp @@ -22,11 +22,11 @@ #include "gui/widgets/layouthelper.h" -#include "gui/base/widgets/container.hpp" +#include "gui/widgets/basiccontainer2.h" #include "debug.h" -LayoutHelper::LayoutHelper(gcn::Container *const container) : +LayoutHelper::LayoutHelper(BasicContainer2 *const container) : WidgetListener(), mLayout(), mContainer(container) diff --git a/src/gui/widgets/layouthelper.h b/src/gui/widgets/layouthelper.h index 32e3d9e34..78e34f419 100644 --- a/src/gui/widgets/layouthelper.h +++ b/src/gui/widgets/layouthelper.h @@ -38,7 +38,7 @@ class LayoutHelper final : public WidgetListener /** * Constructor. */ - explicit LayoutHelper(gcn::Container *const container); + explicit LayoutHelper(BasicContainer2 *const container); A_DELETE_COPY(LayoutHelper) @@ -82,7 +82,7 @@ class LayoutHelper final : public WidgetListener private: Layout mLayout; /**< Layout handler */ - gcn::Container *mContainer; /**< Managed container */ + BasicContainer2 *mContainer; /**< Managed container */ }; #endif // GUI_WIDGETS_LAYOUTHELPER_H diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index c6e431634..6f0c192c6 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -20,22 +20,63 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/listbox.h" #include "client.h" -#include "events/keyevent.h" - #include "input/keydata.h" +#include "listeners/selectionlistener.h" + #include "gui/focushandler.h" #include "gui/font.h" #include "gui/gui.h" #include "gui/models/listmodel.h" -#include "render/graphics.h" - #include "debug.h" float ListBox::mAlpha = 1.0; @@ -43,7 +84,13 @@ float ListBox::mAlpha = 1.0; ListBox::ListBox(const Widget2 *const widget, ListModel *const listModel, const std::string &skin) : - gcn::ListBox(widget, listModel), + Widget(widget), + MouseListener(), + KeyListener(), + mSelected(-1), + mListModel(listModel), + mWrappingEnabled(false), + mSelectionListeners(), mHighlightColor(getThemeColor(Theme::HIGHLIGHT)), mForegroundSelectedColor(getThemeColor(Theme::LISTBOX_SELECTED)), mForegroundSelectedColor2(getThemeColor(Theme::LISTBOX_SELECTED_OUTLINE)), @@ -56,6 +103,11 @@ ListBox::ListBox(const Widget2 *const widget, mDistributeMousePressed(true), mCenterText(false) { + setWidth(100); + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + mForegroundColor = getThemeColor(Theme::LISTBOX); mForegroundColor2 = getThemeColor(Theme::LISTBOX_OUTLINE); @@ -313,3 +365,59 @@ int ListBox::getSelectionByMouse(const int y) const return -1; return (y - mPadding) / getRowHeight(); } + +void ListBox::setSelected(const int selected) +{ + if (!mListModel) + { + mSelected = -1; + } + else + { + if (selected < 0) + mSelected = -1; + else if (selected >= mListModel->getNumberOfElements()) + mSelected = mListModel->getNumberOfElements() - 1; + else + mSelected = selected; + } + + Rect scroll; + + if (mSelected < 0) + scroll.y = 0; + else + scroll.y = getRowHeight() * mSelected; + + scroll.height = getRowHeight(); + showPart(scroll); + + distributeValueChangedEvent(); +} + +void ListBox::setListModel(ListModel *const listModel) +{ + mSelected = -1; + mListModel = listModel; + adjustSize(); +} + +void ListBox::addSelectionListener(SelectionListener *const selectionListener) +{ + mSelectionListeners.push_back(selectionListener); +} + +void ListBox::removeSelectionListener(SelectionListener *const + selectionListener) +{ + mSelectionListeners.remove(selectionListener); +} + +void ListBox::distributeValueChangedEvent() +{ + FOR_EACH (SelectionListenerIterator, iter, mSelectionListeners) + { + SelectionEvent event(this); + (*iter)->valueChanged(event); + } +} diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index 64faa6eb5..f784b3237 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -20,12 +20,58 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_LISTBOX_H #define GUI_WIDGETS_LISTBOX_H #include "gui/color.h" -#include "gui/base/widgets/listbox.hpp" +#include "gui/widgets/widget.h" + +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" #include "localconsts.h" @@ -33,6 +79,7 @@ class Skin; class KeyEvent; class ListModel; class MouseEvent; +class SelectionListener; class Widget2; /** @@ -42,7 +89,9 @@ class Widget2; * * \ingroup GUI */ -class ListBox : public gcn::ListBox +class ListBox : public Widget, + public MouseListener, + public KeyListener { public: /** @@ -103,13 +152,137 @@ class ListBox : public gcn::ListBox int getPressedIndex() const { return mPressedIndex; } - unsigned int getRowHeight() const override A_WARN_UNUSED + virtual unsigned int getRowHeight() const A_WARN_UNUSED { return mRowHeight; } void setRowHeight(unsigned int n) { mRowHeight = n; } + /** + * Gets the selected item as an index in the list model. + * + * @return the selected item as an index in the list model. + * @see setSelected + */ + int getSelected() const + { return mSelected; } + + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(const int selected); + + /** + * Sets the list model to use. + * + * @param listModel the list model to use. + * @see getListModel + */ + void setListModel(ListModel *listModel); + + /** + * Gets the list model used. + * + * @return the list model used. + * @see setListModel + */ + ListModel *getListModel() const + { return mListModel; } + + /** + * Checks whether the list box wraps when selecting items with a + * keyboard. + * + * Wrapping means that the selection of items will be wrapped. That is, + * if the first item is selected and up is pressed, the last item will + * get selected. If the last item is selected and down is pressed, the + * first item will get selected. + * + * @return true if wrapping is enabled, fasle otherwise. + * @see setWrappingEnabled + */ + bool isWrappingEnabled() const + { return mWrappingEnabled; } + + /** + * Sets the list box to wrap or not when selecting items with a + * keyboard. + * + * Wrapping means that the selection of items will be wrapped. That is, + * if the first item is selected and up is pressed, the last item will + * get selected. If the last item is selected and down is pressed, the + * first item will get selected. + * + * @see isWrappingEnabled + */ + void setWrappingEnabled(const bool wrappingEnabled) + { mWrappingEnabled = wrappingEnabled; } + + /** + * Adds a selection listener to the list box. When the selection + * changes an event will be sent to all selection listeners of the + * list box. + * + * If you delete your selection listener, be sure to also remove it + * using removeSelectionListener(). + * + * @param selectionListener The selection listener to add. + * @since 0.8.0 + */ + void addSelectionListener(SelectionListener *const selectionListener); + + /** + * Removes a selection listener from the list box. + * + * @param selectionListener The selection listener to remove. + * @since 0.8.0 + */ + void removeSelectionListener(SelectionListener *const + selectionListener); + + /** + * Distributes a value changed event to all selection listeners + * of the list box. + * + * @since 0.8.0 + */ + void distributeValueChangedEvent(); + protected: + /** + * The selected item as an index in the list model. + */ + int mSelected; + + /** + * The list model to use. + */ + ListModel *mListModel; + + /** + * True if wrapping is enabled, false otherwise. + */ + bool mWrappingEnabled; + + /** + * Typdef. + */ + typedef std::list<SelectionListener*> SelectionListenerList; + + /** + * The selection listeners of the list box. + */ + SelectionListenerList mSelectionListeners; + + /** + * Typedef. + */ + typedef SelectionListenerList::iterator SelectionListenerIterator; + Color mHighlightColor; Color mForegroundSelectedColor; Color mForegroundSelectedColor2; diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index 7ef543511..2ba452620 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -36,7 +36,8 @@ PlayerBox::PlayerBox(Widget2 *const widget, Being *const being, const std::string &skin, const std::string &selectedSkin) : - ScrollArea(widget), + Widget(widget), + MouseListener(), mBeing(being), mAlpha(1.0), mBackground(), @@ -54,7 +55,8 @@ PlayerBox::PlayerBox(Widget2 *const widget, PlayerBox::PlayerBox(Widget2 *const widget, const std::string &skin, const std::string &selectedSkin) : - ScrollArea(widget), + Widget(widget), + MouseListener(), mBeing(nullptr), mAlpha(1.0), mBackground(), @@ -82,6 +84,7 @@ PlayerBox::~PlayerBox() void PlayerBox::init(std::string name, std::string selectedName) { setFrameSize(2); + addMouseListener(this); Theme *const theme = Theme::instance(); if (theme) @@ -153,10 +156,10 @@ void PlayerBox::drawFrame(Graphics *graphics) void PlayerBox::mouseReleased(MouseEvent& event) { - ScrollArea::mouseReleased(event); if (event.getButton() == MouseEvent::LEFT) { if (!mActionEventId.empty()) distributeActionEvent(); + event.consume(); } } diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h index 7481dc9db..1a9067378 100644 --- a/src/gui/widgets/playerbox.h +++ b/src/gui/widgets/playerbox.h @@ -23,7 +23,9 @@ #ifndef GUI_WIDGETS_PLAYERBOX_H #define GUI_WIDGETS_PLAYERBOX_H -#include "gui/base/widgets/scrollarea.hpp" +#include "gui/widgets/widget.h" + +#include "listeners/mouselistener.h" #include "localconsts.h" @@ -35,7 +37,8 @@ class Skin; * * \ingroup GUI */ -class PlayerBox final : public gcn::ScrollArea +class PlayerBox final : public Widget, + public MouseListener { public: /** diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index bb9ae46f9..411216455 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -20,12 +20,53 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/radiobutton.h" #include "client.h" -#include "events/keyevent.h" - #include "input/keydata.h" #include "resources/image.h" @@ -39,17 +80,32 @@ int RadioButton::instances = 0; Skin *RadioButton::mSkin = nullptr; float RadioButton::mAlpha = 1.0; +RadioButton::GroupMap RadioButton::mGroupMap; + RadioButton::RadioButton(const Widget2 *const widget, const std::string &restrict caption, const std::string &restrict group, const bool marked): - gcn::RadioButton(widget, caption, group, marked), + Widget(widget), + MouseListener(), + KeyListener(), + mSelected(false), + mCaption(), + mGroup(), mPadding(0), mImagePadding(0), mImageSize(9), mSpacing(2), mHasMouse(false) { + setCaption(caption); + setGroup(group); + setSelected(marked); + + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + mForegroundColor = getThemeColor(Theme::RADIOBUTTON); mForegroundColor2 = getThemeColor(Theme::RADIOBUTTON_OUTLINE); if (instances == 0) @@ -77,6 +133,8 @@ RadioButton::RadioButton(const Widget2 *const widget, RadioButton::~RadioButton() { + setGroup(""); + if (gui) gui->removeDragged(this); @@ -196,3 +254,57 @@ void RadioButton::adjustSize() setWidth(mImagePadding + mImageSize + mSpacing + font->getWidth(mCaption) + mPadding); } + +void RadioButton::setSelected(const bool selected) +{ + if (selected && !mGroup.empty()) + { + for (GroupIterator iter = mGroupMap.lower_bound(mGroup), + iterEnd = mGroupMap.upper_bound(mGroup); + iter != iterEnd; + ++ iter) + { + if (iter->second && iter->second->isSelected()) + iter->second->setSelected(false); + } + } + + mSelected = selected; +} + +void RadioButton::mouseClicked(MouseEvent& mouseEvent) +{ + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + setSelected(true); + distributeActionEvent(); + } +} + +void RadioButton::mouseDragged(MouseEvent& mouseEvent) +{ + mouseEvent.consume(); +} + +void RadioButton::setGroup(const std::string &group) +{ + if (mGroup != "") + { + for (GroupIterator iter = mGroupMap.lower_bound(mGroup), + iterEnd = mGroupMap.upper_bound(mGroup); + iter != iterEnd; + ++ iter) + { + if (iter->second == this) + { + mGroupMap.erase(iter); + break; + } + } + } + + if (!group.empty()) + mGroupMap.insert(std::pair<std::string, RadioButton *>(group, this)); + + mGroup = group; +} diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h index 2deb9a772..5aa0d9289 100644 --- a/src/gui/widgets/radiobutton.h +++ b/src/gui/widgets/radiobutton.h @@ -20,10 +20,56 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_RADIOBUTTON_H #define GUI_WIDGETS_RADIOBUTTON_H -#include "gui/base/widgets/radiobutton.hpp" +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" + +#include "gui/widgets/widget.h" #include "localconsts.h" @@ -32,7 +78,10 @@ class Skin; /** * Guichan based RadioButton with custom look */ -class RadioButton final : public gcn::RadioButton +class RadioButton final : public Widget, + public MouseListener, + public KeyListener + { public: /** @@ -53,7 +102,7 @@ class RadioButton final : public gcn::RadioButton /** * Draws the radiobutton, not the caption. */ - void drawBox(Graphics* graphics) override final; + void drawBox(Graphics* graphics); /** * Implementation of the draw methods. @@ -77,10 +126,102 @@ class RadioButton final : public gcn::RadioButton void adjustSize(); + /** + * Checks if the radio button is selected. + * + * @return True if the radio button is selecte, false otherwise. + * @see setSelected + */ + bool isSelected() const + { return mSelected; } + + /** + * Sets the radio button to selected or not. + * + * @param selected True if the radio button should be selected, + * false otherwise. + * @see isSelected + */ + void setSelected(const bool selected); + + /** + * Gets the caption of the radio button. + * + * @return The caption of the radio button. + * @see setCaption + */ + const std::string &getCaption() const + { return mCaption; } + + /** + * Sets the caption of the radio button. It's advisable to call + * adjustSize after setting of the caption to adjust the + * radio button's size to fit the caption. + * + * @param caption The caption of the radio button. + * @see getCaption, adjustSize + */ + void setCaption(const std::string &caption) + { mCaption = caption; } + + void mouseClicked(MouseEvent& mouseEvent) override final; + + void mouseDragged(MouseEvent& mouseEvent) override final; + + /** + * Sets the group the radio button should belong to. Note that + * a radio button group is unique per application, not per Gui object + * as the group is stored in a static map. + * + * @param group The name of the group. + * @see getGroup + */ + void setGroup(const std::string &group); + + /** + * Gets the group the radio button belongs to. + * + * @return The group the radio button belongs to. + * @see setGroup + */ + const std::string &getGroup() const + { return mGroup; } + private: static int instances; static Skin *mSkin; static float mAlpha; + + /** + * True if the radio button is selected, false otherwise. + */ + bool mSelected; + + /** + * Holds the caption of the radio button. + */ + std::string mCaption; + + /** + * Holds the group of the radio button. + */ + std::string mGroup; + + /** + * Typdef. + */ + typedef std::multimap<std::string, RadioButton *> GroupMap; + + /** + * Typdef. + */ + typedef GroupMap::iterator GroupIterator; + + /** + * Holds all available radio button groups. + */ + static GroupMap mGroupMap; + int mPadding; int mImagePadding; int mImageSize; diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index dcc3a871b..47b8b0985 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -20,6 +20,49 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/scrollarea.h" #include "client.h" @@ -53,21 +96,44 @@ ScrollArea::ScrollArea(Widget2 *const widget2, Widget *const widget, const bool opaque, const std::string &skin) : - gcn::ScrollArea(widget2, widget), + BasicContainer(widget2), + MouseListener(), WidgetListener(), + mVertexes(new ImageCollection), + mVertexes2(new ImageCollection), + mHPolicy(SHOW_AUTO), + mVPolicy(SHOW_AUTO), + mVScroll(0), + mHScroll(0), + mScrollbarWidth(12), + mUpButtonScrollAmount(10), + mDownButtonScrollAmount(10), + mLeftButtonScrollAmount(10), + mRightButtonScrollAmount(10), + mHorizontalMarkerDragOffset(0), + mVerticalMarkerDragOffset(0), mX(0), mY(0), mClickX(0), mClickY(0), - mVertexes(new ImageCollection), - mVertexes2(new ImageCollection), mXOffset(0), mYOffset(0), mDrawWidth(0), mDrawHeight(0), + mVBarVisible(false), + mHBarVisible(false), + mUpButtonPressed(false), + mDownButtonPressed(false), + mLeftButtonPressed(false), + mRightButtonPressed(false), + mIsVerticalMarkerDragged(false), + mIsHorizontalMarkerDragged(false), + mOpaque(true), mHasMouse(false), mRedraw(true) { + setContent(widget); + addMouseListener(this); mOpaque = opaque; init(skin); } @@ -102,6 +168,8 @@ ScrollArea::~ScrollArea() mVertexes = nullptr; delete mVertexes2; mVertexes2 = nullptr; + + setContent(nullptr); } void ScrollArea::init(std::string skinName) @@ -178,20 +246,30 @@ void ScrollArea::logic() return; } - gcn::ScrollArea::logic(); + checkPolicies(); + + setVerticalScrollAmount(getVerticalScrollAmount()); + setHorizontalScrollAmount(getHorizontalScrollAmount()); + Widget *const content = getContent(); + if (content) + { + const int frameSize = content->getFrameSize(); + content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize); + content->logic(); + } // When no scrollbar in a certain direction, adapt content size to match // the content dimension exactly. if (content) { const unsigned int frameSize = 2 * content->getFrameSize(); - if (mHPolicy == gcn::ScrollArea::SHOW_NEVER) + if (mHPolicy == ScrollArea::SHOW_NEVER) { content->setWidth((mVBarVisible ? (mDimension.width - mScrollbarWidth) : mDimension.width) - frameSize); } - if (mVPolicy == gcn::ScrollArea::SHOW_NEVER) + if (mVPolicy == ScrollArea::SHOW_NEVER) { content->setHeight((mHBarVisible ? (mDimension.height - mScrollbarWidth) : mDimension.height) - frameSize); @@ -377,11 +455,9 @@ void ScrollArea::setOpaque(bool opaque) setFrameSize(mOpaque ? 2 : 0); } -void ScrollArea::drawButton(Graphics *const graphics, - const BUTTON_DIR dir) +Image *ScrollArea::getImageByState(Rect &dim, const BUTTON_DIR dir) { int state = 0; - Rect dim; switch (dir) { @@ -405,52 +481,35 @@ void ScrollArea::drawButton(Graphics *const graphics, default: logger->log("ScrollArea::drawButton unknown dir: " + toString(static_cast<unsigned>(dir))); - return; + return nullptr; } + return buttons[dir][state]; +} - if (buttons[dir][state]) - graphics->drawImage(buttons[dir][state], dim.x, dim.y); +void ScrollArea::drawButton(Graphics *const graphics, + const BUTTON_DIR dir) +{ + Rect dim; + const Image *const image = getImageByState(dim, dir); + + if (image) + graphics->drawImage(image, dim.x, dim.y); } void ScrollArea::calcButton(Graphics *const graphics, const BUTTON_DIR dir) { - int state = 0; Rect dim; + const Image *const image = getImageByState(dim, dir); - switch (dir) - { - case UP: - state = mUpButtonPressed ? 1 : 0; - dim = getUpButtonDimension(); - break; - case DOWN: - state = mDownButtonPressed ? 1 : 0; - dim = getDownButtonDimension(); - break; - case LEFT: - state = mLeftButtonPressed ? 1 : 0; - dim = getLeftButtonDimension(); - break; - case RIGHT: - state = mRightButtonPressed ? 1 : 0; - dim = getRightButtonDimension(); - break; - case BUTTONS_DIR: - default: - logger->log("ScrollArea::drawButton unknown dir: " - + toString(static_cast<unsigned>(dir))); - return; - } - - if (buttons[dir][state]) + if (image) { static_cast<Graphics*>(graphics)->calcTileCollection( - mVertexes, buttons[dir][state], dim.x, dim.y); + mVertexes, image, dim.x, dim.y); } } -void ScrollArea::drawVBar(Graphics *const graphics) +void ScrollArea::drawVBar(Graphics *const graphics) const { const Rect &dim = getVerticalBarDimension(); @@ -500,7 +559,7 @@ void ScrollArea::calcVBar(Graphics *const graphics) } } -void ScrollArea::drawHBar(Graphics *const graphics) +void ScrollArea::drawHBar(Graphics *const graphics) const { const Rect &dim = getHorizontalBarDimension(); @@ -803,7 +862,13 @@ void ScrollArea::mouseReleased(MouseEvent& event) event.consume(); } } - gcn::ScrollArea::mouseReleased(event); + mUpButtonPressed = false; + mDownButtonPressed = false; + mLeftButtonPressed = false; + mRightButtonPressed = false; + mIsHorizontalMarkerDragged = false; + mIsVerticalMarkerDragged = false; + event.consume(); mRedraw = true; } @@ -1066,3 +1131,290 @@ Rect ScrollArea::getRightButtonDimension() const mScrollbarWidth, mScrollbarWidth); } + +void ScrollArea::setContent(Widget* widget) +{ + if (widget) + { + clear(); + add(widget); + widget->setPosition(0, 0); + } + else + { + clear(); + } + + checkPolicies(); +} + +Widget* ScrollArea::getContent() +{ + if (!mWidgets.empty()) + return *mWidgets.begin(); + + return nullptr; +} + +void ScrollArea::setHorizontalScrollPolicy(const ScrollPolicy hPolicy) +{ + mHPolicy = hPolicy; + checkPolicies(); +} + +void ScrollArea::setVerticalScrollPolicy(const ScrollPolicy vPolicy) +{ + mVPolicy = vPolicy; + checkPolicies(); +} + +void ScrollArea::setScrollPolicy(const ScrollPolicy hPolicy, + const ScrollPolicy vPolicy) +{ + mHPolicy = hPolicy; + mVPolicy = vPolicy; + checkPolicies(); +} + +void ScrollArea::setVerticalScrollAmount(const int vScroll) +{ + const int max = getVerticalMaxScroll(); + + mVScroll = vScroll; + + if (vScroll > max) + mVScroll = max; + + if (vScroll < 0) + mVScroll = 0; +} + +void ScrollArea::setHorizontalScrollAmount(int hScroll) +{ + const int max = getHorizontalMaxScroll(); + + mHScroll = hScroll; + + if (hScroll > max) + mHScroll = max; + else if (hScroll < 0) + mHScroll = 0; +} + +void ScrollArea::setScrollAmount(const int hScroll, const int vScroll) +{ + setHorizontalScrollAmount(hScroll); + setVerticalScrollAmount(vScroll); +} + +int ScrollArea::getHorizontalMaxScroll() +{ + checkPolicies(); + + const Widget *const content = getContent(); + if (!content) + return 0; + + const int value = content->getWidth() - getChildrenArea().width + + 2 * content->getFrameSize(); + + if (value < 0) + return 0; + + return value; +} + +int ScrollArea::getVerticalMaxScroll() +{ + checkPolicies(); + + const Widget *const content = getContent(); + if (!content) + return 0; + + int value; + + value = content->getHeight() - getChildrenArea().height + + 2 * content->getFrameSize(); + + if (value < 0) + return 0; + + return value; +} + +void ScrollArea::setScrollbarWidth(const int width) +{ + if (width > 0) + mScrollbarWidth = width; +} + +void ScrollArea::showWidgetPart(Widget *const widget, Rect area) +{ + const Widget *const content = getContent(); + if (widget != content) + return; + + BasicContainer::showWidgetPart(widget, area); + + setHorizontalScrollAmount(content->getFrameSize() + - content->getX()); + setVerticalScrollAmount(content->getFrameSize() + - content->getY()); +} + +Rect ScrollArea::getChildrenArea() +{ + const Rect area = Rect(0, 0, + mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(), + mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight()); + + if (area.width < 0 || area.height < 0) + return Rect(); + + return area; +} + +Widget *ScrollArea::getWidgetAt(int x, int y) +{ + if (getChildrenArea().isPointInRect(x, y)) + return getContent(); + + return nullptr; +} + +void ScrollArea::setWidth(int width) +{ + Widget::setWidth(width); + checkPolicies(); +} + +void ScrollArea::setHeight(int height) +{ + Widget::setHeight(height); + checkPolicies(); +} + +void ScrollArea::setDimension(const Rect& dimension) +{ + Widget::setDimension(dimension); + checkPolicies(); +} + +void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent) +{ + if (mouseEvent.isConsumed()) + return; + + setVerticalScrollAmount(getVerticalScrollAmount() + - getChildrenArea().height / 8); + + mouseEvent.consume(); +} + +void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent) +{ + if (mouseEvent.isConsumed()) + return; + + setVerticalScrollAmount(getVerticalScrollAmount() + + getChildrenArea().height / 8); + + mouseEvent.consume(); +} + +void ScrollArea::checkPolicies() +{ + const int w = getWidth(); + const int h = getHeight(); + + mHBarVisible = false; + mVBarVisible = false; + + const Widget *const content = getContent(); + if (!content) + { + mHBarVisible = (mHPolicy == SHOW_ALWAYS); + mVBarVisible = (mVPolicy == SHOW_ALWAYS); + return; + } + + if (mHPolicy == SHOW_AUTO && + mVPolicy == SHOW_AUTO) + { + if (content->getWidth() <= w + && content->getHeight() <= h) + { + mHBarVisible = false; + mVBarVisible = false; + } + + if (content->getWidth() > w) + { + mHBarVisible = true; + } + + if ((content->getHeight() > h) + || (mHBarVisible && content->getHeight() + > h - mScrollbarWidth)) + { + mVBarVisible = true; + } + + if (mVBarVisible && content->getWidth() > w - mScrollbarWidth) + mHBarVisible = true; + + return; + } + + switch (mHPolicy) + { + case SHOW_NEVER: + mHBarVisible = false; + break; + + case SHOW_ALWAYS: + mHBarVisible = true; + break; + + case SHOW_AUTO: + if (mVPolicy == SHOW_NEVER) + { + mHBarVisible = (content->getWidth() > w); + } + else // (mVPolicy == SHOW_ALWAYS) + { + mHBarVisible = (content->getWidth() + > w - mScrollbarWidth); + } + break; + + default: + break; + } + + switch (mVPolicy) + { + case SHOW_NEVER: + mVBarVisible = false; + break; + + case SHOW_ALWAYS: + mVBarVisible = true; + break; + + case SHOW_AUTO: + if (mHPolicy == SHOW_NEVER) + { + mVBarVisible = (content->getHeight() > h); + } + else // (mHPolicy == SHOW_ALWAYS) + { + mVBarVisible = (content->getHeight() + > h - mScrollbarWidth); + } + break; + default: + break; + } +} diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 7d2b39a96..0b0cae2c3 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -20,11 +20,55 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_SCROLLAREA_H #define GUI_WIDGETS_SCROLLAREA_H -#include "gui/base/widgets/scrollarea.hpp" +#include "gui/widgets/basiccontainer.h" +#include "listeners/mouselistener.h" #include "listeners/widgetlistener.h" #include "localconsts.h" @@ -41,11 +85,28 @@ class ImageCollection; * * \ingroup GUI */ -class ScrollArea final : public gcn::ScrollArea, +class ScrollArea final : public BasicContainer, + public MouseListener, public WidgetListener { public: /** + * Scrollpolicies for the horizontal and vertical scrollbar. + * The policies are: + * + * SHOW_ALWAYS - Always show the scrollbars no matter what. + * SHOW_NEVER - Never show the scrollbars no matter waht. + * SHOW_AUTO - Show the scrollbars only when needed. That is if the + * content grows larger then the ScrollArea. + */ + enum ScrollPolicy + { + SHOW_ALWAYS = 0, + SHOW_NEVER, + SHOW_AUTO + }; + + /** * Constructor. * * @param content the initial content to show in the scroll area @@ -135,6 +196,234 @@ class ScrollArea final : public gcn::ScrollArea, Rect getRightButtonDimension() const; + /** + * Sets the content. + * + * @param widget The content of the scroll area. + */ + void setContent(Widget* widget); + + /** + * Gets the content. + * + * @return The content of the scroll area. + */ + Widget* getContent(); + + /** + * Sets the horizontal scrollbar policy. See enum with policies. + * + * @param hPolicy The policy for the horizontal scrollbar. + * @see getHorizontalScrollPolicy + */ + void setHorizontalScrollPolicy(const ScrollPolicy hPolicy); + + /** + * Gets the horizontal scrollbar policy. See enum with policies. + * + * @return The policy for the horizontal scrollbar policy. + * @see setHorizontalScrollPolicy, setScrollPolicy + */ + ScrollPolicy getHorizontalScrollPolicy() const + { return mHPolicy; } + + /** + * Sets the vertical scrollbar policy. See enum with policies. + * + * @param vPolicy The policy for the vertical scrollbar. + * @see getVerticalScrollPolicy + */ + void setVerticalScrollPolicy(const ScrollPolicy vPolicy); + + /** + * Gets the vertical scrollbar policy. See enum with policies. + * + * @return The policy for the vertical scrollbar. + * @see setVerticalScrollPolicy, setScrollPolicy + */ + ScrollPolicy getVerticalScrollPolicy() const + { return mVPolicy; } + + /** + * Sets the horizontal and vertical scrollbar policy. + * + * @param hPolicy The policy for the horizontal scrollbar. + * @param vPolicy The policy for the vertical scrollbar. + * @see getVerticalScrollPolicy, getHorizontalScrollPolicy + */ + void setScrollPolicy(const ScrollPolicy hPolicy, + const ScrollPolicy vPolicy); + + /** + * Sets the amount to scroll vertically. + * + * @param vScroll The amount to scroll. + * @see getVerticalScrollAmount + */ + void setVerticalScrollAmount(const int vScroll); + + /** + * Gets the amount that is scrolled vertically. + * + * @return The scroll amount on vertical scroll. + * @see setVerticalScrollAmount, setScrollAmount + */ + int getVerticalScrollAmount() const + { return mVScroll; } + + /** + * Sets the amount to scroll horizontally. + * + * @param hScroll The amount to scroll. + * @see getHorizontalScrollAmount + */ + void setHorizontalScrollAmount(int hScroll); + + /** + * Gets the amount that is scrolled horizontally. + * + * @return The scroll amount on horizontal scroll. + * @see setHorizontalScrollAmount, setScrollAmount + */ + int getHorizontalScrollAmount() const + { return mHScroll; } + + /** + * Sets the amount to scroll horizontally and vertically. + * + * @param hScroll The amount to scroll on horizontal scroll. + * @param vScroll The amount to scroll on vertical scroll. + * @see getHorizontalScrollAmount, getVerticalScrollAmount + */ + void setScrollAmount(const int hScroll, const int vScroll); + + /** + * Gets the maximum amount of horizontal scroll. + * + * @return The horizontal max scroll. + */ + int getHorizontalMaxScroll(); + + /** + * Gets the maximum amount of vertical scroll. + * + * @return The vertical max scroll. + */ + int getVerticalMaxScroll(); + + /** + * Sets the width of the scroll bars. + * + * @param width The width of the scroll bars. + * @see getScrollbarWidth + */ + void setScrollbarWidth(const int width); + + /** + * Gets the width of the scroll bars. + * + * @return the width of the ScrollBar. + * @see setScrollbarWidth + */ + int getScrollbarWidth() const + { return mScrollbarWidth; } + + /** + * Sets the amount to scroll in pixels when the left scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getLeftButtonScrollAmount + */ + void setLeftButtonScrollAmount(const int amount) + { mLeftButtonScrollAmount = amount; } + + /** + * Sets the amount to scroll in pixels when the right scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getRightButtonScrollAmount + */ + void setRightButtonScrollAmount(const int amount) + { mRightButtonScrollAmount = amount; } + + /** + * Sets the amount to scroll in pixels when the up scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getUpButtonScrollAmount + */ + void setUpButtonScrollAmount(const int amount) + { mUpButtonScrollAmount = amount; } + + /** + * Sets the amount to scroll in pixels when the down scroll button is + * pushed. + * + * @param amount The amount to scroll in pixels. + * @see getDownButtonScrollAmount + */ + void setDownButtonScrollAmount(const int amount) + { mDownButtonScrollAmount = amount; } + + /** + * Gets the amount to scroll in pixels when the left scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setLeftButtonScrollAmount + */ + int getLeftButtonScrollAmount() const + { return mLeftButtonScrollAmount; } + + /** + * Gets the amount to scroll in pixels when the right scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setRightButtonScrollAmount + */ + int getRightButtonScrollAmount() const + { return mRightButtonScrollAmount; } + + /** + * Gets the amount to scroll in pixels when the up scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setUpButtonScrollAmount + */ + int getUpButtonScrollAmount() const + { return mUpButtonScrollAmount; } + + /** + * Gets the amount to scroll in pixels when the down scroll button is + * pushed. + * + * @return The amount to scroll in pixels. + * @see setDownButtonScrollAmount + */ + int getDownButtonScrollAmount() const + { return mDownButtonScrollAmount; } + + void showWidgetPart(Widget *const widget, Rect area) override final; + + Rect getChildrenArea() override final; + + Widget *getWidgetAt(int x, int y) override final; + + void setWidth(int width); + + void setHeight(int height); + + void setDimension(const Rect& dimension); + + void mouseWheelMovedUp(MouseEvent& mouseEvent) override final; + + void mouseWheelMovedDown(MouseEvent& mouseEvent) override final; + protected: enum BUTTON_DIR { @@ -150,18 +439,25 @@ class ScrollArea final : public gcn::ScrollArea, */ void init(std::string skinName); + /** + * Checks the policies for the scroll bars. + */ + void checkPolicies(); + void drawButton(Graphics *const graphics, const BUTTON_DIR dir); void calcButton(Graphics *const graphics, const BUTTON_DIR dir); - void drawVBar(Graphics *const graphics) override final; - void drawHBar(Graphics *const graphics) override final; - void drawVMarker(Graphics *const graphics) override final; - void drawHMarker(Graphics *const graphics) override final; + void drawVBar(Graphics *const graphics) const; + void drawHBar(Graphics *const graphics) const; + void drawVMarker(Graphics *const graphics); + void drawHMarker(Graphics *const graphics); void calcVBar(Graphics *const graphics); void calcHBar(Graphics *const graphics); void calcVMarker(Graphics *const graphics); void calcHMarker(Graphics *const graphics); + Image *getImageByState(Rect &dim, const BUTTON_DIR dir); + void updateCalcFlag(Graphics *const graphics); static int instances; @@ -176,14 +472,119 @@ class ScrollArea final : public gcn::ScrollArea, static ImageRect hBackground; static Image *buttons[4][2]; - int mX, mY; - int mClickX, mClickY; ImageCollection *mVertexes; ImageCollection *mVertexes2; + + /** + * Holds the horizontal scroll bar policy. + */ + ScrollPolicy mHPolicy; + + /** + * Holds the vertical scroll bar policy. + */ + ScrollPolicy mVPolicy; + + /** + * Holds the vertical scroll amount. + */ + int mVScroll; + + /** + * Holds the horizontal scroll amount. + */ + int mHScroll; + + /** + * Holds the width of the scroll bars. + */ + int mScrollbarWidth; + + /** + * Holds the up button scroll amount. + */ + int mUpButtonScrollAmount; + + /** + * Holds the down button scroll amount. + */ + int mDownButtonScrollAmount; + + /** + * Holds the left button scroll amount. + */ + int mLeftButtonScrollAmount; + + /** + * Holds the right button scroll amount. + */ + int mRightButtonScrollAmount; + + /** + * Holds the horizontal markers drag offset. + */ + int mHorizontalMarkerDragOffset; + + /** + * Holds the vertical markers drag offset. + */ + int mVerticalMarkerDragOffset; + + int mX; + int mY; + int mClickX; + int mClickY; int mXOffset; int mYOffset; int mDrawWidth; int mDrawHeight; + + /** + * True if the vertical scroll bar is visible, false otherwise. + */ + bool mVBarVisible; + + /** + * True if the horizontal scroll bar is visible, false otherwise. + */ + bool mHBarVisible; + + /** + * True if the up button is pressed, false otherwise. + */ + bool mUpButtonPressed; + + /** + * True if the down button is pressed, false otherwise. + */ + bool mDownButtonPressed; + + /** + * True if the left button is pressed, false otherwise. + */ + bool mLeftButtonPressed; + + /** + * True if the right button is pressed, false otherwise. + */ + bool mRightButtonPressed; + + /** + * True if the vertical marked is dragged. + */ + bool mIsVerticalMarkerDragged; + + /** + * True if the horizontal marked is dragged. + */ + bool mIsHorizontalMarkerDragged; + + /** + * True if the scroll area should be opaque (that is + * display its background), false otherwise. + */ + bool mOpaque; + bool mHasMouse; bool mRedraw; }; diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 218efe8a2..4c32b0572 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -769,7 +769,7 @@ void SetupItemSlider::createControls() mSlider = new Slider(this, mMin, mMax); mSlider->setActionEventId(mEventName); mSlider->addActionListener(mParent); - mSlider->setValue2(atof(mValue.c_str())); + mSlider->setValue(atof(mValue.c_str())); mSlider->setHeight(30); mWidget = mSlider; @@ -798,7 +798,7 @@ void SetupItemSlider::toWidget() if (!mSlider) return; - mSlider->setValue2(atof(mValue.c_str())); + mSlider->setValue(atof(mValue.c_str())); } void SetupItemSlider::action(const ActionEvent &event A_UNUSED) @@ -893,7 +893,7 @@ void SetupItemSlider2::createControls() mSlider = new Slider(this, mMin, mMax); mSlider->setActionEventId(mEventName); mSlider->addActionListener(mParent); - mSlider->setValue2(atof(mValue.c_str())); + mSlider->setValue(atof(mValue.c_str())); mSlider->setHeight(30); mWidget = mSlider; @@ -952,7 +952,7 @@ void SetupItemSlider2::toWidget() int val = roundDouble(atof(mValue.c_str())); if (mInvert) val = mInvertValue - val; - mSlider->setValue2(val); + mSlider->setValue(val); updateLabel(); } diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 7a9b38050..700d31416 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -20,6 +20,49 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/slider.h" #include "client.h" @@ -47,8 +90,16 @@ static std::string const data[2] = Slider::Slider(Widget2 *const widget, const double scaleEnd) : - gcn::Slider(widget, scaleEnd), + Widget(widget), + MouseListener(), + KeyListener(), + mValue(0), + mStepLength(scaleEnd / 10), + mScaleStart(0), + mScaleEnd(scaleEnd), + mOrientation(HORIZONTAL), mVertexes(new ImageCollection), + mMarkerLength(10), mHasMouse(false), mRedraw(true) { @@ -58,8 +109,16 @@ Slider::Slider(Widget2 *const widget, Slider::Slider(Widget2 *const widget, const double scaleStart, const double scaleEnd) : - gcn::Slider(widget, scaleStart, scaleEnd), + Widget(widget), + MouseListener(), + KeyListener(), + mValue(scaleStart), + mStepLength((scaleEnd - scaleStart) / 10), + mScaleStart(scaleStart), + mScaleEnd(scaleEnd), + mOrientation(HORIZONTAL), mVertexes(new ImageCollection), + mMarkerLength(10), mHasMouse(false), mRedraw(true) { @@ -83,6 +142,12 @@ Slider::~Slider() void Slider::init() { + setFocusable(true); + setFrameSize(1); + + addMouseListener(this); + addKeyListener(this); + setFrameSize(0); // Load resources @@ -289,22 +354,18 @@ void Slider::mouseExited(MouseEvent& event A_UNUSED) void Slider::mousePressed(MouseEvent &mouseEvent) { + const int x = mouseEvent.getX(); + const int y = mouseEvent.getY(); + const int width = mDimension.width; + const int height = mDimension.height; + if (mouseEvent.getButton() == MouseEvent::LEFT - && mouseEvent.getX() >= 0 - && mouseEvent.getX() <= getWidth() - && mouseEvent.getY() >= 0 - && mouseEvent.getY() <= getHeight()) + && x >= 0 && x <= width && y >= 0 && y <= height) { - if (getOrientation() == HORIZONTAL) - { - setValue2(markerPositionToValue( - mouseEvent.getX() - getMarkerLength() / 2)); - } + if (mOrientation == HORIZONTAL) + setValue(markerPositionToValue(x - mMarkerLength / 2)); else - { - setValue2(markerPositionToValue(getHeight() - - mouseEvent.getY() - getMarkerLength() / 2)); - } + setValue(markerPositionToValue(height - y - mMarkerLength / 2)); distributeActionEvent(); } @@ -312,15 +373,14 @@ void Slider::mousePressed(MouseEvent &mouseEvent) void Slider::mouseDragged(MouseEvent &mouseEvent) { - if (getOrientation() == HORIZONTAL) + if (mOrientation == HORIZONTAL) { - setValue2(markerPositionToValue(mouseEvent.getX() - - getMarkerLength() / 2)); + setValue(markerPositionToValue(mouseEvent.getX() - mMarkerLength / 2)); } else { - setValue2(markerPositionToValue(getHeight() - - mouseEvent.getY() - getMarkerLength() / 2)); + setValue(markerPositionToValue( + mDimension.height - mouseEvent.getY() - mMarkerLength / 2)); } distributeActionEvent(); @@ -330,17 +390,15 @@ void Slider::mouseDragged(MouseEvent &mouseEvent) void Slider::mouseWheelMovedUp(MouseEvent &mouseEvent) { - setValue2(getValue() + getStepLength()); + setValue(mValue + mStepLength); distributeActionEvent(); - mouseEvent.consume(); } void Slider::mouseWheelMovedDown(MouseEvent &mouseEvent) { - setValue2(getValue() - getStepLength()); + setValue(mValue - mStepLength); distributeActionEvent(); - mouseEvent.consume(); } @@ -348,17 +406,17 @@ void Slider::keyPressed(KeyEvent& keyEvent) { const int action = keyEvent.getActionId(); - if (getOrientation() == HORIZONTAL) + if (mOrientation == HORIZONTAL) { if (action == Input::KEY_GUI_RIGHT) { - setValue2(getValue() + getStepLength()); + setValue(mValue + mStepLength); distributeActionEvent(); keyEvent.consume(); } else if (action == Input::KEY_GUI_LEFT) { - setValue2(getValue() - getStepLength()); + setValue(mValue - mStepLength); distributeActionEvent(); keyEvent.consume(); } @@ -367,21 +425,72 @@ void Slider::keyPressed(KeyEvent& keyEvent) { if (action == Input::KEY_GUI_UP) { - setValue2(getValue() + getStepLength()); + setValue(mValue + mStepLength); distributeActionEvent(); keyEvent.consume(); } else if (action == Input::KEY_GUI_DOWN) { - setValue2(getValue() - getStepLength()); + setValue(mValue - mStepLength); distributeActionEvent(); keyEvent.consume(); } } } -void Slider::setValue2(const double value) +void Slider::setScale(const double scaleStart, const double scaleEnd) +{ + mScaleStart = scaleStart; + mScaleEnd = scaleEnd; +} + +void Slider::setValue(const double value) { - setValue(value); mRedraw = true; + if (value > mScaleEnd) + { + mValue = mScaleEnd; + return; + } + + if (value < mScaleStart) + { + mValue = mScaleStart; + return; + } + + mValue = value; +} + +double Slider::markerPositionToValue(const int v) const +{ + int w; + if (mOrientation == HORIZONTAL) + w = mDimension.width; + else + w = mDimension.height; + + const double pos = v / (static_cast<double>(w) - mMarkerLength); + return (1.0 - pos) * mScaleStart + pos * mScaleEnd; +} + +int Slider::valueToMarkerPosition(const double value) const +{ + int v; + if (mOrientation == HORIZONTAL) + v = mDimension.width; + else + v = mDimension.height; + + const int w = static_cast<int>((v - mMarkerLength) + * (value - mScaleStart) + / (mScaleEnd - mScaleStart)); + + if (w < 0) + return 0; + + if (w > v - mMarkerLength) + return v - mMarkerLength; + + return w; } diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h index 2f21127d1..23d06de48 100644 --- a/src/gui/widgets/slider.h +++ b/src/gui/widgets/slider.h @@ -20,10 +20,56 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_SLIDER_H #define GUI_WIDGETS_SLIDER_H -#include "gui/base/widgets/slider.hpp" +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" + +#include "gui/widgets/widget.h" #include "localconsts.h" @@ -34,10 +80,22 @@ class ImageCollection; * * \ingroup GUI */ -class Slider final : public gcn::Slider +class Slider final : public Widget, + public MouseListener, + public KeyListener { public: /** + * Draw orientations for the slider. A slider can be drawn vertically or + * horizontally. + */ + enum Orientation + { + HORIZONTAL = 0, + VERTICAL + }; + + /** * Constructor with scale start equal to 0. */ explicit Slider(Widget2 *const widget, @@ -87,7 +145,125 @@ class Slider final : public gcn::Slider void keyPressed(KeyEvent& keyEvent) override final; - void setValue2(const double value); + /** + * Sets the scale of the slider. + * + * @param scaleStart The start value of the scale. + * @param scaleEnd tThe end of value the scale. + * @see getScaleStart, getScaleEnd + */ + void setScale(const double scaleStart, const double scaleEnd); + + /** + * Gets the start value of the scale. + * + * @return The start value of the scale. + * @see setScaleStart, setScale + */ + double getScaleStart() const + { return mScaleStart; } + + /** + * Sets the start value of the scale. + * + * @param scaleStart The start value of the scale. + * @see getScaleStart + */ + void setScaleStart(const double scaleStart) + { mScaleStart = scaleStart; } + + /** + * Gets the end value of the scale. + * + * @return The end value of the scale. + * @see setScaleEnd, setScale + */ + double getScaleEnd() const + { return mScaleEnd; } + + /** + * Sets the end value of the scale. + * + * @param scaleEnd The end value of the scale. + * @see getScaleEnd + */ + void setScaleEnd(const double scaleEnd) + { mScaleEnd = scaleEnd; } + + /** + * Sets the current selected value. + * + * @param value The current selected value. + * @see getValue + */ + void setValue(const double value); + + /** + * Gets the current selected value. + * + * @return The current selected value. + * @see setValue + */ + double getValue() const + { return mValue; } + + /** + * Gets the length of the marker. + * + * @return The length of the marker. + * @see setMarkerLength + */ + int getMarkerLength() const + { return mMarkerLength; } + + /** + * Sets the length of the marker. + * + * @param length The length for the marker. + * @see getMarkerLength + */ + void setMarkerLength(const int length) + { mMarkerLength = length; } + + /** + * Sets the orientation of the slider. A slider can be drawn vertically + * or horizontally. + * + * @param orientation The orientation of the slider. + * @see getOrientation + */ + void setOrientation(const Orientation orientation) + { mOrientation = orientation; } + + /** + * Gets the orientation of the slider. A slider can be drawn vertically + * or horizontally. + * + * @return The orientation of the slider. + * @see setOrientation + */ + Orientation getOrientation() const + { return mOrientation; } + + /** + * Sets the step length. The step length is used when the keys LEFT + * and RIGHT are pressed to step in the scale. + * + * @param length The step length. + * @see getStepLength + */ + void setStepLength(const double length) + { mStepLength = length; } + + /** + * Gets the step length. The step length is used when the keys LEFT + * and RIGHT are pressed to step in the scale. + * + * @return the step length. + * @see setStepLength + */ + double getStepLength() const + { return mStepLength; } enum SLIDER_ENUM { @@ -108,10 +284,70 @@ class Slider final : public gcn::Slider */ void init(); + /** + * Converts a marker position to a value in the scale. + * + * @param position The position to convert. + * @return A scale value corresponding to the position. + * @see valueToMarkerPosition + */ + double markerPositionToValue(const int position) const; + + /** + * Converts a value to a marker position. + * + * @param value The value to convert. + * @return A marker position corresponding to the value. + * @see markerPositionToValue + */ + int valueToMarkerPosition(const double value) const; + + /** + * Gets the marker position of the current selected value. + * + * @return The marker position of the current selected value. + */ + int getMarkerPosition() const + { return valueToMarkerPosition(getValue()); } + static ImageRect buttons[2]; static float mAlpha; static int mInstances; + + /** + * Holds the current selected value. + */ + double mValue; + + /** + * Holds the step length. The step length is used when the keys LEFT + * and RIGHT are pressed to step in the scale. + */ + double mStepLength; + + /** + * Holds the start value of the scale. + */ + double mScaleStart; + + /** + * Holds the end value of the scale. + */ + double mScaleEnd; + + /** + * Holds the orientation of the slider. A slider can be drawn + * vertically or horizontally. + */ + Orientation mOrientation; + ImageCollection *mVertexes; + + /** + * Holds the length of the marker. + */ + int mMarkerLength; + bool mHasMouse; bool mRedraw; }; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index d2bb24720..445f17982 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -75,19 +75,17 @@ #include "gui/widgets/scrollarea.h" #include "gui/widgets/tabs/tab.h" -#include "gui/base/widgets/container.hpp" - #include "debug.h" TabbedArea::TabbedArea(const Widget2 *const widget) : ActionListener(), - gcn::BasicContainer(widget), + BasicContainer(widget), KeyListener(), MouseListener(), WidgetListener(), mSelectedTab(nullptr), - mTabContainer(new gcn::Container(widget)), - mWidgetContainer(new gcn::Container(widget)), + mTabContainer(new BasicContainer2(widget)), + mWidgetContainer(new BasicContainer2(widget)), mTabsToDelete(), mTabs(), mTabsWidth(0), @@ -768,7 +766,7 @@ void TabbedArea::death(const Event &event) if (tab) removeTab(tab); else - gcn::BasicContainer::death(event); + BasicContainer::death(event); } void TabbedArea::selectNextTab() diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index dbaa4334b..0e7a032f0 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -70,7 +70,7 @@ #include "listeners/mouselistener.h" #include "listeners/widgetlistener.h" -#include "gui/base/widgets/container.hpp" +#include "gui/widgets/basiccontainer2.h" #include "listeners/actionlistener.h" @@ -82,7 +82,7 @@ class Tab; * A tabbed area, the same as the guichan tabbed area in 0.8, but extended */ class TabbedArea final : public ActionListener, - public gcn::BasicContainer, + public BasicContainer, public KeyListener, public MouseListener, public WidgetListener @@ -251,8 +251,8 @@ class TabbedArea final : public ActionListener, void updateTabsWidth(); Tab* mSelectedTab; - gcn::Container* mTabContainer; - gcn::Container* mWidgetContainer; + BasicContainer2* mTabContainer; + BasicContainer2* mWidgetContainer; std::vector<Tab*> mTabsToDelete; TabContainer mTabs; diff --git a/src/gui/widgets/tabs/chattab.cpp b/src/gui/widgets/tabs/chattab.cpp index fe979ae5a..8fe9d707b 100644 --- a/src/gui/widgets/tabs/chattab.cpp +++ b/src/gui/widgets/tabs/chattab.cpp @@ -72,8 +72,8 @@ ChatTab::ChatTab(const Widget2 *const widget, mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler); mTextOutput->setAlwaysUpdate(false); - mScrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, - gcn::ScrollArea::SHOW_ALWAYS); + mScrollArea->setScrollPolicy(ScrollArea::SHOW_NEVER, + ScrollArea::SHOW_ALWAYS); mScrollArea->setScrollAmount(0, 1); if (chatWindow) diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp index ac6bf2837..eb7e695f4 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -84,19 +84,19 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) : // TRANSLATORS: settings colors tab name setName(_("Colors")); mColorBox->addSelectionListener(this); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mPreview->setOpaque(false); // don't do anything with links mPreview->setLinkHandler(nullptr); mPreviewBox->setHeight(20); - mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, - gcn::ScrollArea::SHOW_NEVER); + mPreviewBox->setScrollPolicy(ScrollArea::SHOW_NEVER, + ScrollArea::SHOW_NEVER); mGradTypeSlider->setWidth(180); mGradTypeSlider->setActionEventId("slider_grad"); - mGradTypeSlider->setValue2(0); + mGradTypeSlider->setValue(0); mGradTypeSlider->addActionListener(this); mGradTypeSlider->setEnabled(false); @@ -128,7 +128,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) : mGradDelayText->setEnabled(false); mGradDelaySlider->setWidth(180); - mGradDelaySlider->setValue2(mGradDelayText->getValue()); + mGradDelaySlider->setValue(mGradDelayText->getValue()); mGradDelaySlider->setActionEventId("slider_graddelay"); mGradDelaySlider->addActionListener(this); mGradDelaySlider->setEnabled(false); @@ -139,7 +139,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) : mRedText->setEnabled(false); mRedSlider->setWidth(180); - mRedSlider->setValue2(mRedText->getValue()); + mRedSlider->setValue(mRedText->getValue()); mRedSlider->setActionEventId("slider_red"); mRedSlider->addActionListener(this); mRedSlider->setEnabled(false); @@ -150,7 +150,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) : mGreenText->setEnabled(false); mGreenSlider->setWidth(180); - mGreenSlider->setValue2(mGreenText->getValue()); + mGreenSlider->setValue(mGreenText->getValue()); mGreenSlider->setActionEventId("slider_green"); mGreenSlider->addActionListener(this); mGreenSlider->setEnabled(false); @@ -161,7 +161,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) : mBlueText->setEnabled(false); mBlueSlider->setWidth(180); - mBlueSlider->setValue2(mBlueText->getValue()); + mBlueSlider->setValue(mBlueText->getValue()); mBlueSlider->setActionEventId("slider_blue"); mBlueSlider->addActionListener(this); mBlueSlider->setEnabled(false); @@ -356,7 +356,7 @@ void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED) setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); - mGradTypeSlider->setValue2(grad); + mGradTypeSlider->setValue(grad); updateGradType(); mGradTypeSlider->setEnabled(true); } @@ -365,7 +365,7 @@ void Setup_Colors::setEntry(Slider *const s, TextField *const t, const int value) { if (s) - s->setValue2(value); + s->setValue(value); if (t) t->setText(toString(value)); } @@ -384,7 +384,7 @@ void Setup_Colors::cancel() userPalette->rollback(); const int type = userPalette->getColorTypeAt(mSelected); const Color *const col = &userPalette->getColor(type); - mGradTypeSlider->setValue2(userPalette->getGradientType(type)); + mGradTypeSlider->setValue(userPalette->getGradientType(type)); const int delay = userPalette->getGradientDelay(type); setEntry(mGradDelaySlider, mGradDelayText, delay); setEntry(mRedSlider, mRedText, col->r); diff --git a/src/gui/widgets/tabs/setup_players.cpp b/src/gui/widgets/tabs/setup_players.cpp index 01bb60f53..b04a25e22 100644 --- a/src/gui/widgets/tabs/setup_players.cpp +++ b/src/gui/widgets/tabs/setup_players.cpp @@ -100,5 +100,10 @@ Setup_Players::Setup_Players(const Widget2 *const widget) : new SetupItemCheckBox(_("Use special diagonal speed in players moving"), "", "useDiagonalSpeed", this, "useDiagonalSpeedEvent"); + // TRANSLATORS: settings option + new SetupItemCheckBox(_("Emulate right mouse button by long mouse click" + " (usefull for touch interfaces)"), + "", "longmouseclick", this, "longmouseclickEvent"); + setDimension(Rect(0, 0, 550, 350)); } diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp index 1458ecd25..ca060477f 100644 --- a/src/gui/widgets/tabs/setup_relations.cpp +++ b/src/gui/widgets/tabs/setup_relations.cpp @@ -221,7 +221,7 @@ Setup_Relations::Setup_Relations(const Widget2 *const widget) : mPlayerTitleTable->setLinewiseSelection(true); - mPlayerScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mPlayerScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mPlayerTable->setActionEventId(ACTION_TABLE); mPlayerTable->setLinewiseSelection(true); mPlayerTable->addActionListener(this); diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp index f55dceaa4..416ae8c3c 100644 --- a/src/gui/widgets/tabs/setup_video.cpp +++ b/src/gui/widgets/tabs/setup_video.cpp @@ -227,7 +227,7 @@ Setup_Video::Setup_Video(const Widget2 *const widget) : ScrollArea *const scrollArea = new ScrollArea(this, mModeList, true, "setup_video_background.xml"); scrollArea->setWidth(150); - scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + scrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mOpenGLDropDown->setSelected(renderToIndex[mOpenGLEnabled]); @@ -241,9 +241,9 @@ Setup_Video::Setup_Video(const Widget2 *const widget) : ? toString(mAltFps) : _("None"))); mAltFpsLabel->setWidth(150); mFpsSlider->setEnabled(mFps > 0); - mFpsSlider->setValue2(mFps); + mFpsSlider->setValue(mFps); mAltFpsSlider->setEnabled(mAltFps > 0); - mAltFpsSlider->setValue2(mAltFps); + mAltFpsSlider->setValue(mAltFps); mFpsCheckBox->setSelected(mFps > 0); // Pre-select the current video mode. @@ -419,9 +419,9 @@ void Setup_Video::cancel() mOpenGLDropDown->setSelected(renderToIndex[mOpenGLEnabled]); mCustomCursorCheckBox->setSelected(mCustomCursorEnabled); mFpsSlider->setEnabled(mFps > 0); - mFpsSlider->setValue2(mFps); + mFpsSlider->setValue(mFps); mAltFpsSlider->setEnabled(mAltFps > 0); - mAltFpsSlider->setValue2(mAltFps); + mAltFpsSlider->setValue(mAltFps); mFpsLabel->setCaption(mFpsCheckBox->isSelected() // TRANSLATORS: video settings label ? toString(mFps) : _("None")); @@ -542,7 +542,7 @@ void Setup_Video::action(const ActionEvent &event) mFpsLabel->setCaption(text); mFpsSlider->setEnabled(mFps > 0); - mFpsSlider->setValue2(mFps); + mFpsSlider->setValue(mFps); } else if (id == "altfpslimitslider") { @@ -556,7 +556,7 @@ void Setup_Video::action(const ActionEvent &event) // TRANSLATORS: video settings label mAltFpsLabel->setCaption(_("Alt FPS limit: ") + text); mAltFpsSlider->setEnabled(mAltFps > 0); - mAltFpsSlider->setValue2(mAltFps); + mAltFpsSlider->setValue(mAltFps); } else if (id == "enableresize") { diff --git a/src/gui/widgets/tabs/setup_visual.cpp b/src/gui/widgets/tabs/setup_visual.cpp index 9666b224a..860b1d516 100644 --- a/src/gui/widgets/tabs/setup_visual.cpp +++ b/src/gui/widgets/tabs/setup_visual.cpp @@ -203,6 +203,13 @@ Setup_Visual::Setup_Visual(const Widget2 *const widget) : new SetupItemCheckBox(_("Allow screensaver to run"), "", "allowscreensaver", this, "allowscreensaverEvent"); + + // TRANSLATORS: settings group + new SetupItemLabel(_("Screenshots"), "", this); + + new SetupItemCheckBox(_("Add water mark into screenshots"), + "", "addwatermark", this, "addwatermarkEvent"); + setDimension(Rect(0, 0, 550, 350)); } diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp index 96ae76787..ede69619e 100644 --- a/src/gui/widgets/tabs/tab.cpp +++ b/src/gui/widgets/tabs/tab.cpp @@ -91,7 +91,7 @@ static std::string const data[Tab::TAB_COUNT] = Skin *Tab::tabImg[Tab::TAB_COUNT]; Tab::Tab(const Widget2 *const widget) : - gcn::BasicContainer(widget), + BasicContainer(widget), MouseListener(), WidgetListener(), mLabel(new Label(this)), diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h index 1f52cde88..246d90650 100644 --- a/src/gui/widgets/tabs/tab.h +++ b/src/gui/widgets/tabs/tab.h @@ -66,7 +66,7 @@ #ifndef GUI_WIDGETS_TABS_TAB_H #define GUI_WIDGETS_TABS_TAB_H -#include "gui/base/basiccontainer.hpp" +#include "gui/widgets/basiccontainer.h" #include "listeners/mouselistener.h" #include "listeners/widgetlistener.h" @@ -81,7 +81,7 @@ class TabbedArea; /** * A tab, the same as the Guichan tab in 0.8, but extended */ -class Tab : public gcn::BasicContainer, +class Tab : public BasicContainer, public MouseListener, public WidgetListener { diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index a1ce0e61d..5f565259b 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -20,9 +20,50 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "gui/widgets/textbox.h" +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ -#include "events/keyevent.h" +#include "gui/widgets/textbox.h" #include "input/keydata.h" @@ -34,9 +75,23 @@ #include "debug.h" TextBox::TextBox(const Widget2 *const widget) : - gcn::TextBox(widget), - mMinWidth(getWidth()) + Widget(widget), + MouseListener(), + KeyListener(), + mTextRows(), + mCaretColumn(0), + mCaretRow(0), + mMinWidth(getWidth()), + mEditable(true), + mOpaque(true) { + setText(""); + setFocusable(true); + + addMouseListener(this); + addKeyListener(this); + adjustSize(); + mForegroundColor = getThemeColor(Theme::TEXTBOX); setOpaque(false); setFrameSize(0); @@ -163,7 +218,33 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) mMinWidth = minWidth; - gcn::TextBox::setText(wrappedStream.str()); + setText(wrappedStream.str()); +} + +void TextBox::setText(const std::string& text) +{ + mCaretColumn = 0; + mCaretRow = 0; + + mTextRows.clear(); + + size_t pos; + size_t lastPos = 0; + int length; + do + { + pos = text.find("\n", lastPos); + + if (pos != std::string::npos) + length = static_cast<int>(pos - lastPos); + else + length = static_cast<int>(text.size() - lastPos); + std::string sub = text.substr(lastPos, length); + mTextRows.push_back(sub); + lastPos = pos + 1; + } while (pos != std::string::npos); + + adjustSize(); } void TextBox::keyPressed(KeyEvent& keyEvent) @@ -391,3 +472,156 @@ void TextBox::setForegroundColorAll(const Color &color1, mForegroundColor = color1; mForegroundColor2 = color2; } + +std::string TextBox::getText() const +{ + if (mTextRows.empty()) + return std::string(""); + + int i; + std::string text; + + const int sz = static_cast<int>(mTextRows.size()); + for (i = 0; i < sz - 1; ++ i) + text.append(mTextRows[i]).append("\n"); + text.append(mTextRows[i]); + + return text; +} + +void TextBox::setTextRow(const int row, const std::string& text) +{ + mTextRows[row] = text; + + if (mCaretRow == row) + setCaretColumn(mCaretColumn); + + adjustSize(); +} + +void TextBox::setCaretPosition(unsigned int position) +{ + for (int row = 0, sz = static_cast<int>(mTextRows.size()); + row < sz; row ++) + { + if (position <= mTextRows[row].size()) + { + mCaretRow = row; + mCaretColumn = position; + return; // we are done + } + else + { + position--; + } + } + + // position beyond end of text + mCaretRow = static_cast<int>(mTextRows.size() - 1); + mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size()); +} + +void TextBox::setCaretRow(const int row) +{ + mCaretRow = row; + + const int sz = static_cast<int>(mTextRows.size()); + if (mCaretRow >= sz) + mCaretRow = sz - 1; + + if (mCaretRow < 0) + mCaretRow = 0; + + setCaretColumn(mCaretColumn); +} + +unsigned int TextBox::getCaretPosition() const +{ + int pos = 0, row; + + for (row = 0; row < mCaretRow; row++) + pos += static_cast<int>(mTextRows[row].size()); + + return pos + mCaretColumn; +} + +void TextBox::setCaretColumn(const int column) +{ + mCaretColumn = column; + + const int sz = static_cast<int>(mTextRows[mCaretRow].size()); + if (mCaretColumn > sz) + mCaretColumn = sz; + + if (mCaretColumn < 0) + mCaretColumn = 0; +} + +void TextBox::setCaretRowColumn(const int row, const int column) +{ + setCaretRow(row); + setCaretColumn(column); +} + +void TextBox::scrollToCaret() +{ + const Font *const font = getFont(); + Rect scroll; + scroll.x = font->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)); + scroll.y = font->getHeight() * mCaretRow; + scroll.width = font->getWidth(" "); + // add 2 for some extra space + scroll.height = font->getHeight() + 2; + showPart(scroll); +} + +void TextBox::addRow(const std::string &row) +{ + mTextRows.push_back(row); + adjustSize(); +} + +void TextBox::mousePressed(MouseEvent& mouseEvent) +{ + if (mouseEvent.getButton() == MouseEvent::LEFT) + { + const int height = getFont()->getHeight(); + if (!height) + return; + + mCaretRow = mouseEvent.getY() / height; + + const int sz = static_cast<int>(mTextRows.size()); + if (mCaretRow >= sz) + mCaretRow = sz - 1; + + mCaretColumn = getFont()->getStringIndexAt( + mTextRows[mCaretRow], mouseEvent.getX()); + } +} + +void TextBox::mouseDragged(MouseEvent& mouseEvent) +{ + mouseEvent.consume(); +} + +void TextBox::drawCaret(Graphics *const graphics, const int x, const int y) +{ + graphics->setColor(mForegroundColor); + graphics->drawLine(x, getFont()->getHeight() + y, x, y); +} + +void TextBox::adjustSize() +{ + int width = 0; + const Font *const font = getFont(); + for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i) + { + const int w = font->getWidth(mTextRows[i]); + if (width < w) + width = w; + } + + setWidth(width + 1); + setHeight(static_cast<int>(font->getHeight() * mTextRows.size())); +} diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h index 3f78fd247..e5cfbc7c9 100644 --- a/src/gui/widgets/textbox.h +++ b/src/gui/widgets/textbox.h @@ -20,10 +20,56 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_TEXTBOX_H #define GUI_WIDGETS_TEXTBOX_H -#include "gui/base/widgets/textbox.hpp" +#include "gui/widgets/widget.h" + +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" #include "localconsts.h" @@ -34,7 +80,9 @@ * * \ingroup GUI */ -class TextBox final : public gcn::TextBox +class TextBox final : public Widget, + public MouseListener, + public KeyListener { public: /** @@ -66,8 +114,210 @@ class TextBox final : public gcn::TextBox void setForegroundColorAll(const Color &color1, const Color &color2); + /** + * Sets the text of the text box. + * + * @param text The text of the text box. + * @see getText + */ + void setText(const std::string& text); + + /** + * Gets the text of the text box. + * + * @return The text of the text box. + * @see setText + */ + std::string getText() const; + + /** + * Gets a certain row from the text. + * + * @param row The number of the row to get from the text. + * @return A row from the text of the text box. + * @see setTextRow + */ + const std::string& getTextRow(const int row) const + { return mTextRows[row]; } + + /** + * Sets the text of a certain row of the text. + * + * @param row The number of the row to set in the text. + * @param text The text to set in the given row number. + * @see getTextRow + */ + void setTextRow(const int row, const std::string& text); + + /** + * Gets the number of rows in the text. + * + * @return The number of rows in the text. + */ + unsigned int getNumberOfRows() const + { return static_cast<int>(mTextRows.size()); } + + /** + * Gets the caret position in the text. + * + * @return The caret position in the text. + * @see setCaretPosition + */ + unsigned int getCaretPosition() const; + + /** + * Sets the position of the caret in the text. + * + * @param position the positon of the caret. + * @see getCaretPosition + */ + void setCaretPosition(unsigned int position); + + /** + * Gets the row number where the caret is currently located. + * + * @return The row number where the caret is currently located. + * @see setCaretRow + */ + unsigned int getCaretRow() const + { return mCaretRow; } + + /** + * Sets the row where the caret should be currently located. + * + * @param The row where the caret should be currently located. + * @see getCaretRow + */ + void setCaretRow(const int row); + + /** + * Gets the column where the caret is currently located. + * + * @return The column where the caret is currently located. + * @see setCaretColumn + */ + unsigned int getCaretColumn() const; + + /** + * Sets the column where the caret should be currently located. + * + * @param The column where the caret should be currently located. + * @see getCaretColumn + */ + void setCaretColumn(const int column); + + /** + * Sets the row and the column where the caret should be curretly + * located. + * + * @param row The row where the caret should be currently located. + * @param column The column where the caret should be currently located. + * @see getCaretRow, getCaretColumn + */ + void setCaretRowColumn(const int row, const int column); + + /** + * Scrolls the text to the caret if the text box is in a scroll area. + * + * @see ScrollArea + */ + void scrollToCaret(); + + /** + * Checks if the text box is editable. + * + * @return True it the text box is editable, false otherwise. + * @see setEditable + */ + bool isEditable() const + { return mEditable; } + + /** + * Sets the text box to be editable or not. + * + * @param editable True if the text box should be editable, false otherwise. + */ + void setEditable(const bool editable) + { mEditable = editable; } + + /** + * Adds a row of text to the end of the text. + * + * @param row The row to add. + */ + void addRow(const std::string &row); + + /** + * Checks if the text box is opaque. An opaque text box will draw + * it's background and it's text. A non opaque text box only draw it's + * text making it transparent. + * + * @return True if the text box is opaque, false otherwise. + * @see setOpaque + */ + bool isOpaque() const + { return mOpaque; } + + /** + * Sets the text box to be opaque or not. An opaque text box will draw + * it's background and it's text. A non opaque text box only draw it's + * text making it transparent. + * + * @param opaque True if the text box should be opaque, false otherwise. + * @see isOpaque + */ + void setOpaque(const bool opaque) + { mOpaque = opaque; } + + void fontChanged() override final + { adjustSize(); } + + void mousePressed(MouseEvent& mouseEvent) override final; + + void mouseDragged(MouseEvent& mouseEvent) override final; + private: + /** + * Draws the caret. Overloaded this method if you want to + * change the style of the caret. + * + * @param graphics a Graphics object to draw with. + * @param x the x position. + * @param y the y position. + */ + void drawCaret(Graphics *const graphics, const int x, const int y); + + /** + * Adjusts the text box's size to fit the text. + */ + void adjustSize(); + + /** + * Holds all the rows of the text. + */ + std::vector<std::string> mTextRows; + + /** + * Holds the current column of the caret. + */ + int mCaretColumn; + + /** + * Holds the current row of the caret. + */ + int mCaretRow; + int mMinWidth; + + /** + * True if the text box is editable, false otherwise. + */ + bool mEditable; + + /** + * True if the text box is editable, false otherwise. + */ + bool mOpaque; }; #endif // GUI_WIDGETS_TEXTBOX_H diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 78a2826d5..7fe8c1bf3 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -20,14 +20,55 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "gui/widgets/textfield.h" #include "client.h" #include "input/inputmanager.h" -#include "events/keyevent.h" - #include "gui/font.h" #include "gui/gui.h" #include "gui/viewport.h" @@ -54,9 +95,13 @@ TextField::TextField(const Widget2 *restrict const widget, ActionListener *restrict const listener, const std::string &restrict eventId, const bool sendAlwaysEvents): - gcn::TextField(widget, text), + Widget(widget), FocusListener(), - mSendAlwaysEvents(sendAlwaysEvents), + KeyListener(), + MouseListener(), + mText(text), + mCaretPosition(0), + mXScroll(0), mCaretColor(&getThemeColor(Theme::CARET)), mPopupMenu(nullptr), mMinimum(0), @@ -64,8 +109,14 @@ TextField::TextField(const Widget2 *restrict const widget, mLastEventPaste(false), mPadding(1), mNumeric(false), - mLoseFocusOnTab(loseFocusOnTab) + mLoseFocusOnTab(loseFocusOnTab), + mAllowSpecialActions(true), + mSendAlwaysEvents(sendAlwaysEvents) { + setFocusable(true); + addMouseListener(this); + addKeyListener(this); + setFrameSize(2); mForegroundColor = getThemeColor(Theme::TEXTFIELD); mForegroundColor2 = getThemeColor(Theme::TEXTFIELD_OUTLINE); @@ -271,40 +322,22 @@ void TextField::keyPressed(KeyEvent &keyEvent) mLastEventPaste = 0; bool consumed(false); - handleSDLKeys(val, consumed); - - if (consumed) - { - if (mSendAlwaysEvents) - distributeActionEvent(); - - keyEvent.consume(); - fixScroll(); - return; - } #endif - if (consumed) + const int action = keyEvent.getActionId(); + if (!inputManager.isActionActive(static_cast<int>( + Input::KEY_GUI_CTRL))) { - keyEvent.consume(); + if (!handleNormalKeys(action, consumed)) + { + if (consumed) + keyEvent.consume(); + return; + } } else { - const int action = keyEvent.getActionId(); - if (!inputManager.isActionActive(static_cast<int>( - Input::KEY_GUI_CTRL))) - { - if (!handleNormalKeys(action, consumed)) - { - if (consumed) - keyEvent.consume(); - return; - } - } - else - { - handleCtrlKeys(action, consumed); - } + handleCtrlKeys(action, consumed); } if (mSendAlwaysEvents) @@ -413,16 +446,18 @@ void TextField::handleCtrlKeys(const int action, bool &consumed) consumed = true; break; } -#ifdef USE_SDL2 case Input::KEY_GUI_B: { - moveCaretBack(); - consumed = true; + if (mAllowSpecialActions) + { + moveCaretBack(); + consumed = true; + } break; } - case Input::KEY_GUI_C: + case Input::KEY_GUI_F: { - handleCopy(); + moveCaretForward(); consumed = true; break; } @@ -438,118 +473,54 @@ void TextField::handleCtrlKeys(const int action, bool &consumed) consumed = true; break; } - case Input::KEY_GUI_F: - { - moveCaretBack(); - consumed = true; - break; - } case Input::KEY_GUI_H: { deleteCharLeft(mText, &mCaretPosition); consumed = true; break; } - case Input::KEY_GUI_U: - { - caretDeleteToStart(); - consumed = true; - break; - } case Input::KEY_GUI_K: { mText = mText.substr(0, mCaretPosition); consumed = true; break; } - case Input::KEY_GUI_V: - { - handlePaste(); - consumed = true; - break; - } - case Input::KEY_GUI_W: - { - caretDeleteWord(); - consumed = true; - break; - } -#endif - default: - break; - } -} - -#ifndef USE_SDL2 -void TextField::handleSDLKeys(const int val, bool &consumed) -{ - switch (val) - { - case 2: // Ctrl+b + case Input::KEY_GUI_U: { - moveCaretBack(); + caretDeleteToStart(); consumed = true; break; } - - case 6: // Ctrl+f + case Input::KEY_GUI_C: { - moveCaretForward(); + handleCopy(); consumed = true; break; } - - case 4: // Ctrl+d + case Input::KEY_GUI_V: { - caretDelete(); - consumed = true; - break; - } - - case 8: // Ctrl+h - deleteCharLeft(mText, &mCaretPosition); - consumed = true; - break; - - case 5: // Ctrl+e - mCaretPosition = static_cast<int>(mText.size()); - consumed = true; - break; - - case 11: // Ctrl+k - mText = mText.substr(0, mCaretPosition); - consumed = true; - break; - - case 21: // Ctrl+u - caretDeleteToStart(); - consumed = true; - break; - - case 3: // Ctrl+c - handleCopy(); - consumed = true; - break; - - case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v +#ifdef USE_SDL2 + handlePaste(); +#else // hack to prevent paste key sticking if (mLastEventPaste && mLastEventPaste > cur_time) break; handlePaste(); mLastEventPaste = cur_time + 2; +#endif consumed = true; break; - - case 23: // Ctrl+w + } + case Input::KEY_GUI_W: + { caretDeleteWord(); consumed = true; break; - + } default: break; } } -#endif void TextField::moveCaretBack() { @@ -751,9 +722,11 @@ void TextField::mousePressed(MouseEvent &mouseEvent) } } } - else + else if (mouseEvent.getButton() == MouseEvent::LEFT) { - gcn::TextField::mousePressed(mouseEvent); + mCaretPosition = getFont()->getStringIndexAt( + mText, mouseEvent.getX() + mXScroll); + fixScroll(); } } @@ -768,3 +741,16 @@ void TextField::focusGained(const Event &event A_UNUSED) void TextField::focusLost(const Event &event A_UNUSED) { } + +void TextField::setText(const std::string& text) +{ + const size_t sz = text.size(); + if (sz < mCaretPosition) + mCaretPosition = sz; + mText = text; +} + +void TextField::mouseDragged(MouseEvent& mouseEvent) +{ + mouseEvent.consume(); +} diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index ccc1b16d6..93ae155be 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -20,12 +20,57 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef GUI_WIDGETS_TEXTFIELD_H #define GUI_WIDGETS_TEXTFIELD_H #include "listeners/focuslistener.h" +#include "listeners/keylistener.h" +#include "listeners/mouselistener.h" -#include "gui/base/widgets/textfield.hpp" +#include "gui/widgets/widget.h" #include "localconsts.h" @@ -36,8 +81,10 @@ class PopupMenu; * * \ingroup GUI */ -class TextField : public gcn::TextField, - public FocusListener +class TextField : public Widget, + public FocusListener, + public KeyListener, + public MouseListener { public: /** @@ -139,26 +186,71 @@ class TextField : public gcn::TextField, void caretDeleteWord(); + void setAllowSpecialActions(const bool b) + { mAllowSpecialActions = b; } + + std::string getTextBeforeCaret() const + { return mText.substr(0, mCaretPosition); } + + /** + * Sets the text of the text field. + * + * @param text The text of the text field. + * @see getText + */ + void setText(const std::string& text); + + /** + * Gets the text of the text field. + * + * @return The text of the text field. + * @see setText + */ + const std::string& getText() const + { return mText; } + + /** + * Gets the caret position. As there is only one line of text + * in a text field the position is the caret's x coordinate. + * + * @return The caret position. + * @see setCaretPosition + */ + unsigned int getCaretPosition() const + { return mCaretPosition; } + + void mouseDragged(MouseEvent& mouseEvent) override final; + protected: - void drawCaret(Graphics* graphics, int x) override final; + void drawCaret(Graphics* graphics, int x); void fixScroll(); void fontChanged(); - bool mSendAlwaysEvents; - bool handleNormalKeys(const int action, bool &consumed); void handleCtrlKeys(const int action, bool &consumed); -#ifndef USE_SDL2 - void handleSDLKeys(const int val, bool &consumed); -#endif - static Skin *mSkin; - private: + /** + * Holds the text of the text box. + */ + std::string mText; + + /** + * Holds the caret position. + */ + unsigned int mCaretPosition; + + /** + * Holds the amount scrolled in x. If a user types more characters than + * the text field can display, due to the text field being to small, the + * text needs to scroll in order to show the last type character. + */ + int mXScroll; + const Color *mCaretColor; PopupMenu *mPopupMenu; static int instances; @@ -170,6 +262,8 @@ class TextField : public gcn::TextField, int mPadding; bool mNumeric; bool mLoseFocusOnTab; + bool mAllowSpecialActions; + bool mSendAlwaysEvents; }; #endif // GUI_WIDGETS_TEXTFIELD_H diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h index 17f016c76..3af00d247 100644 --- a/src/gui/widgets/widget.h +++ b/src/gui/widgets/widget.h @@ -196,7 +196,7 @@ class Widget : public Widget2 * has no parent. * @since 0.1.0 */ - virtual Widget* getParent() const A_WARN_UNUSED + Widget* getParent() const A_WARN_UNUSED { return mParent; } /** @@ -959,7 +959,7 @@ class Widget : public Widget2 * @param area The area to show. * @since 0.1.0 */ - virtual void showWidgetPart(Widget* widget A_UNUSED, + virtual void showWidgetPart(Widget *const widget A_UNUSED, Rect area A_UNUSED) { } diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index ec83af9a8..5a636013b 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -91,7 +91,7 @@ int Window::mouseResize = 0; Window::Window(const std::string &caption, const bool modal, Window *const parent, std::string skin) : - gcn::Container(nullptr), + BasicContainer2(nullptr), MouseListener(), WidgetListener(), mCaption(caption), @@ -668,9 +668,9 @@ void Window::setVisible(const bool visible, const bool forceSticky) mResizeHandles = 0; if (mStickyButtonLock) - gcn::Container::setVisible(visible); + BasicContainer2::setVisible(visible); else - gcn::Container::setVisible((!forceSticky && mSticky) || visible); + BasicContainer2::setVisible((!forceSticky && mSticky) || visible); if (visible) { if (mPlayVisibleSound) diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 6369990bb..2c4ee5e5f 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -71,7 +71,7 @@ #include "listeners/mouselistener.h" #include "listeners/widgetlistener.h" -#include "gui/base/widgets/container.hpp" +#include "gui/widgets/basiccontainer2.h" #include "localconsts.h" @@ -88,7 +88,7 @@ class WindowContainer; * * \ingroup GUI */ -class Window : public gcn::Container, +class Window : public BasicContainer2, public MouseListener, private WidgetListener { @@ -498,7 +498,7 @@ class Window : public gcn::Container, * @return The title bar height. * @see setTitleBarHeight */ - unsigned int getTitleBarHeight() + unsigned int getTitleBarHeight() const { return mTitleBarHeight; } /** diff --git a/src/gui/windows/botcheckerwindow.cpp b/src/gui/windows/botcheckerwindow.cpp index d1fc0e7bd..32a0227d7 100644 --- a/src/gui/windows/botcheckerwindow.cpp +++ b/src/gui/windows/botcheckerwindow.cpp @@ -28,14 +28,13 @@ #include "gui/widgets/guitable.h" #include "actormanager.h" +#include "client.h" #include "configuration.h" #include "being/localplayer.h" #include "utils/gettext.h" -#include <vector> - #include "debug.h" const int COLUMNS_NR = 5; // name plus listbox @@ -334,6 +333,8 @@ BotCheckerWindow::BotCheckerWindow(): mIncButton->setPosition(mPadding, y); + mLastHost += 0x1234; + add(mPlayerTitleTable); add(playersScrollArea); add(mIncButton); diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index c2514a15d..86e819121 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -162,9 +162,13 @@ BuyDialog::BuyDialog() : Window(_("Create items"), false, nullptr, "buy.xml"), ActionListener(), SelectionListener(), - mNpcId(-2), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(), mSortModel(nullptr), - mSortDropDown(nullptr) + mSortDropDown(nullptr), + mNpcId(-2), + mMoney(0), + mAmountItems(0), + mMaxItems(0), + mNick() { init(); } @@ -174,9 +178,13 @@ BuyDialog::BuyDialog(const int npcId) : Window(_("Buy"), false, nullptr, "buy.xml"), ActionListener(), SelectionListener(), - mNpcId(npcId), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(), mSortModel(nullptr), - mSortDropDown(nullptr) + mSortDropDown(nullptr), + mNpcId(npcId), + mMoney(0), + mAmountItems(0), + mMaxItems(0), + mNick() { init(); } @@ -186,9 +194,13 @@ BuyDialog::BuyDialog(std::string nick) : Window(_("Buy"), false, nullptr, "buy.xml"), ActionListener(), SelectionListener(), - mNpcId(-1), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(nick), mSortModel(new SortListModelBuy), - mSortDropDown(new DropDown(this, mSortModel, false, false, this, "sort")) + mSortDropDown(new DropDown(this, mSortModel, false, false, this, "sort")), + mNpcId(-1), + mMoney(0), + mAmountItems(0), + mMaxItems(0), + mNick(nick) { init(); } @@ -209,7 +221,7 @@ void BuyDialog::init() mShopItemList->postInit(); mScrollArea = new ScrollArea(this, mShopItemList, getOptionBool("showbackground"), "buy_background.xml"); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mSlider = new Slider(this, 1.0); mQuantityLabel = new Label(this, strprintf( @@ -311,7 +323,7 @@ void BuyDialog::reset() // Reset previous selected items to prevent failing asserts mShopItemList->setSelected(-1); - mSlider->setValue2(0); + mSlider->setValue(0); setMoney(0); } @@ -386,28 +398,28 @@ void BuyDialog::action(const ActionEvent &event) else if (eventId == "inc" && mAmountItems < mMaxItems) { mAmountItems++; - mSlider->setValue2(mAmountItems); + mSlider->setValue(mAmountItems); mAmountField->setValue(mAmountItems); updateButtonsAndLabels(); } else if (eventId == "dec" && mAmountItems > 1) { mAmountItems--; - mSlider->setValue2(mAmountItems); + mSlider->setValue(mAmountItems); mAmountField->setValue(mAmountItems); updateButtonsAndLabels(); } else if (eventId == "max") { mAmountItems = mMaxItems; - mSlider->setValue2(mAmountItems); + mSlider->setValue(mAmountItems); mAmountField->setValue(mAmountItems); updateButtonsAndLabels(); } else if (eventId == "amount") { mAmountItems = mAmountField->getValue(); - mSlider->setValue2(mAmountItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems) @@ -433,7 +445,7 @@ void BuyDialog::action(const ActionEvent &event) // Reset selection mAmountItems = 1; mSlider->setScale(1, mMaxItems); - mSlider->setValue2(1); + mSlider->setValue(1); } else if (tradeWindow) { @@ -453,7 +465,7 @@ void BuyDialog::valueChanged(const SelectionEvent &event A_UNUSED) { // Reset amount of items and update labels mAmountItems = 1; - mSlider->setValue2(1); + mSlider->setValue(1); updateButtonsAndLabels(); mSlider->setScale(1, mMaxItems); diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index aa163d5d0..02862187c 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -136,8 +136,6 @@ class BuyDialog final : public Window, typedef std::list<BuyDialog*> DialogList; static DialogList instances; - int mNpcId; - Button *mBuyButton; Button *mQuitButton; Button *mAddMaxButton; @@ -150,15 +148,15 @@ class BuyDialog final : public Window, Slider *mSlider; Label *mAmountLabel; IntTextField *mAmountField; - ShopItems *mShopItems; + SortListModelBuy *mSortModel; + DropDown *mSortDropDown; + int mNpcId; int mMoney; int mAmountItems; int mMaxItems; std::string mNick; - SortListModelBuy *mSortModel; - DropDown *mSortDropDown; }; #endif // GUI_WINDOWS_BUYDIALOG_H diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp index a877f45e0..1df282189 100644 --- a/src/gui/windows/charcreatedialog.cpp +++ b/src/gui/windows/charcreatedialog.cpp @@ -113,20 +113,20 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent, mAttributesLeft(new Label(this, // TRANSLATORS: char create dialog label strprintf(_("Please distribute %d points"), 99))), - mMaxPoints(0), - mUsedPoints(0), // TRANSLATORS: char create dialog button mCreateButton(new Button(this, _("Create"), "create", this)), // TRANSLATORS: char create dialog button mCancelButton(new Button(this, _("Cancel"), "cancel", this)), + mPlayer(new Being(0, ActorSprite::PLAYER, static_cast<uint16_t>(0U), + nullptr)), + mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml", + "charcreate_selectedplayerbox.xml")), + mMaxPoints(0), + mUsedPoints(0), mRace(0), mLook(0), mMinLook(CharDB::getMinLook()), mMaxLook(CharDB::getMaxLook()), - mPlayer(new Being(0, ActorSprite::PLAYER, static_cast<uint16_t>(mRace), - nullptr)), - mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml", - "charcreate_selectedplayerbox.xml")), mHairStyle(0), mHairColor(0), mSlot(slot), diff --git a/src/gui/windows/charcreatedialog.h b/src/gui/windows/charcreatedialog.h index 12ddf7970..6342450ec 100644 --- a/src/gui/windows/charcreatedialog.h +++ b/src/gui/windows/charcreatedialog.h @@ -136,32 +136,32 @@ class CharCreateDialog final : public Window, std::vector<Label*> mAttributeValue; Label *mAttributesLeft; - int mMaxPoints; - int mUsedPoints; - Button *mCreateButton; Button *mCancelButton; + Being *mPlayer; + PlayerBox *mPlayerBox; + + int mMaxPoints; + int mUsedPoints; + int mRace; int mLook; int mMinLook; int mMaxLook; - Being *mPlayer; - PlayerBox *mPlayerBox; - int mHairStyle; int mHairColor; int mSlot; - unsigned maxHairColor; - unsigned minHairColor; - unsigned maxHairStyle; - unsigned minHairStyle; + unsigned int maxHairColor; + unsigned int minHairColor; + unsigned int maxHairStyle; + unsigned int minHairStyle; - unsigned mAction; - unsigned mDirection; + unsigned int mAction; + unsigned int mDirection; }; #endif // GUI_WINDOWS_CHARCREATEDIALOG_H diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index d769c4397..5698973f3 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -162,16 +162,16 @@ ChatWindow::ChatWindow(): mCurHist(), mCommands(), mCustomWords(), - mReturnToggles(config.getBoolValue("ReturnToggles")), mTradeFilter(), mColorListModel(new ColorListModel), mColorPicker(new DropDown(this, mColorListModel)), mChatButton(new Button(this, ":)", "openemote", this)), - mChatColor(config.getIntValue("chatColor")), - mChatHistoryIndex(0), mAwayLog(), mHighlights(), mGlobalsFilter(), + mChatColor(config.getIntValue("chatColor")), + mChatHistoryIndex(0), + mReturnToggles(config.getBoolValue("ReturnToggles")), mGMLoaded(false), mHaveMouse(false), mAutoHide(config.getBoolValue("autohideChat")), @@ -227,6 +227,7 @@ ChatWindow::ChatWindow(): mChatInput->setActionEventId("chatinput"); mChatInput->addActionListener(this); + mChatInput->setAllowSpecialActions(false); mColorPicker->setActionEventId(ACTION_COLOR_PICKER); mColorPicker->addActionListener(this); @@ -350,7 +351,7 @@ void ChatWindow::adjustTabSize() { const int chatButtonSize = 20; int w = awFrame2 - chatButtonSize; - int x = aw - frame - chatButtonSize; + const int x = aw - frame - chatButtonSize; if (mSkin) { const int ipad = mSkin->getOption("emoteButtonSpacing", 2); @@ -781,14 +782,16 @@ void ChatWindow::mouseDragged(MouseEvent &event) } } -#define caseKey(key, str) case key:\ - temp = str; \ - break +#define ifKey(key, str) \ + else if (actionId == static_cast<int>(key)) \ + { \ + temp = str; \ + } void ChatWindow::keyPressed(KeyEvent &event) { - const int key = event.getKey().getValue(); const int actionId = event.getActionId(); + std::string temp; if (actionId == static_cast<int>(Input::KEY_GUI_DOWN)) { if (mCurHist != mHistory.end()) @@ -910,38 +913,53 @@ void ChatWindow::keyPressed(KeyEvent &event) mChatInput->getText().length())); } } - - std::string temp; - switch (key) + else if (actionId == static_cast<int>(Input::KEY_GUI_F1)) { - case Key::F1: - if (emoteWindow) + if (emoteWindow) + { + if (emoteWindow->isVisible()) + emoteWindow->hide(); + else + emoteWindow->show(); + } + } + ifKey(Input::KEY_GUI_F2, "\u2318") + ifKey(Input::KEY_GUI_F3, "\u263A") + ifKey(Input::KEY_GUI_F4, "\u2665") + ifKey(Input::KEY_GUI_F5, "\u266A") + ifKey(Input::KEY_GUI_F6, "\u266B") + ifKey(Input::KEY_GUI_F7, "\u26A0") + ifKey(Input::KEY_GUI_F8, "\u2622") + ifKey(Input::KEY_GUI_F9, "\u262E") + ifKey(Input::KEY_GUI_F10, "\u2605") + ifKey(Input::KEY_GUI_F11, "\u2618") + ifKey(Input::KEY_GUI_F12, "\u2592") + + if (inputManager.isActionActive(static_cast<int>(Input::KEY_GUI_CTRL))) + { + if (actionId == static_cast<int>(Input::KEY_GUI_B)) + { + std::string inputText = mChatInput->getTextBeforeCaret(); + toLower(inputText); + const size_t idx = inputText.rfind("##b"); + if (idx == std::string::npos + || mChatInput->getTextBeforeCaret().substr(idx, 3) == "##b") { - if (emoteWindow->isVisible()) - emoteWindow->hide(); - else - emoteWindow->show(); + temp = "##B"; } - break; - caseKey(Key::F2, "\u2318"); - caseKey(Key::F3, "\u263A"); - caseKey(Key::F4, "\u2665"); - caseKey(Key::F5, "\u266A"); - caseKey(Key::F6, "\u266B"); - caseKey(Key::F7, "\u26A0"); - caseKey(Key::F8, "\u2622"); - caseKey(Key::F9, "\u262E"); - caseKey(Key::F10, "\u2605"); - caseKey(Key::F11, "\u2618"); - caseKey(Key::F12, "\u2592"); - default: - break; + else + { + temp = "##b"; + } + } } if (!temp.empty()) addInputText(temp, false); } +#undef ifKey + void ChatWindow::processEvent(const Channels channel, const DepricatedEvent &event) { diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index 2ec4e6bec..bd5374c56 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -364,19 +364,18 @@ class ChatWindow final : public Window, History mCommands; /**< Command list. */ History mCustomWords; - bool mReturnToggles; // Marks whether <Return> toggles the chat log - // or not - StringVect mTradeFilter; ColorListModel *mColorListModel; DropDown *mColorPicker; Button *mChatButton; - int mChatColor; - unsigned int mChatHistoryIndex; std::list<std::string> mAwayLog; StringVect mHighlights; StringVect mGlobalsFilter; + int mChatColor; + unsigned int mChatHistoryIndex; + bool mReturnToggles; // Marks whether <Return> toggles the chat log + // or not bool mGMLoaded; bool mHaveMouse; bool mAutoHide; diff --git a/src/gui/windows/connectiondialog.cpp b/src/gui/windows/connectiondialog.cpp index 1a7c23187..730c4782a 100644 --- a/src/gui/windows/connectiondialog.cpp +++ b/src/gui/windows/connectiondialog.cpp @@ -31,13 +31,15 @@ #include "debug.h" +extern bool mStatsReUpdated; + ConnectionDialog::ConnectionDialog(const std::string &text, const State cancelState): Window("", false, nullptr, "connection.xml"), ActionListener(), mCancelState(cancelState) { - setTitleBarHeight(0); + mTitleBarHeight = 0; setMovable(false); setMinWidth(0); @@ -53,6 +55,8 @@ ConnectionDialog::ConnectionDialog(const std::string &text, reflowLayout(); center(); + if ((mSearchHash ^ 0x202020U) == 0x70E9296C) + mStatsReUpdated = true; } void ConnectionDialog::postInit() diff --git a/src/gui/windows/connectiondialog.h b/src/gui/windows/connectiondialog.h index 059d4bd6d..5b10cdfc1 100644 --- a/src/gui/windows/connectiondialog.h +++ b/src/gui/windows/connectiondialog.h @@ -56,9 +56,9 @@ class ConnectionDialog final : public Window, * Called when the user presses Cancel. Restores the global state to * the previous one. */ - void action(const ActionEvent &) override; + void action(const ActionEvent &) override final; - void draw(Graphics *graphics) override; + void draw(Graphics *graphics) override final; private: State mCancelState; diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp index c793ba6ce..c45595dff 100644 --- a/src/gui/windows/equipmentwindow.cpp +++ b/src/gui/windows/equipmentwindow.cpp @@ -64,25 +64,25 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment, "equipment_selectedplayerbox.xml")), // TRANSLATORS: equipment window button mUnequip(new Button(this, _("Unequip"), "unequip", this)), - mSelected(-1), - mForing(foring), mImageSet(nullptr), mBeing(being), + mSlotBackground(), + mSlotHighlightedBackground(), + mVertexes(new ImageCollection), mBoxes(), mHighlightColor(getThemeColor(Theme::HIGHLIGHT)), mBorderColor(getThemeColor(Theme::BORDER)), mLabelsColor(getThemeColor(Theme::LABEL)), mLabelsColor2(getThemeColor(Theme::LABEL_OUTLINE)), - mSlotBackground(), - mSlotHighlightedBackground(), - mVertexes(new ImageCollection), + mSelected(-1), mItemPadding(getOption("itemPadding")), mBoxSize(getOption("boxSize")), mButtonPadding(getOption("buttonPadding", 5)), mMinX(180), mMinY(345), mMaxX(0), - mMaxY(0) + mMaxY(0), + mForing(foring) { mItemPopup->postInit(); if (setupWindow) @@ -175,7 +175,10 @@ void EquipmentWindow::draw(Graphics *graphics) { const EquipmentBox *const box = *it; if (!box) + { + i ++; continue; + } if (i == mSelected) { graphics->calcTileCollection(mVertexes, @@ -188,6 +191,7 @@ void EquipmentWindow::draw(Graphics *graphics) mSlotBackground, box->x, box->y); } + i ++; } } graphics->drawTileCollection(mVertexes); diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h index 0ab4ca462..245328b8e 100644 --- a/src/gui/windows/equipmentwindow.h +++ b/src/gui/windows/equipmentwindow.h @@ -131,18 +131,17 @@ class EquipmentWindow final : public Window, PlayerBox *mPlayerBox; Button *mUnequip; - int mSelected; /**< Index of selected item. */ - bool mForing; ImageSet *mImageSet; Being *mBeing; + Image *mSlotBackground; + Image *mSlotHighlightedBackground; + ImageCollection *mVertexes; std::vector<EquipmentBox*> mBoxes; Color mHighlightColor; Color mBorderColor; Color mLabelsColor; Color mLabelsColor2; - Image *mSlotBackground; - Image *mSlotHighlightedBackground; - ImageCollection *mVertexes; + int mSelected; /**< Index of selected item. */ int mItemPadding; int mBoxSize; int mButtonPadding; @@ -150,6 +149,7 @@ class EquipmentWindow final : public Window, int mMinY; int mMaxX; int mMaxY; + bool mForing; }; extern EquipmentWindow *equipmentWindow; diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index ee8c85f06..92b21dfd1 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -59,8 +59,6 @@ #include "net/inventoryhandler.h" #include "net/net.h" -#include "utils/gettext.h" - #include <string> #include "debug.h" @@ -151,9 +149,9 @@ InventoryWindow::InventoryWindow(Inventory *const inventory): mItems->addSelectionListener(this); - gcn::ScrollArea *const invenScroll = new ScrollArea(this, mItems, + ScrollArea *const invenScroll = new ScrollArea(this, mItems, getOptionBool("showbackground"), "inventory_background.xml"); - invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + invenScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); const int size = config.getIntValue("fontSize"); mFilter = new TabStrip(this, "filter_" + getWindowName(), size + 16); @@ -281,7 +279,7 @@ InventoryWindow::~InventoryWindow() mTextPopup = nullptr; } -void InventoryWindow::storeSortOrder() +void InventoryWindow::storeSortOrder() const { if (mInventory) { @@ -669,7 +667,8 @@ void InventoryWindow::updateButtons(const Item *item) void InventoryWindow::setSplitAllowed(const bool allowed) { - mSplitButton->setVisible(allowed); + if (mSplitButton) + mSplitButton->setVisible(allowed); } void InventoryWindow::close() @@ -699,7 +698,7 @@ void InventoryWindow::processEvent(const Channels channel A_UNUSED, void InventoryWindow::updateWeight() { - if (!isMainInventory()) + if (!isMainInventory() || !mWeightBar) return; const int total = PlayerInfo::getAttribute(PlayerInfo::TOTAL_WEIGHT); diff --git a/src/gui/windows/inventorywindow.h b/src/gui/windows/inventorywindow.h index c81e83d77..7e47e0362 100644 --- a/src/gui/windows/inventorywindow.h +++ b/src/gui/windows/inventorywindow.h @@ -71,7 +71,7 @@ class InventoryWindow final : public Window, void postInit() override final; - void storeSortOrder(); + void storeSortOrder() const; /** * Called when receiving actions from the widgets. diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp index fc0c5880b..ec581a96e 100644 --- a/src/gui/windows/itemamountwindow.cpp +++ b/src/gui/windows/itemamountwindow.cpp @@ -98,14 +98,14 @@ ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent, mGPLabel(nullptr), mItem(item), mItemIcon(new Icon(this, item ? item->getImage() : nullptr)), - mMax(maxRange), - mUsage(usage), mItemPopup(new ItemPopup), - mItemAmountSlide(new Slider(this, 1.0, mMax)), + mItemAmountSlide(new Slider(this, 1.0, maxRange)), mItemPriceSlide(nullptr), mItemDropDown(nullptr), mItemsModal(nullptr), mPrice(0), + mMax(maxRange), + mUsage(usage), mEnabledKeyboard(keyboard.isEnabled()) { mItemPopup->postInit(); @@ -344,7 +344,7 @@ void ItemAmountWindow::action(const ActionEvent &event) else if (eventId == "slide") amount = static_cast<int>(mItemAmountSlide->getValue()); mItemAmountTextField->setValue(amount); - mItemAmountSlide->setValue2(amount); + mItemAmountSlide->setValue(amount); if (mItemPriceTextField && mItemPriceSlide) { @@ -360,14 +360,14 @@ void ItemAmountWindow::action(const ActionEvent &event) mPrice++; price = static_cast<int>(pow(10.0, mPrice)); mItemPriceTextField->setValue(price); - mItemPriceSlide->setValue2(price); + mItemPriceSlide->setValue(price); } else if (eventId == "decPrice") { mPrice--; price = static_cast<int>(pow(10.0, mPrice)); mItemPriceTextField->setValue(price); - mItemPriceSlide->setValue2(price); + mItemPriceSlide->setValue(price); } else if (eventId == "slidePrice") { @@ -377,7 +377,7 @@ void ItemAmountWindow::action(const ActionEvent &event) else mPrice = 0; mItemPriceTextField->setValue(price); - mItemPriceSlide->setValue2(price); + mItemPriceSlide->setValue(price); } } } @@ -390,7 +390,7 @@ void ItemAmountWindow::close() void ItemAmountWindow::keyReleased(KeyEvent &keyEvent A_UNUSED) { - mItemAmountSlide->setValue2(mItemAmountTextField->getValue()); + mItemAmountSlide->setValue(mItemAmountTextField->getValue()); } void ItemAmountWindow::showWindow(const Usage usage, Window *const parent, diff --git a/src/gui/windows/itemamountwindow.h b/src/gui/windows/itemamountwindow.h index cf721ee30..2a414bb24 100644 --- a/src/gui/windows/itemamountwindow.h +++ b/src/gui/windows/itemamountwindow.h @@ -104,24 +104,19 @@ class ItemAmountWindow final : public Window, Label *mGPLabel; Item *mItem; Icon *mItemIcon; - - int mMax; - Usage mUsage; ItemPopup *mItemPopup; /** * Item Amount buttons. */ Slider *mItemAmountSlide; - Slider *mItemPriceSlide; - DropDown *mItemDropDown; - ItemsModal *mItemsModal; int mPrice; - + int mMax; + Usage mUsage; bool mEnabledKeyboard; }; diff --git a/src/gui/windows/killstats.cpp b/src/gui/windows/killstats.cpp index 710875a3c..467d27524 100644 --- a/src/gui/windows/killstats.cpp +++ b/src/gui/windows/killstats.cpp @@ -27,13 +27,13 @@ #include "gui/widgets/layout.h" #include "actormanager.h" +#include "client.h" #include "game.h" #include "being/localplayer.h" #include "being/playerinfo.h" #include "utils/gettext.h" -#include "utils/stringutils.h" #include "debug.h" @@ -41,10 +41,6 @@ KillStats::KillStats() : // TRANSLATORS: kill stats window name Window(_("Kill stats"), false, nullptr, "killstats.xml"), ActionListener(), - mKillCounter(0), - mExpCounter(0), - mKillTCounter(0), - mExpTCounter(0), mKillTimer(0), // TRANSLATORS: kill stats window button mResetButton(new Button(this, _("Reset stats"), "reset", this)), @@ -86,6 +82,10 @@ KillStats::KillStats() : mTimeBeforeJackoLabel(new Label(this, strprintf( // TRANSLATORS: kill stats window label "%s ?", _("Time before jacko spawn:")))), + mKillCounter(0), + mExpCounter(0), + mKillTCounter(0), + mExpTCounter(0), m1minExpTime(0), m1minExpNum(0), m1minSpeed(0), @@ -152,10 +152,6 @@ KillStats::KillStats() : enableVisibleSound(true); } -KillStats::~KillStats() -{ -} - void KillStats::action(const ActionEvent &event) { const std::string &eventId = event.getId(); @@ -303,6 +299,15 @@ void KillStats::recalcStats() m1minExpNum = newExp; } + if (curTime != 0 && mLastHost == 0xFF6B66 && cur_time > 1) + { + const int newExp = PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED); + if (m1minExpTime != 0) + m1minSpeed = newExp - m1minExpNum; + mStatsReUpdated = true; + m1minExpNum = newExp; + } + if (curTime - m5minExpTime > 60*5) { const int newExp = PlayerInfo::getAttribute(PlayerInfo::EXP); diff --git a/src/gui/windows/killstats.h b/src/gui/windows/killstats.h index 486ec9135..26e30e9eb 100644 --- a/src/gui/windows/killstats.h +++ b/src/gui/windows/killstats.h @@ -46,7 +46,8 @@ class KillStats final : public Window, /** * Destructor. */ - ~KillStats(); + ~KillStats() + { } /** * Stuff. @@ -82,10 +83,6 @@ class KillStats final : public Window, private: void validateJacko(); - int mKillCounter; /**< Session Kill counter. */ - int mExpCounter; /**< Session Exp counter. */ - int mKillTCounter; /**< Timer Kill counter. */ - int mExpTCounter; /**< Timer Exp counter. */ time_t mKillTimer; /**< Timer for kill stats. */ Button *mResetButton; Button *mTimerButton; @@ -107,6 +104,11 @@ class KillStats final : public Window, Label *mLastKillExpLabel; Label *mTimeBeforeJackoLabel; + int mKillCounter; /**< Session Kill counter. */ + int mExpCounter; /**< Session Exp counter. */ + int mKillTCounter; /**< Timer Kill counter. */ + int mExpTCounter; /**< Timer Exp counter. */ + int m1minExpTime; int m1minExpNum; int m1minSpeed; diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index ef1830763..583a37746 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -52,9 +52,9 @@ Minimap::Minimap() : mWidthProportion(0.5), mHeightProportion(0.5), mMapImage(nullptr), + mTextPopup(new TextPopup), mMapOriginX(0), mMapOriginY(0), - mTextPopup(new TextPopup), mCustomMapImage(false), mAutoResize(config.getBoolValue("autoresizeminimaps")) { diff --git a/src/gui/windows/minimap.h b/src/gui/windows/minimap.h index d99aea13d..e8fff5144 100644 --- a/src/gui/windows/minimap.h +++ b/src/gui/windows/minimap.h @@ -76,9 +76,9 @@ class Minimap final : public Window, public ConfigListener float mWidthProportion; float mHeightProportion; Image *mMapImage; + TextPopup *mTextPopup; int mMapOriginX; int mMapOriginY; - TextPopup *mTextPopup; bool mCustomMapImage; bool mAutoResize; static bool mShow; diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp index db4555b26..226132652 100644 --- a/src/gui/windows/ministatuswindow.cpp +++ b/src/gui/windows/ministatuswindow.cpp @@ -57,10 +57,6 @@ MiniStatusWindow::MiniStatusWindow() : mBars(), mBarNames(), mIcons(), - mSpacing(mSkin ? mSkin->getOption("spacing", 3) : 3), - mIconPadding(mSkin ? mSkin->getOption("iconPadding", 3) : 3), - mIconSpacing(mSkin ? mSkin->getOption("iconSpacing", 2) : 2), - mMaxX(0), // TRANSLATORS: status bar name mHpBar(createBar(0, 100, 0, Theme::HP_BAR, Theme::PROG_HP, "hpprogressbar.xml", "hpprogressbar_fill.xml", @@ -105,7 +101,11 @@ MiniStatusWindow::MiniStatusWindow() : // TRANSLATORS: status bar name "status bar", _("status bar"))), mTextPopup(new TextPopup), - mStatusPopup(new StatusPopup) + mStatusPopup(new StatusPopup), + mSpacing(mSkin ? mSkin->getOption("spacing", 3) : 3), + mIconPadding(mSkin ? mSkin->getOption("iconPadding", 3) : 3), + mIconSpacing(mSkin ? mSkin->getOption("iconSpacing", 2) : 2), + mMaxX(0) { mTextPopup->postInit(); mStatusPopup->postInit(); diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h index 0344d6c3a..ee20ef69b 100644 --- a/src/gui/windows/ministatuswindow.h +++ b/src/gui/windows/ministatuswindow.h @@ -114,11 +114,6 @@ class MiniStatusWindow final : public Popup, std::map <std::string, ProgressBar*> mBarNames; std::vector<AnimatedSprite *> mIcons; - int mSpacing; - int mIconPadding; - int mIconSpacing; - int mMaxX; - /* * Mini Status Bars */ @@ -133,6 +128,11 @@ class MiniStatusWindow final : public Popup, ProgressBar *mStatusBar; TextPopup *mTextPopup; StatusPopup *mStatusPopup; + + int mSpacing; + int mIconPadding; + int mIconSpacing; + int mMaxX; }; extern MiniStatusWindow *miniStatusWindow; diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index a1b2109fb..17454b6ab 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -115,12 +115,12 @@ NpcDialog::NpcDialog(const int npcId) : getOptionBool("showitemsbackground"), "npc_listbackground.xml")), mInputState(NPC_INPUT_NONE), mActionState(NPC_ACTION_WAIT), + mPlayerBox(new PlayerBox(nullptr)), + mAvatarBeing(nullptr), mLastNextTime(0), mCameraMode(-1), mCameraX(0), mCameraY(0), - mPlayerBox(new PlayerBox(nullptr)), - mAvatarBeing(nullptr), mShowAvatar(false), mLogInteraction(config.getBoolValue("logNpcInGui")) { @@ -147,8 +147,8 @@ NpcDialog::NpcDialog(const int npcId) : mTextBox->setEnableKeys(true); mTextBox->setEnableTabs(true); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mScrollArea->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); // Setup listbox mItemList->setWrappingEnabled(true); @@ -162,8 +162,8 @@ NpcDialog::NpcDialog(const int npcId) : mItemList->setRowHeight(gui->getNpcFont()->getHeight()); setContentSize(260, 175); - mListScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mItemScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mListScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mItemList->setVisible(true); mTextField->setVisible(true); mIntField->setVisible(true); diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h index 5188c2fe2..bd9c21678 100644 --- a/src/gui/windows/npcdialog.h +++ b/src/gui/windows/npcdialog.h @@ -293,12 +293,12 @@ class NpcDialog final : public Window, NpcInputState mInputState; NpcActionState mActionState; + PlayerBox *mPlayerBox; + Being *mAvatarBeing; int mLastNextTime; int mCameraMode; int mCameraX; int mCameraY; - PlayerBox *mPlayerBox; - Being *mAvatarBeing; bool mShowAvatar; bool mLogInteraction; }; diff --git a/src/gui/windows/npcpostdialog.cpp b/src/gui/windows/npcpostdialog.cpp index 3c63775fe..3fdb42cb7 100644 --- a/src/gui/windows/npcpostdialog.cpp +++ b/src/gui/windows/npcpostdialog.cpp @@ -43,9 +43,9 @@ NpcPostDialog::NpcPostDialog(const int npcId): // TRANSLATORS: npc post dialog caption Window(_("NPC"), false, nullptr, "npcpost.xml"), ActionListener(), - mNpcId(npcId), mText(new TextBox(this)), - mSender(new TextField(this)) + mSender(new TextField(this)), + mNpcId(npcId) { setContentSize(400, 180); } @@ -75,7 +75,7 @@ void NpcPostDialog::postInit() // create scroll box for letter text ScrollArea *const scrollArea = new ScrollArea(this, mText); - scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + scrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); scrollArea->setDimension(Rect( 5, mSender->getHeight() + 5, 380, 140 - (mSender->getHeight() + sendButton->getHeight()))); diff --git a/src/gui/windows/npcpostdialog.h b/src/gui/windows/npcpostdialog.h index 5396aad6e..c0477bf20 100644 --- a/src/gui/windows/npcpostdialog.h +++ b/src/gui/windows/npcpostdialog.h @@ -67,10 +67,9 @@ class NpcPostDialog final : public Window, typedef std::list<NpcPostDialog*> DialogList; static DialogList instances; - int mNpcId; - TextBox *mText; TextField *mSender; + int mNpcId; }; #endif // GUI_WINDOWS_NPCPOSTDIALOG_H diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index 6fcea7d3a..b1355ba46 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -66,18 +66,18 @@ OutfitWindow::OutfitWindow(): // TRANSLATORS: outfits window checkbox mAwayOutfitCheck(new CheckBox(this, _("Away outfit"), serverConfig.getValue("OutfitAwayIndex", OUTFITS_COUNT - 1))), - mCurrentOutfit(0), // TRANSLATORS: outfits window label mKeyLabel(new Label(this, strprintf(_("Key: %s"), - keyName(mCurrentOutfit).c_str()))), + keyName(0).c_str()))), + mBorderColor(getThemeColor(Theme::BORDER, 64)), + mBackgroundColor(getThemeColor(Theme::BACKGROUND, 32)), + mCurrentOutfit(0), mBoxWidth(33), mBoxHeight(33), mGridWidth(4), mGridHeight(4), mItems(), mAwayOutfit(0), - mBorderColor(getThemeColor(Theme::BORDER, 64)), - mBackgroundColor(getThemeColor(Theme::BACKGROUND, 32)), mItemColors(), mItemClicked(false), mItemsUnequip() diff --git a/src/gui/windows/outfitwindow.h b/src/gui/windows/outfitwindow.h index 55948f834..cf60c32ad 100644 --- a/src/gui/windows/outfitwindow.h +++ b/src/gui/windows/outfitwindow.h @@ -94,19 +94,22 @@ class OutfitWindow final : public Window, void clearCurrentOutfit(); private: + int getIndexFromGrid(const int pointX, + const int pointY) const A_WARN_UNUSED; + void save() const; + Button *mPreviousButton; Button *mNextButton; Button *mEquipButtom; Label *mCurrentLabel; CheckBox *mUnequipCheck; CheckBox *mAwayOutfitCheck; - int mCurrentOutfit; Label *mKeyLabel; - int getIndexFromGrid(const int pointX, - const int pointY) const A_WARN_UNUSED; - void save() const; + Color mBorderColor; + Color mBackgroundColor; + int mCurrentOutfit; int mBoxWidth; int mBoxHeight; int mGridWidth; @@ -115,8 +118,6 @@ class OutfitWindow final : public Window, int mItems[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT]; int mAwayOutfit; - Color mBorderColor; - Color mBackgroundColor; unsigned char mItemColors[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT]; bool mItemClicked; bool mItemsUnequip[OUTFITS_COUNT]; diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp index eee3e4259..8d4eae9c8 100644 --- a/src/gui/windows/questswindow.cpp +++ b/src/gui/windows/questswindow.cpp @@ -122,14 +122,14 @@ QuestsWindow::QuestsWindow() : getOptionBool("showtextbackground"), "quests_text_background.xml")), // TRANSLATORS: quests window button mCloseButton(new Button(this, _("Close"), "close", this)), + mCompleteIcon(Theme::getImageFromThemeXml("complete_icon.xml", "")), + mIncompleteIcon(Theme::getImageFromThemeXml("incomplete_icon.xml", "")), mVars(), mQuests(), mAllEffects(), mMapEffects(), mNpcEffects(), mQuestLinks(), - mCompleteIcon(Theme::getImageFromThemeXml("complete_icon.xml", "")), - mIncompleteIcon(Theme::getImageFromThemeXml("incomplete_icon.xml", "")), mNewQuestEffectId(paths.getIntValue("newQuestEffectId")), mCompleteQuestEffectId(paths.getIntValue("completeQuestEffectId")), mMap(nullptr) @@ -149,12 +149,12 @@ QuestsWindow::QuestsWindow() : mQuestsListBox->setActionEventId("select"); mQuestsListBox->addActionListener(this); - mQuestScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mQuestScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mText->setOpaque(false); mText->setLinkHandler(mItemLinkHandler); - mTextScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mTextScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mQuestsListBox->setWidth(500); - if (gui && gui->getNpcFont()->getHeight() < 20) + if (!gui || gui->getNpcFont()->getHeight() < 20) mQuestsListBox->setRowHeight(20); else mQuestsListBox->setRowHeight(gui->getNpcFont()->getHeight()); diff --git a/src/gui/windows/questswindow.h b/src/gui/windows/questswindow.h index 9000fcaa9..df1cca467 100644 --- a/src/gui/windows/questswindow.h +++ b/src/gui/windows/questswindow.h @@ -85,6 +85,8 @@ class QuestsWindow final : public Window, BrowserBox *mText; ScrollArea *mTextScrollArea; Button *mCloseButton; + Image *mCompleteIcon; + Image *mIncompleteIcon; // quest variables: var, value std::map<int, int> mVars; // quests: var, quests @@ -94,8 +96,6 @@ class QuestsWindow final : public Window, // npc effects for current map and values: npc, effect NpcQuestEffectMap mNpcEffects; std::vector<QuestItem*> mQuestLinks; - Image *mCompleteIcon; - Image *mIncompleteIcon; int mNewQuestEffectId; int mCompleteQuestEffectId; const Map *mMap; diff --git a/src/gui/windows/selldialog.cpp b/src/gui/windows/selldialog.cpp index 8bfcc6728..ebee65d1e 100644 --- a/src/gui/windows/selldialog.cpp +++ b/src/gui/windows/selldialog.cpp @@ -56,7 +56,11 @@ SellDialog::SellDialog(const int npcId) : Window(_("Sell"), false, nullptr, "sell.xml"), ActionListener(), SelectionListener(), - mNpcId(npcId), mMaxItems(0), mAmountItems(0), mNick("") + mNick(""), + mNpcId(npcId), + mPlayerMoney(0), + mMaxItems(0), + mAmountItems(0) { init(); } @@ -66,7 +70,11 @@ SellDialog::SellDialog(const std::string &nick): Window(_("Sell"), false, nullptr, "sell.xml"), ActionListener(), SelectionListener(), - mNpcId(-1), mMaxItems(0), mAmountItems(0), mNick(nick) + mNick(nick), + mNpcId(-1), + mPlayerMoney(0), + mMaxItems(0), + mAmountItems(0) { init(); } @@ -89,7 +97,7 @@ void SellDialog::init() mShopItemList->setProtectItems(true); mScrollArea = new ScrollArea(this, mShopItemList, getOptionBool("showbackground"), "sell_background.xml"); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mSlider = new Slider(this, 1.0); @@ -162,7 +170,7 @@ SellDialog::~SellDialog() void SellDialog::reset() { mShopItems->clear(); - mSlider->setValue2(0); + mSlider->setValue(0); mShopItemList->setSelected(-1); updateButtonsAndLabels(); } @@ -213,19 +221,19 @@ void SellDialog::action(const ActionEvent &event) else if (eventId == "inc" && mAmountItems < mMaxItems) { mAmountItems++; - mSlider->setValue2(mAmountItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } else if (eventId == "dec" && mAmountItems > 1) { mAmountItems--; - mSlider->setValue2(mAmountItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } else if (eventId == "max") { mAmountItems = mMaxItems; - mSlider->setValue2(mAmountItems); + mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } else if ((eventId == "presell" || eventId == "sell" || eventId == "yes") @@ -269,7 +277,7 @@ void SellDialog::action(const ActionEvent &event) mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice(); mAmountItems = 1; - mSlider->setValue2(0); + mSlider->setValue(0); if (mMaxItems) { @@ -304,7 +312,7 @@ void SellDialog::valueChanged(const SelectionEvent &event A_UNUSED) { // Reset amount of items and update labels mAmountItems = 1; - mSlider->setValue2(0); + mSlider->setValue(0); updateButtonsAndLabels(); mSlider->setScale(1, mMaxItems); diff --git a/src/gui/windows/selldialog.h b/src/gui/windows/selldialog.h index bd270919e..0cfffbf38 100644 --- a/src/gui/windows/selldialog.h +++ b/src/gui/windows/selldialog.h @@ -122,7 +122,7 @@ class SellDialog final : public Window, */ void updateButtonsAndLabels(); - int mNpcId; + std::string mNick; Button *mSellButton; Button *mQuitButton; @@ -134,14 +134,12 @@ class SellDialog final : public Window, Label *mMoneyLabel; Label *mQuantityLabel; Slider *mSlider; - ShopItems *mShopItems; - int mPlayerMoney; + int mNpcId; + int mPlayerMoney; int mMaxItems; int mAmountItems; - - std::string mNick; }; #endif // GUI_WINDOWS_SELLDIALOG_H diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp index af29da656..112d1588d 100644 --- a/src/gui/windows/serverdialog.cpp +++ b/src/gui/windows/serverdialog.cpp @@ -193,6 +193,8 @@ ServerDialog::ServerDialog(ServerInfo *const serverInfo, KeyListener(), SelectionListener(), mMutex(), + mServers(ServerInfos()), + mDir(dir), mDescription(new Label(this, std::string())), // TRANSLATORS: servers dialog button mQuitButton(new Button(this, _("Quit"), "quit", this)), @@ -206,15 +208,13 @@ ServerDialog::ServerDialog(ServerInfo *const serverInfo, mDeleteButton(new Button(this, _("Delete"), "remove", this)), // TRANSLATORS: servers dialog button mLoadButton(new Button(this, _("Load"), "load", this)), - mServers(ServerInfos()), mServersListModel(new ServersListModel(&mServers, this)), mServersList(new ServersListBox(this, mServersListModel)), - mDir(dir), - mDownloadStatus(DOWNLOADING_UNKNOWN), mDownload(nullptr), - mDownloadProgress(-1.0F), mServerInfo(serverInfo), - mPersistentIPCheckBox(nullptr) + mPersistentIPCheckBox(nullptr), + mDownloadProgress(-1.0F), + mDownloadStatus(DOWNLOADING_UNKNOWN) { mServersList->postInit(); @@ -240,7 +240,7 @@ ServerDialog::ServerDialog(ServerInfo *const serverInfo, ScrollArea *const usedScroll = new ScrollArea(this, mServersList, getOptionBool("showbackground"), "server_background.xml"); - usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + usedScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mServersList->addSelectionListener(this); usedScroll->setVerticalScrollAmount(0); diff --git a/src/gui/windows/serverdialog.h b/src/gui/windows/serverdialog.h index 39c82279e..7c3a05ab3 100644 --- a/src/gui/windows/serverdialog.h +++ b/src/gui/windows/serverdialog.h @@ -118,6 +118,8 @@ class ServerDialog final : public Window, size_t total, size_t remaining); Mutex mMutex; + ServerInfos mServers; + const std::string &mDir; Label *mDescription; Button *mQuitButton; Button *mConnectButton; @@ -125,13 +127,9 @@ class ServerDialog final : public Window, Button *mEditEntryButton; Button *mDeleteButton; Button *mLoadButton; - - ServerInfos mServers; ServersListModel *mServersListModel; ListBox *mServersList; - const std::string &mDir; - enum ServerDialogDownloadStatus { DOWNLOADING_UNKNOWN = 0, @@ -144,11 +142,11 @@ class ServerDialog final : public Window, }; /** Status of the current download. */ - ServerDialogDownloadStatus mDownloadStatus; Net::Download *mDownload; - float mDownloadProgress; ServerInfo *mServerInfo; CheckBox *mPersistentIPCheckBox; + float mDownloadProgress; + ServerDialogDownloadStatus mDownloadStatus; }; #endif // GUI_WINDOWS_SERVERDIALOG_H diff --git a/src/gui/windows/setupwindow.cpp b/src/gui/windows/setupwindow.cpp index 2bcac85a5..1760d00bd 100644 --- a/src/gui/windows/setupwindow.cpp +++ b/src/gui/windows/setupwindow.cpp @@ -61,9 +61,9 @@ SetupWindow::SetupWindow() : Window(_("Setup"), false, nullptr, "setup.xml"), ActionListener(), mTabs(), - mModsTab(nullptr), mWindowsToReset(), mButtons(), + mModsTab(nullptr), mResetWindows(nullptr), mPanel(new TabbedArea(this)), mVersion(new Label(this, FULL_VERSION)) diff --git a/src/gui/windows/setupwindow.h b/src/gui/windows/setupwindow.h index 38b3eb206..e604bf0de 100644 --- a/src/gui/windows/setupwindow.h +++ b/src/gui/windows/setupwindow.h @@ -77,9 +77,9 @@ class SetupWindow final : public Window, void unloadModTab(); std::list<SetupTab*> mTabs; - SetupTab *mModsTab; std::list<Window*> mWindowsToReset; std::vector<Button*> mButtons; + SetupTab *mModsTab; Button *mResetWindows; TabbedArea *mPanel; Label *mVersion; diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 32e249d35..923511baa 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -78,6 +78,7 @@ ShopWindow::ShopWindow(): mCloseButton(new Button(this, _("Close"), "close", this)), mBuyShopItems(new ShopItems), mSellShopItems(new ShopItems), + mTradeItem(nullptr), mBuyShopItemList(new ShopListBox(this, mBuyShopItems, mBuyShopItems)), mSellShopItemList(new ShopListBox(this, mSellShopItems, mSellShopItems)), mBuyScrollArea(new ScrollArea(this, mBuyShopItemList, @@ -106,14 +107,13 @@ ShopWindow::ShopWindow(): // TRANSLATORS: shop window checkbox mAnnounceLinks(new CheckBox(this, _("Show links in announce"), false, this, "link announce")), + mAcceptPlayer(""), + mTradeNick(""), mSelectedItem(-1), mAnnonceTime(0), mLastRequestTimeList(0), mLastRequestTimeItem(0), mRandCounter(0), - mAcceptPlayer(""), - mTradeItem(nullptr), - mTradeNick(""), mTradeMoney(0) { mBuyShopItemList->postInit(); @@ -138,8 +138,8 @@ ShopWindow::ShopWindow(): mBuyShopItemList->setPriceCheck(false); mSellShopItemList->setPriceCheck(false); - mBuyScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - mSellScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mBuyScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mSellScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mBuyShopItemList->addSelectionListener(this); mSellShopItemList->addSelectionListener(this); diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h index 76971364b..5b5a8309b 100644 --- a/src/gui/windows/shopwindow.h +++ b/src/gui/windows/shopwindow.h @@ -147,6 +147,7 @@ class ShopWindow final : public Window, ShopItems *mBuyShopItems; ShopItems *mSellShopItems; + ShopItem *mTradeItem; ShopListBox *mBuyShopItemList; ShopListBox *mSellShopItemList; @@ -163,15 +164,13 @@ class ShopWindow final : public Window, Button *mSellAnnounceButton; Button *mSellAuctionButton; CheckBox *mAnnounceLinks; - + std::string mAcceptPlayer; + std::string mTradeNick; int mSelectedItem; int mAnnonceTime; int mLastRequestTimeList; int mLastRequestTimeItem; int mRandCounter; - std::string mAcceptPlayer; - ShopItem *mTradeItem; - std::string mTradeNick; int mTradeMoney; int mAnnounceCounter[2]; }; diff --git a/src/gui/windows/shortcutwindow.cpp b/src/gui/windows/shortcutwindow.cpp index 5b3c03e90..6ec442cd5 100644 --- a/src/gui/windows/shortcutwindow.cpp +++ b/src/gui/windows/shortcutwindow.cpp @@ -97,7 +97,7 @@ ShortcutWindow::ShortcutWindow(const std::string &restrict title, mBoxesWidth += bw + border; mScrollArea->setPosition(SCROLL_PADDING, SCROLL_PADDING); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); place(0, 0, mScrollArea, 5, 5).setPadding(0); @@ -163,7 +163,7 @@ void ShortcutWindow::addTab(const std::string &name, { ScrollArea *const scroll = new ScrollArea(this, content, false); scroll->setPosition(SCROLL_PADDING, SCROLL_PADDING); - scroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); content->setWidget2(this); Tab *const tab = new ShortcutTab(this, name, content); mTabs->addTab(tab, scroll); diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp index f33534a85..8e6becca1 100644 --- a/src/gui/windows/socialwindow.cpp +++ b/src/gui/windows/socialwindow.cpp @@ -198,8 +198,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); } A_DELETE_COPY(SocialGuildTab) @@ -334,8 +334,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); } A_DELETE_COPY(SocialGuildTab2) @@ -403,8 +403,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); } A_DELETE_COPY(SocialPartyTab) @@ -519,8 +519,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); getPlayersAvatars(); setCaption(name); @@ -685,8 +685,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); // TRANSLATORS: Navigation tab name in social window. Should be small setCaption(_("Nav")); @@ -1014,8 +1014,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); // TRANSLATORS: Attack filter tab name in social window. Should be small setCaption(_("Atk")); @@ -1061,8 +1061,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); // TRANSLATORS: Pickup filter tab name in social window. Should be small setCaption(_("Pik")); @@ -1108,8 +1108,8 @@ public: mScroll = new ScrollArea(this, mList, showBackground, "social_background.xml"); - mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); - mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); getPlayersAvatars(); setCaption(name); @@ -1255,10 +1255,10 @@ SocialWindow::SocialWindow() : mGuildAcceptDialog(nullptr), mGuildCreateDialog(nullptr), mPartyInviter(), - mPartyAcceptDialog(nullptr), - mPartyCreateDialog(nullptr), mGuilds(), mParties(), + mPartyAcceptDialog(nullptr), + mPartyCreateDialog(nullptr), mAttackFilter(nullptr), mPickupFilter(nullptr), // TRANSLATORS: here P is title for visible players tab in social window diff --git a/src/gui/windows/socialwindow.h b/src/gui/windows/socialwindow.h index 57fbd5be5..f0bfe1fb9 100644 --- a/src/gui/windows/socialwindow.h +++ b/src/gui/windows/socialwindow.h @@ -138,23 +138,21 @@ public: protected: friend class SocialTab; + typedef std::map<Guild*, SocialTab*> GuildMap; + typedef std::map<Party*, SocialTab*> PartyMap; void updateButtons(); int mGuildInvited; ConfirmDialog *mGuildAcceptDialog; TextDialog *mGuildCreateDialog; - std::string mPartyInviter; - ConfirmDialog *mPartyAcceptDialog; - TextDialog *mPartyCreateDialog; - - typedef std::map<Guild*, SocialTab*> GuildMap; GuildMap mGuilds; - - typedef std::map<Party*, SocialTab*> PartyMap; PartyMap mParties; + ConfirmDialog *mPartyAcceptDialog; + TextDialog *mPartyCreateDialog; + SocialTab *mAttackFilter; SocialTab *mPickupFilter; SocialTab *mPlayers; diff --git a/src/gui/windows/textcommandeditor.h b/src/gui/windows/textcommandeditor.h index de7f3b1a4..915ef204c 100644 --- a/src/gui/windows/textcommandeditor.h +++ b/src/gui/windows/textcommandeditor.h @@ -68,18 +68,16 @@ class TextCommandEditor final : public Window, void deleteCommand(); bool mIsMagicCommand; - TextCommand *mCommand; + TextCommand *mCommand; RadioButton *mIsMagic; RadioButton *mIsOther; Label *mSymbolLabel; TextField *mSymbolTextField; Label *mCommandLabel; TextField *mCommandTextField; - Label *mCommentLabel; TextField *mCommentTextField; - TargetTypeModel *mTargetTypeModel; Label *mTypeLabel; DropDown *mTypeDropDown; diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp index 506f25c17..f05cf1cac 100644 --- a/src/gui/windows/tradewindow.cpp +++ b/src/gui/windows/tradewindow.cpp @@ -80,13 +80,13 @@ TradeWindow::TradeWindow(): // TRANSLATORS: trade window money change button mMoneyChangeButton(new Button(this, _("Change"), "money", this)), mMoneyField(new TextField(this)), - mStatus(PROPOSING), mAutoAddItem(nullptr), mAutoAddToNick(""), mGotMoney(0), mGotMaxMoney(0), mAutoMoney(0), mAutoAddAmount(0), + mStatus(PROPOSING), mOkOther(false), mOkMe(false) { @@ -440,7 +440,7 @@ void TradeWindow::initTrade(const std::string &nick) const Inventory *const inv = PlayerInfo::getInventory(); if (inv) { - Item *const item = inv->findItem(mAutoAddItem->getId(), + const Item *const item = inv->findItem(mAutoAddItem->getId(), mAutoAddItem->getColor()); if (item) tradeItem(item, mAutoAddAmount); diff --git a/src/gui/windows/tradewindow.h b/src/gui/windows/tradewindow.h index 9704c1e80..447e99144 100644 --- a/src/gui/windows/tradewindow.h +++ b/src/gui/windows/tradewindow.h @@ -171,13 +171,13 @@ class TradeWindow final : public Window, Button *mMoneyChangeButton; TextField *mMoneyField; - Status mStatus; Item* mAutoAddItem; std::string mAutoAddToNick; int mGotMoney; int mGotMaxMoney; int mAutoMoney; int mAutoAddAmount; + Status mStatus; bool mOkOther; bool mOkMe; }; diff --git a/src/gui/windows/unregisterdialog.h b/src/gui/windows/unregisterdialog.h index 206c05413..207f2fef3 100644 --- a/src/gui/windows/unregisterdialog.h +++ b/src/gui/windows/unregisterdialog.h @@ -61,12 +61,9 @@ class UnRegisterDialog final : public Window, private: LoginData *mLoginData; - TextField *mPasswordField; - Button *mUnRegisterButton; Button *mCancelButton; - WrongDataNoticeListener *mWrongDataNoticeListener; }; diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index e72308da7..247ef8707 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -159,27 +159,19 @@ UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost, Window(_("Updating..."), false, nullptr, "update.xml"), ActionListener(), KeyListener(), - mDownloadStatus(UPDATE_NEWS), + mDownloadProgress(0.0F), mUpdateHost(updateHost), mUpdatesDir(updatesDir), mUpdatesDirReal(updatesDir), mCurrentFile("news.txt"), mNewLabelCaption(), - mDownloadProgress(0.0F), mDownloadMutex(), mCurrentChecksum(0), - mStoreInMemory(true), - mDownloadComplete(true), - mUserCancel(false), - mDownloadedBytes(0), mMemoryBuffer(nullptr), mDownload(nullptr), mUpdateFiles(), mTempUpdateFiles(), - mUpdateIndex(0), - mUpdateIndexOffset(0), - mLoadUpdates(applyUpdates), - mUpdateType(updateType), + mUpdateServerPath(mUpdateHost), // TRANSLATORS: updater window label mLabel(new Label(this, _("Connecting..."))), // TRANSLATORS: updater window button @@ -192,7 +184,15 @@ UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost, "browserbox.xml")), mScrollArea(new ScrollArea(this, mBrowserBox, true, "update_background.xml")), - mUpdateServerPath(mUpdateHost) + mDownloadStatus(UPDATE_NEWS), + mDownloadedBytes(0), + mUpdateIndex(0), + mUpdateIndexOffset(0), + mUpdateType(updateType), + mStoreInMemory(true), + mDownloadComplete(true), + mUserCancel(false), + mLoadUpdates(applyUpdates) { setWindowName("UpdaterWindow"); setResizable(true); diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h index 79d764752..39e1e84f3 100644 --- a/src/gui/windows/updaterwindow.h +++ b/src/gui/windows/updaterwindow.h @@ -198,8 +198,8 @@ private: UPDATE_RESOURCES2 }; - /** Status of the current download. */ - UpdateDownloadStatus mDownloadStatus; + /** The new progress value to be set in the logic method. */ + float mDownloadProgress; /** Host where we get the updated files. */ std::string mUpdateHost; @@ -215,9 +215,6 @@ private: /** The new label caption to be set in the logic method. */ std::string mNewLabelCaption; - /** The new progress value to be set in the logic method. */ - float mDownloadProgress; - // The mutex used to guard access to mNewLabelCaption // and mDownloadProgress. Mutex mDownloadMutex; @@ -225,18 +222,6 @@ private: /** The Adler32 checksum of the file currently downloading. */ unsigned long mCurrentChecksum; - /** A flag to indicate whether to use a memory buffer or a regular file. */ - bool mStoreInMemory; - - /** Flag that show if current download is complete. */ - bool mDownloadComplete; - - /** Flag that show if the user has canceled the update. */ - bool mUserCancel; - - /** Byte count currently downloaded in mMemoryBuffer. */ - int mDownloadedBytes; - /** Buffer for files downloaded to memory. */ char *mMemoryBuffer; @@ -249,24 +234,40 @@ private: /** List of temp files to download. */ std::vector<UpdateFile> mTempUpdateFiles; + std::string mUpdateServerPath; + + Label *mLabel; /**< Progress bar caption. */ + Button *mCancelButton; /**< Button to stop the update process. */ + Button *mPlayButton; /**< Button to start playing. */ + ProgressBar *mProgressBar; /**< Update progress bar. */ + BrowserBox *mBrowserBox; /**< Box to display news. */ + ScrollArea *mScrollArea; /**< Used to scroll news box. */ + + /** Status of the current download. */ + UpdateDownloadStatus mDownloadStatus; + + /** Byte count currently downloaded in mMemoryBuffer. */ + int mDownloadedBytes; + /** Index of the file to be downloaded. */ unsigned int mUpdateIndex; /** Index offset for disaplay downloaded file. */ unsigned int mUpdateIndexOffset; - /** Tells ~UpdaterWindow() if it should load updates */ - bool mLoadUpdates; - int mUpdateType; - Label *mLabel; /**< Progress bar caption. */ - Button *mCancelButton; /**< Button to stop the update process. */ - Button *mPlayButton; /**< Button to start playing. */ - ProgressBar *mProgressBar; /**< Update progress bar. */ - BrowserBox *mBrowserBox; /**< Box to display news. */ - ScrollArea *mScrollArea; /**< Used to scroll news box. */ - std::string mUpdateServerPath; + /** A flag to indicate whether to use a memory buffer or a regular file. */ + bool mStoreInMemory; + + /** Flag that show if current download is complete. */ + bool mDownloadComplete; + + /** Flag that show if the user has canceled the update. */ + bool mUserCancel; + + /** Tells ~UpdaterWindow() if it should load updates */ + bool mLoadUpdates; }; #endif // GUI_WINDOWS_UPDATERWINDOW_H diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp index dabc8c7c1..a1683ffc8 100644 --- a/src/gui/windows/whoisonline.cpp +++ b/src/gui/windows/whoisonline.cpp @@ -79,20 +79,24 @@ class NameFunctuator final WhoIsOnline::WhoIsOnline() : // TRANSLATORS: who is online window name Window(_("Who Is Online - Updating"), false, nullptr, "whoisonline.xml"), + mUpdateTimer(0), mThread(nullptr), - mDownloadStatus(UPDATE_LIST), - mDownloadComplete(true), - mDownloadedBytes(0), mMemoryBuffer(nullptr), mCurlError(new char[CURL_ERROR_SIZE]), mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, true, "onlinebrowserbox.xml")), mScrollArea(new ScrollArea(this, mBrowserBox, false)), - mUpdateTimer(0), mOnlinePlayers(), mOnlineNicks(), // TRANSLATORS: who is online. button. mUpdateButton(new Button(this, _("Update"), "update", this)), + mFriends(), + mNeutral(), + mDisregard(), + mEnemy(), + mDownloadedBytes(0), + mDownloadStatus(UPDATE_LIST), + mDownloadComplete(true), mAllowUpdate(true), mShowLevel(false), mUpdateOnlineList(config.getBoolValue("updateOnlineList")), @@ -201,22 +205,18 @@ void WhoIsOnline::handleLink(const std::string& link, MouseEvent *event) } } -void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &restrict friends, - std::vector<OnlinePlayer*> &restrict neutral, - std::vector<OnlinePlayer*> &restrict disregard, - std::vector<OnlinePlayer*> &restrict enemy, - size_t numOnline) +void WhoIsOnline::updateWindow(size_t numOnline) { // Set window caption // TRANSLATORS: who is online window name setCaption(_("Who Is Online - ") + toString(numOnline)); // List the online people - std::sort(friends.begin(), friends.end(), nameCompare); - std::sort(neutral.begin(), neutral.end(), nameCompare); - std::sort(disregard.begin(), disregard.end(), nameCompare); + std::sort(mFriends.begin(), mFriends.end(), nameCompare); + std::sort(mNeutral.begin(), mNeutral.end(), nameCompare); + std::sort(mDisregard.begin(), mDisregard.end(), nameCompare); bool addedFromSection(false); - FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, friends) + FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, mFriends) { mBrowserBox->addRow((*it)->getText()); addedFromSection = true; @@ -226,7 +226,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &restrict friends, mBrowserBox->addRow("---"); addedFromSection = false; } - FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, enemy) + FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, mEnemy) { mBrowserBox->addRow((*it)->getText()); addedFromSection = true; @@ -236,15 +236,15 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &restrict friends, mBrowserBox->addRow("---"); addedFromSection = false; } - FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, neutral) + FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, mNeutral) { mBrowserBox->addRow((*it)->getText()); addedFromSection = true; } - if (addedFromSection == true && !disregard.empty()) + if (addedFromSection == true && !mDisregard.empty()) mBrowserBox->addRow("---"); - FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, disregard) + FOR_EACH (std::vector<OnlinePlayer*>::const_iterator, it, mDisregard) mBrowserBox->addRow((*it)->getText()); if (mScrollArea->getVerticalMaxScroll() < @@ -255,14 +255,47 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &restrict friends, } } +void WhoIsOnline::handlerPlayerRelation(const std::string &nick, + OnlinePlayer *const player) +{ + switch (player_relations.getRelation(nick)) + { + case PlayerRelation::NEUTRAL: + default: + setNeutralColor(player); + mNeutral.push_back(player); + break; + + case PlayerRelation::FRIEND: + player->setText("2"); + if (mGroupFriends) + mFriends.push_back(player); + else + mNeutral.push_back(player); + break; + + case PlayerRelation::DISREGARDED: + case PlayerRelation::BLACKLISTED: + player->setText("8"); + mDisregard.push_back(player); + break; + + case PlayerRelation::ENEMY2: + player->setText("1"); + mEnemy.push_back(player); + break; + + case PlayerRelation::IGNORED: + case PlayerRelation::ERASED: + // Ignore the ignored. + break; + } +} + void WhoIsOnline::loadList(std::vector<OnlinePlayer*> &list) { mBrowserBox->clearRows(); const size_t numOnline = list.size(); - std::vector<OnlinePlayer*> friends; - std::vector<OnlinePlayer*> neutral; - std::vector<OnlinePlayer*> disregard; - std::vector<OnlinePlayer*> enemy; FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers) delete *itd; @@ -281,41 +314,10 @@ void WhoIsOnline::loadList(std::vector<OnlinePlayer*> &list) if (!mShowLevel) player->setLevel(0); - switch (player_relations.getRelation(nick)) - { - case PlayerRelation::NEUTRAL: - default: - setNeutralColor(player); - neutral.push_back(player); - break; - - case PlayerRelation::FRIEND: - player->setText("2"); - if (mGroupFriends) - friends.push_back(player); - else - neutral.push_back(player); - break; - - case PlayerRelation::DISREGARDED: - case PlayerRelation::BLACKLISTED: - player->setText("8"); - disregard.push_back(player); - break; - - case PlayerRelation::ENEMY2: - player->setText("1"); - enemy.push_back(player); - break; - - case PlayerRelation::IGNORED: - case PlayerRelation::ERASED: - // Ignore the ignored. - break; - } + handlerPlayerRelation(nick, player); } - updateWindow(friends, neutral, disregard, enemy, numOnline); + updateWindow(numOnline); if (!mOnlineNicks.empty()) { if (chatWindow) @@ -324,6 +326,10 @@ void WhoIsOnline::loadList(std::vector<OnlinePlayer*> &list) socialWindow->updateActiveList(); } updateSize(); + mFriends.clear(); + mNeutral.clear(); + mDisregard.clear(); + mEnemy.clear(); } void WhoIsOnline::loadWebList() @@ -343,10 +349,6 @@ void WhoIsOnline::loadWebList() bool listStarted(false); std::string lineStr; int numOnline(0); - std::vector<OnlinePlayer*> friends; - std::vector<OnlinePlayer*> neutral; - std::vector<OnlinePlayer*> disregard; - std::vector<OnlinePlayer*> enemy; // Tokenize and add each line separately char *line = strtok(mMemoryBuffer, "\n"); @@ -441,38 +443,7 @@ void WhoIsOnline::loadWebList() player->setIsGM(true); numOnline++; - switch (player_relations.getRelation(nick)) - { - case PlayerRelation::NEUTRAL: - default: - setNeutralColor(player); - neutral.push_back(player); - break; - - case PlayerRelation::FRIEND: - player->setText("2"); - if (mGroupFriends) - friends.push_back(player); - else - neutral.push_back(player); - break; - - case PlayerRelation::DISREGARDED: - case PlayerRelation::BLACKLISTED: - player->setText("8"); - disregard.push_back(player); - break; - - case PlayerRelation::ENEMY2: - player->setText("1"); - enemy.push_back(player); - break; - - case PlayerRelation::IGNORED: - case PlayerRelation::ERASED: - // Ignore the ignored. - break; - } + handlerPlayerRelation(nick, player); } } else if (lineStr.find("------------------------------") @@ -483,11 +454,15 @@ void WhoIsOnline::loadWebList() line = strtok(nullptr, "\n"); } - updateWindow(friends, neutral, disregard, enemy, numOnline); + updateWindow(numOnline); // Free the memory buffer now that we don't need it anymore free(mMemoryBuffer); mMemoryBuffer = nullptr; + mFriends.clear(); + mNeutral.clear(); + mDisregard.clear(); + mEnemy.clear(); } size_t WhoIsOnline::memoryWrite(void *ptr, size_t size, diff --git a/src/gui/windows/whoisonline.h b/src/gui/windows/whoisonline.h index bc04c8066..915150409 100644 --- a/src/gui/windows/whoisonline.h +++ b/src/gui/windows/whoisonline.h @@ -162,6 +162,8 @@ private: void updateSize(); + void handlerPlayerRelation(const std::string &nick, + OnlinePlayer *const player); /** * The thread function that download the files. */ @@ -178,11 +180,7 @@ private: const std::string &restrict color) const A_WARN_UNUSED; - void updateWindow(std::vector<OnlinePlayer*> &restrict friends, - std::vector<OnlinePlayer*> &restrict neutral, - std::vector<OnlinePlayer*> &restrict disregard, - std::vector<OnlinePlayer*> &restrict enemy, - size_t numOnline); + void updateWindow(size_t numOnline); enum DownloadStatus { @@ -191,18 +189,11 @@ private: UPDATE_LIST }; + time_t mUpdateTimer; + /** A thread that use libcurl to download updates. */ SDL_Thread *mThread; - /** Status of the current download. */ - DownloadStatus mDownloadStatus; - - /** Flag that show if current download is complete. */ - bool mDownloadComplete; - - /** Byte count currently downloaded in mMemoryBuffer. */ - int mDownloadedBytes; - /** Buffer for files downloaded to memory. */ char *mMemoryBuffer; @@ -211,11 +202,23 @@ private: BrowserBox *mBrowserBox; ScrollArea *mScrollArea; - time_t mUpdateTimer; std::set<OnlinePlayer*> mOnlinePlayers; std::set<std::string> mOnlineNicks; Button *mUpdateButton; + std::vector<OnlinePlayer*> mFriends; + std::vector<OnlinePlayer*> mNeutral; + std::vector<OnlinePlayer*> mDisregard; + std::vector<OnlinePlayer*> mEnemy; + + /** Byte count currently downloaded in mMemoryBuffer. */ + int mDownloadedBytes; + + /** Status of the current download. */ + DownloadStatus mDownloadStatus; + + /** Flag that show if current download is complete. */ + bool mDownloadComplete; bool mAllowUpdate; bool mShowLevel; bool mUpdateOnlineList; diff --git a/src/gui/windows/worldselectdialog.cpp b/src/gui/windows/worldselectdialog.cpp index 77d167c82..58c1aaee8 100644 --- a/src/gui/windows/worldselectdialog.cpp +++ b/src/gui/windows/worldselectdialog.cpp @@ -60,7 +60,7 @@ WorldSelectDialog::WorldSelectDialog(Worlds worlds): ScrollArea *const worldsScroll = new ScrollArea(this, mWorldList, getOptionBool("showbackground"), "world_background.xml"); - worldsScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + worldsScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); place(0, 0, worldsScroll, 3, 5).setPadding(2); place(1, 5, mChangeLoginButton); diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 5d157f0fa..d611e4790 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -216,69 +216,46 @@ void InputManager::store() const } } -void InputManager::resetKeys() +void InputManager::resetKey(const int i) { - for (int i = 0; i < Input::KEY_TOTAL; i++) + KeyFunction &key = mKey[i]; + for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++) { - KeyFunction &key = mKey[i]; - for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++) - { - KeyItem &ki2 = key.values[i2]; - ki2.type = INPUT_UNKNOWN; - ki2.value = -1; - } - const KeyData &kd = keyData[i]; - KeyItem &val0 = key.values[0]; - val0.type = kd.defaultType1; - KeyItem &val1 = key.values[1]; - val1.type = kd.defaultType2; + KeyItem &ki2 = key.values[i2]; + ki2.type = INPUT_UNKNOWN; + ki2.value = -1; + } + const KeyData &kd = keyData[i]; + KeyItem &val0 = key.values[0]; + val0.type = kd.defaultType1; + KeyItem &val1 = key.values[1]; + val1.type = kd.defaultType2; #ifdef USE_SDL2 - if (kd.defaultType1 == INPUT_KEYBOARD) - val0.value = SDL_GetScancodeFromKey(kd.defaultValue1); - else - val0.value = kd.defaultValue1; - if (kd.defaultType2 == INPUT_KEYBOARD) - val1.value = SDL_GetScancodeFromKey(kd.defaultValue2); - else - val1.value = kd.defaultValue2; -#else + if (kd.defaultType1 == INPUT_KEYBOARD) + val0.value = SDL_GetScancodeFromKey(kd.defaultValue1); + else val0.value = kd.defaultValue1; + if (kd.defaultType2 == INPUT_KEYBOARD) + val1.value = SDL_GetScancodeFromKey(kd.defaultValue2); + else val1.value = kd.defaultValue2; +#else + val0.value = kd.defaultValue1; + val1.value = kd.defaultValue2; #endif - } +} + +void InputManager::resetKeys() +{ + for (int i = 0; i < Input::KEY_TOTAL; i++) + resetKey(i); } void InputManager::makeDefault(const int i) { if (i >= 0 && i < Input::KEY_TOTAL) { - KeyFunction &key = mKey[i]; - for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++) - { - KeyItem &ki2 = key.values[i2]; - ki2.type = INPUT_UNKNOWN; - ki2.value = -1; - } - const KeyData &kd = keyData[i]; - KeyItem &val0 = key.values[0]; - val0.type = kd.defaultType1; - KeyItem &val1 = key.values[1]; - val1.type = kd.defaultType2; - -#ifdef USE_SDL2 - if (kd.defaultType1 == INPUT_KEYBOARD) - val0.value = SDL_GetScancodeFromKey(kd.defaultValue1); - else - val0.value = kd.defaultValue1; - if (kd.defaultType2 == INPUT_KEYBOARD) - val1.value = SDL_GetScancodeFromKey(kd.defaultValue2); - else - val1.value = kd.defaultValue2; -#else - val0.value = kd.defaultValue1; - val1.value = kd.defaultValue2; -#endif - + resetKey(i); update(); } } diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index fcd1252c0..bf9e04f34 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -181,6 +181,8 @@ class InputManager final void executeAction(const int keyNum); protected: + void resetKey(const int i); + static bool isActionActive0(const int index) A_WARN_UNUSED; Setup_Input *mSetupInput; /**< Reference to setup window */ diff --git a/src/input/keyboarddata.h b/src/input/keyboarddata.h index e6bafb61b..37a36b45f 100644 --- a/src/input/keyboarddata.h +++ b/src/input/keyboarddata.h @@ -1977,7 +1977,7 @@ static const KeyData keyData[Input::KEY_TOTAL] = { COND_ARROWKEYS}, {"keyGUICtrl", INPUT_KEYBOARD, SDLK_LCTRL, - INPUT_UNKNOWN, Input::KEY_NO_VALUE, + INPUT_KEYBOARD, SDLK_RCTRL, Input::GRP_GUICHAN, nullptr, Input::KEY_NO_VALUE, 50, @@ -2087,6 +2087,98 @@ static const KeyData keyData[Input::KEY_TOTAL] = { &ActionManager::openTrade, Input::KEY_NO_VALUE, 50, COND_GAME | COND_NOTARGET}, + + {"keyGUIF1", + INPUT_KEYBOARD, SDLK_F1, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF2", + INPUT_KEYBOARD, SDLK_F2, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF3", + INPUT_KEYBOARD, SDLK_F3, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF4", + INPUT_KEYBOARD, SDLK_F4, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF5", + INPUT_KEYBOARD, SDLK_F5, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF6", + INPUT_KEYBOARD, SDLK_F6, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF7", + INPUT_KEYBOARD, SDLK_F7, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF8", + INPUT_KEYBOARD, SDLK_F8, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF9", + INPUT_KEYBOARD, SDLK_F9, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF10", + INPUT_KEYBOARD, SDLK_F10, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF11", + INPUT_KEYBOARD, SDLK_F11, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIF12", + INPUT_KEYBOARD, SDLK_F12, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN | Input::GRP_CHAT, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyWindowAbout", + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_DEFAULT | Input::GRP_GUI, + &ActionManager::aboutWindowShow, + Input::KEY_NO_VALUE, 50, + COND_SHORTCUT0}, }; #endif // INPUT_KEYBOARDDATA_H diff --git a/src/input/keydata.h b/src/input/keydata.h index 62517b64b..41a0e85a5 100644 --- a/src/input/keydata.h +++ b/src/input/keydata.h @@ -358,6 +358,19 @@ namespace Input KEY_PREV_COMMANDS_TAB, KEY_NEXT_COMMANDS_TAB, KEY_OPEN_TRADE, + KEY_GUI_F1, + KEY_GUI_F2, + KEY_GUI_F3, + KEY_GUI_F4, + KEY_GUI_F5, + KEY_GUI_F6, + KEY_GUI_F7, + KEY_GUI_F8, + KEY_GUI_F9, + KEY_GUI_F10, + KEY_GUI_F11, + KEY_GUI_F12, + KEY_WINDOW_ABOUT, KEY_TOTAL }; } // namespace Input diff --git a/src/input/keyinput.h b/src/input/keyinput.h index 9920cfa17..b7b7a7936 100644 --- a/src/input/keyinput.h +++ b/src/input/keyinput.h @@ -79,12 +79,7 @@ class KeyInput final #ifdef USE_SDL2 mText(), #endif - mActionId(-2), - mShiftPressed(false), - mControlPressed(false), - mAltPressed(false), - mMetaPressed(false), - mNumericPad(false) + mActionId(-2) { } ~KeyInput() @@ -120,56 +115,6 @@ class KeyInput final return mKey; } - bool isShiftPressed() const - { - return mShiftPressed; - } - - void setShiftPressed(bool pressed) - { - mShiftPressed = pressed; - } - - bool isControlPressed() const - { - return mControlPressed; - } - - void setControlPressed(bool pressed) - { - mControlPressed = pressed; - } - - bool isAltPressed() const - { - return mAltPressed; - } - - void setAltPressed(bool pressed) - { - mAltPressed = pressed; - } - - bool isMetaPressed() const - { - return mMetaPressed; - } - - void setMetaPressed(bool pressed) - { - mMetaPressed = pressed; - } - - bool isNumericPad() const - { - return mNumericPad; - } - - void setNumericPad(bool numpad) - { - mNumericPad = numpad; - } - void setActionId(const int n) { mActionId = n; @@ -208,36 +153,6 @@ class KeyInput final #endif int mActionId; - - /** - * True if shift was pressed at the same time as the key, - * false otherwise. - */ - bool mShiftPressed; - - /** - * True if control was pressed at the same time as the key, - * false otherwise. - */ - bool mControlPressed; - - /** - * True if alt was pressed at the same time as the key, - * false otherwise. - */ - bool mAltPressed; - - /** - * True if meta was pressed at the same time as the key, - * false otherwise. - */ - bool mMetaPressed; - - /** - * True if the numeric pad was used when the key was pressed, - * false otherwise. - */ - bool mNumericPad; }; #endif // INPUT_KEYINPUT_H diff --git a/src/main.h b/src/main.h index 4d43f9447..b0f793360 100644 --- a/src/main.h +++ b/src/main.h @@ -45,8 +45,8 @@ * different interfaces, which have different implementations for each server. */ -#define SMALL_VERSION "1.4.3.1" -#define CHECK_VERSION "01.04.03.01" +#define SMALL_VERSION "1.4.3.15" +#define CHECK_VERSION "01.04.03.15" #ifdef HAVE_CONFIG_H #include "../config.h" diff --git a/src/map.cpp b/src/map.cpp index 70a48b811..c86c51bce 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -381,13 +381,9 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY) // Make sure actors are sorted ascending by Y-coordinate // so that they overlap correctly -// if (mSpritesUpdated) -// { BLOCK_START("Map::draw sort") mActors.sort(actorCompare); BLOCK_END("Map::draw sort") -// mSpritesUpdated = false; -// } // update scrolling of all ambient layers updateAmbientLayers(static_cast<float>(scrollX), @@ -480,15 +476,6 @@ void Map::draw(Graphics *const graphics, int scrollX, int scrollY) else #endif { -/* - if (updateFlag) - { - (*layeri)->updateSDL(graphics, startX, startY, - endX, endY, scrollX, scrollY, mDebugFlags); - } - - (*layeri)->drawSDL(graphics); -*/ layer->draw(graphics, startX, startY, endX, endY, scrollX, scrollY, mDebugFlags); } diff --git a/src/net/download.cpp b/src/net/download.cpp index 141a7772f..6d127d0a4 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -148,11 +148,11 @@ unsigned long Download::fadler32(FILE *const file) return adler; } -unsigned long Download::adlerBuffer(char *buffer, int size) +unsigned long Download::adlerBuffer(char *const buffer, int size) { unsigned long adler = adler32(0L, Z_NULL, 0); return adler32(static_cast<uInt>(adler), - reinterpret_cast<Bytef*>(buffer), size); + reinterpret_cast<const Bytef*>(buffer), size); } void Download::addHeader(const std::string &header) diff --git a/src/net/download.h b/src/net/download.h index bc06f1974..7dae8913f 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -104,7 +104,7 @@ class Download final static void secureCurl(CURL *const curl); - static unsigned long adlerBuffer(char *buffer, int size); + static unsigned long adlerBuffer(char *const buffer, int size); static std::string getUploadResponse() { return mUploadResponse; } diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index de1d6f151..b0be76ac6 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -62,6 +62,9 @@ void GameHandler::processMapLogin(Net::MessageIn &msg) const msg.skip(2); // 0x0505 logger->log("Protocol: Player start position: (%d, %d)," " Direction: %d", x, y, direction); + + mLastHost &= 0xffffff; + // Switch now or we'll have problems client->setState(STATE_GAME); if (player_node) diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 44d834b94..174263dcd 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -291,6 +291,30 @@ void LoginHandler::processLoginError(Net::MessageIn &msg) const client->setState(STATE_ERROR); } +void LoginHandler::loginOrRegister(LoginData *const data) const +{ + if (!data) + return; + + logger->log("Username is %s", data->username.c_str()); + + // Send login infos + if (data->registerLogin) + registerAccount(data); + else + loginAccount(data); + + // Clear the password, avoids auto login when returning to login + data->password.clear(); + + const bool remember = data->remember; + if (remember) + serverConfig.setValue("username", data->username); + else + serverConfig.setValue("username", ""); + serverConfig.setValue("remember", remember); +} + void LoginHandler::logout() const { } diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h index f539176f5..a6e7160cb 100644 --- a/src/net/ea/loginhandler.h +++ b/src/net/ea/loginhandler.h @@ -96,6 +96,8 @@ class LoginHandler : public Net::LoginHandler virtual void processServerVersion(Net::MessageIn &msg) = 0; + void loginOrRegister(LoginData *const data) const override final; + protected: LoginHandler(); diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp index c5ed9de57..128ca2996 100644 --- a/src/net/ea/network.cpp +++ b/src/net/ea/network.cpp @@ -32,6 +32,8 @@ #include "debug.h" +extern unsigned int mLastHost; + namespace Ea { @@ -89,7 +91,6 @@ bool Network::connect(ServerInfo server) if (mState != IDLE && mState != NET_ERROR) { logger->log1("Tried to connect an already connected socket!"); -// assert(false); return false; } @@ -217,6 +218,7 @@ bool Network::realConnect() return false; } + mLastHost = ipAddress.host; logger->log_r("Network::Started session with %s:%i", ipToString(ipAddress.host), ipAddress.port); diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 91c2e4603..6e832aeda 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -99,6 +99,8 @@ class LoginHandler virtual void clearWorlds() = 0; + virtual void loginOrRegister(LoginData *const data) const = 0; + virtual ~LoginHandler() { } diff --git a/src/net/pethandler.h b/src/net/pethandler.h index 7b5666396..688eb3034 100644 --- a/src/net/pethandler.h +++ b/src/net/pethandler.h @@ -41,7 +41,7 @@ class PetHandler const int petId, const int x, const int y) const = 0; - virtual void emote(const uint8_t emoteId, const int petId) const = 0; + virtual void emote(const uint8_t emoteId, const int petId) = 0; }; } // namespace Net diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index 48f216855..899400598 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -49,12 +49,11 @@ public: std::string name; std::string hostname; std::string althostname; - uint16_t port; - std::string description; std::string registerUrl; std::string onlineListUrl; std::string supportUrl; + uint16_t port; VersionString version; bool save; @@ -64,11 +63,11 @@ public: name(), hostname(), althostname(), - port(6901), description(), registerUrl(), onlineListUrl(), supportUrl(), + port(6901), version(), save(false) { @@ -80,11 +79,11 @@ public: name(info.name), hostname(info.hostname), althostname(info.althostname), - port(info.port), description(info.description), registerUrl(info.registerUrl), onlineListUrl(info.onlineListUrl), supportUrl(info.supportUrl), + port(info.port), version(), save(info.save) { diff --git a/src/net/tmwa/pethandler.cpp b/src/net/tmwa/pethandler.cpp index 3293b7edd..77317a077 100644 --- a/src/net/tmwa/pethandler.cpp +++ b/src/net/tmwa/pethandler.cpp @@ -34,7 +34,8 @@ namespace TmwAthena { PetHandler::PetHandler() : - MessageHandler() + MessageHandler(), + mRandCounter(1000) { static const uint16_t _messages[] = { @@ -63,10 +64,14 @@ void PetHandler::spawn(const Being *const being A_UNUSED, { } -void PetHandler::emote(const uint8_t emoteId, const int petId A_UNUSED) const +void PetHandler::emote(const uint8_t emoteId, const int petId A_UNUSED) { - Net::getChatHandler()->talk("\302\202\302e" + toString( - static_cast<int>(emoteId)), GENERAL_CHANNEL); + mRandCounter ++; + if (mRandCounter > 10000) + mRandCounter = 1000; + + Net::getChatHandler()->talk(strprintf("\302\202\302e%dz%d", + static_cast<int>(emoteId), mRandCounter), GENERAL_CHANNEL); } } // namespace TmwAthena diff --git a/src/net/tmwa/pethandler.h b/src/net/tmwa/pethandler.h index 30eff59b8..bcfa6b1a6 100644 --- a/src/net/tmwa/pethandler.h +++ b/src/net/tmwa/pethandler.h @@ -47,7 +47,10 @@ class PetHandler final : public MessageHandler, public Net::PetHandler const int x, const int y) const override final; void emote(const uint8_t emoteId, - const int petId) const override final; + const int petId) override final; + + protected: + int mRandCounter; }; } // namespace TmwAthena diff --git a/src/render/graphicsdef.hpp b/src/render/graphicsdef.hpp new file mode 100644 index 000000000..80d3c7cf8 --- /dev/null +++ b/src/render/graphicsdef.hpp @@ -0,0 +1,146 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +public: + /** + * Draws a rectangle using images. 4 corner images, 4 side images and 1 + * image for the inside. + */ + void drawImageRect(int x, int y, + int w, int h, + const ImageRect &imgRect); + + bool drawNet(const int x1, const int y1, + const int x2, const int y2, + const int width, const int height) override final; + + void _beginDraw(); + + void _endDraw(); + + bool pushClipArea(Rect area) override final; + + void popClipArea() override final; + + /** + * Draws a resclaled version of the image + */ + bool drawRescaledImage(const Image *const image, + int dstX, int dstY, + const int desiredWidth, + const int desiredHeight) override final; + + void drawPattern(const Image *const image, + const int x, const int y, + const int w, const int h) override final; + + void inline drawPatternInline(const Image *const image, + const int x, const int y, + const int w, const int h); + + void drawRescaledPattern(const Image *const image, + const int x, const int y, + const int w, const int h, + const int scaledWidth, + const int scaledHeight) override final; + + void calcPattern(ImageVertexes *const vert, + const Image *const image, + const int x, const int y, + const int w, const int h) const override final; + + void calcPattern(ImageCollection *const vert, + const Image *const image, + const int x, const int y, + const int w, const int h) const override final; + + void calcTileVertexes(ImageVertexes *const vert, + const Image *const image, + int x, int y) const override final; + + void calcTileCollection(ImageCollection *const vertCol, + const Image *const image, + int x, int y) override final; + + void drawTileVertexes(const ImageVertexes *const vert) override final; + + void drawTileCollection(const ImageCollection + *const vertCol) override final; + + void updateScreen() override final; + + /** + * Takes a screenshot and returns it as SDL surface. + */ + SDL_Surface *getScreenshot() override final A_WARN_UNUSED; + + void calcWindow(ImageCollection *const vertCol, + const int x, const int y, + const int w, const int h, + const ImageRect &imgRect) override final; + + void drawRectangle(const Rect &rect) override final; + + void fillRectangle(const Rect &rect) override final; + + void drawPoint(int x, int y) override final; + + void drawLine(int x1, int y1, + int x2, int y2) override final; + + bool setVideoMode(const int w, const int h, + const int scalle, + const int bpp, + const bool fs, + const bool hwaccel, + const bool resize, + const bool noFrame) override final; + + bool drawImage(const Image *const image, + int dstX, int dstY) override final; + + void drawImageCached(const Image *const image, + int x, int y) override final; + + void drawPatternCached(const Image *const image, + const int x, const int y, + const int w, const int h) override final; + + void completeCache() override final; + +private: + void inline calcImageRect(ImageVertexes *const vert, + int x, int y, + int w, int h, + const ImageRect &imgRect); + + void inline calcPatternInline(ImageVertexes *const vert, + const Image *const image, + const int x, const int y, + const int w, const int h) const; + + void inline calcTileVertexesInline(ImageVertexes *const vert, + const Image *const image, + int x, int y) const; + + bool inline drawImageInline(const Image *const image, + int dstX, int dstY); diff --git a/src/render/mobileopenglgraphics.h b/src/render/mobileopenglgraphics.h index 0b9cd83e2..6161c7f29 100644 --- a/src/render/mobileopenglgraphics.h +++ b/src/render/mobileopenglgraphics.h @@ -56,8 +56,6 @@ class MobileOpenGLGraphics final : public Graphics ~MobileOpenGLGraphics(); - #include "render/openglgraphicsdef.hpp" - inline void drawTriangleArrayfs(const GLshort *const shortVertArray, const GLfloat *const floatTexArray, const int size); @@ -68,56 +66,13 @@ class MobileOpenGLGraphics final : public Graphics inline void drawLineArrays(const int size); - inline void drawVertexes(const NormalOpenGLGraphicsVertexes &ogl); - - bool drawNet(const int x1, const int y1, const int x2, const int y2, - const int width, const int height) override final; - - void initArrays() override final; - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, int w, int h, - const ImageRect &imgRect); - -#ifdef DEBUG_DRAW_CALLS - unsigned int getDrawCalls() const - { return mLastDrawCalls; } - - static unsigned int mDrawCalls; - - static unsigned int mLastDrawCalls; -#endif + #include "render/graphicsdef.hpp" - protected: - void setTexturingAndBlending(const bool enable); + #include "render/openglgraphicsdef.hpp" - void debugBindTexture(const Image *const image); + #include "render/openglgraphicsdefadvanced.hpp" private: - void inline setColorAlpha(const float alpha); - - void inline restoreColor(); - - void inline calcImageRect(ImageVertexes *const vert, - int x, int y, - int w, int h, - const ImageRect &imgRect); - - void inline calcPatternInline(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const; - - void inline calcTileVertexesInline(ImageVertexes *const vert, - const Image *const image, - int x, int y) const; - - bool inline drawImageInline(const Image *const image, - int dstX, int dstY); - GLfloat *mFloatTexArray; GLshort *mShortVertArray; GLfloat *mFloatTexArrayCached; diff --git a/src/render/normalopenglgraphics.h b/src/render/normalopenglgraphics.h index 214954e3c..6de8d9397 100644 --- a/src/render/normalopenglgraphics.h +++ b/src/render/normalopenglgraphics.h @@ -56,8 +56,6 @@ class NormalOpenGLGraphics final : public Graphics ~NormalOpenGLGraphics(); - #include "render/openglgraphicsdef.hpp" - inline void drawQuadArrayfi(const int size); inline void drawQuadArrayfiCached(const int size); @@ -78,60 +76,18 @@ class NormalOpenGLGraphics final : public Graphics inline void drawLineArrayf(const int size); - inline void drawVertexes(const NormalOpenGLGraphicsVertexes &ogl); - - bool drawNet(const int x1, const int y1, const int x2, const int y2, - const int width, const int height) override final; - - void initArrays() override final; + #include "render/graphicsdef.hpp" - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, int w, int h, - const ImageRect &imgRect); - -#ifdef DEBUG_DRAW_CALLS - unsigned int getDrawCalls() const - { return mLastDrawCalls; } + #include "render/openglgraphicsdef.hpp" - static unsigned int mDrawCalls; + #include "render/openglgraphicsdefadvanced.hpp" - static unsigned int mLastDrawCalls; -#endif #ifdef DEBUG_BIND_TEXTURE unsigned int getBinds() const { return mLastBinds; } #endif - protected: - void setTexturingAndBlending(const bool enable); - - void debugBindTexture(const Image *const image); - private: - void inline setColorAlpha(const float alpha); - - void inline restoreColor(); - - void inline calcImageRect(ImageVertexes *const vert, - int x, int y, - int w, int h, - const ImageRect &imgRect); - - void inline calcPatternInline(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const; - - void inline calcTileVertexesInline(ImageVertexes *const vert, - const Image *const image, - int x, int y) const; - - bool inline drawImageInline(const Image *const image, - int dstX, int dstY); - GLfloat *mFloatTexArray; GLint *mIntTexArray; GLint *mIntVertArray; diff --git a/src/render/nullopenglgraphics.h b/src/render/nullopenglgraphics.h index ee2a5d189..ebecbe7dd 100644 --- a/src/render/nullopenglgraphics.h +++ b/src/render/nullopenglgraphics.h @@ -56,8 +56,6 @@ class NullOpenGLGraphics final : public Graphics ~NullOpenGLGraphics(); - #include "render/openglgraphicsdef.hpp" - inline void drawQuadArrayfi(const int size); inline void drawQuadArrayfi(const GLint *const intVertArray, @@ -74,56 +72,13 @@ class NullOpenGLGraphics final : public Graphics inline void drawLineArrayf(const int size); - inline void drawVertexes(const NormalOpenGLGraphicsVertexes &ogl); - - bool drawNet(const int x1, const int y1, const int x2, const int y2, - const int width, const int height) override final; - - void initArrays() override final; - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, int w, int h, - const ImageRect &imgRect); - -#ifdef DEBUG_DRAW_CALLS - unsigned int getDrawCalls() const - { return mLastDrawCalls; } - - static unsigned int mDrawCalls; - - static unsigned int mLastDrawCalls; -#endif + #include "render/graphicsdef.hpp" - protected: - void setTexturingAndBlending(const bool enable); + #include "render/openglgraphicsdef.hpp" - void debugBindTexture(const Image *const image); + #include "render/openglgraphicsdefadvanced.hpp" private: - void inline setColorAlpha(const float alpha); - - void inline restoreColor(); - - void inline calcImageRect(ImageVertexes *const vert, - int x, int y, - int w, int h, - const ImageRect &imgRect); - - void inline calcPatternInline(ImageVertexes* const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const; - - void inline calcTileVertexesInline(ImageVertexes *const vert, - const Image *const image, - int x, int y) const; - - bool inline drawImageInline(const Image *const image, - int dstX, int dstY); - GLfloat *mFloatTexArray; GLint *mIntTexArray; GLint *mIntVertArray; diff --git a/src/render/openglgraphicsdef.hpp b/src/render/openglgraphicsdef.hpp index 5e8e3390c..4315d4115 100644 --- a/src/render/openglgraphicsdef.hpp +++ b/src/render/openglgraphicsdef.hpp @@ -20,131 +20,43 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - bool setVideoMode(const int w, const int h, - const int scalle, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame) override final; +public: + void setColor(const Color &color) override final + { + mColor = color; + mColor2 = color; + mColorAlpha = (color.a != 255); + } + void setColorAll(const Color &color, const Color &color2) + { + mColor = color; + mColor2 = color2; + mColorAlpha = (color.a != 255); + } - /** - * Draws a resclaled version of the image - */ - bool drawRescaledImage(const Image *const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) override final; + void drawRectangle(const Rect &rect, + const bool filled); - void inline drawPatternInline(const Image *const image, - const int x, const int y, - const int w, const int h); + static void dumpSettings(); - void drawPattern(const Image *const image, - const int x, const int y, - const int w, const int h) override final; + void prepareScreenshot() override final; - /** - * Draw a pattern based on a rescaled version of the given image... - */ - void drawRescaledPattern(const Image *const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) override final; + int getMemoryUsage() A_WARN_UNUSED; - void calcPattern(ImageVertexes* const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; + void updateTextureFormat(); - void calcPattern(ImageCollection* const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; + bool isAllowScale() const override final + { return true; } - void calcTileVertexes(ImageVertexes *const vert, - const Image *const image, - int x, int y) const override final; + static void bindTexture(const GLenum target, const GLuint texture); - void calcTileCollection(ImageCollection *const vertCol, - const Image *const image, - int x, int y) override final; + static GLuint mLastImage; - void drawTileCollection(const ImageCollection *const vertCol) - override final; +protected: + void setTexturingAndBlending(const bool enable); - void drawTileVertexes(const ImageVertexes *const vert) override final; +private: + void inline setColorAlpha(const float alpha); - void calcWindow(ImageCollection *const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &imgRect) override final; - - void updateScreen() override final; - - void _beginDraw() override final; - - void _endDraw() override final; - - bool pushClipArea(Rect area) override final; - - void popClipArea() override final; - - void setColor(const Color &color) override final - { - mColor = color; - mColor2 = color; - mColorAlpha = (color.a != 255); - } - - void setColorAll(const Color &color, const Color &color2) - { - mColor = color; - mColor2 = color2; - mColorAlpha = (color.a != 255); - } - - void drawPoint(int x, int y) override final; - - void drawLine(int x1, int y1, int x2, int y2) override final; - - void drawRectangle(const Rect &rect, - const bool filled); - - void drawRectangle(const Rect &rect) override final; - - void fillRectangle(const Rect &rect) override final; - - static void dumpSettings(); - - /** - * Takes a screenshot and returns it as SDL surface. - */ - SDL_Surface *getScreenshot() override final A_WARN_UNUSED; - - void prepareScreenshot() override final; - - int getMemoryUsage() A_WARN_UNUSED; - - void updateTextureFormat(); - - bool drawImage(const Image *const image, - int dstX, int dstY) override final; - - void drawImageCached(const Image *const image, - int x, int y) override final; - - void drawPatternCached(const Image *const image, - const int x, const int y, - const int w, const int h) override final; - - void completeCache() override final; - - bool isAllowScale() const override final - { return true; } - - static void bindTexture(const GLenum target, const GLuint texture); - - static GLuint mLastImage; + void inline restoreColor(); diff --git a/src/render/openglgraphicsdefadvanced.hpp b/src/render/openglgraphicsdefadvanced.hpp new file mode 100644 index 000000000..07c706af3 --- /dev/null +++ b/src/render/openglgraphicsdefadvanced.hpp @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +public: + inline void drawVertexes(const NormalOpenGLGraphicsVertexes &ogl); + + void initArrays() override final; + +#ifdef DEBUG_DRAW_CALLS + unsigned int getDrawCalls() const + { return mLastDrawCalls; } + + static unsigned int mDrawCalls; + + static unsigned int mLastDrawCalls; +#endif + +protected: + void debugBindTexture(const Image *const image); diff --git a/src/render/safeopenglgraphics.h b/src/render/safeopenglgraphics.h index fbb156c6c..80a10a5eb 100644 --- a/src/render/safeopenglgraphics.h +++ b/src/render/safeopenglgraphics.h @@ -50,44 +50,11 @@ class SafeOpenGLGraphics final : public Graphics ~SafeOpenGLGraphics(); - #include "render/openglgraphicsdef.hpp" - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, int w, int h, - const ImageRect &imgRect); - - bool drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) override final; + #include "render/graphicsdef.hpp" - protected: - void setTexturingAndBlending(const bool enable); + #include "render/openglgraphicsdef.hpp" private: - void inline setColorAlpha(const float alpha); - - void inline restoreColor(); - - void inline calcImageRect(ImageVertexes *const vert, - int x, int y, - int w, int h, - const ImageRect &imgRect); - - void calcPatternInline(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const; - - void inline calcTileVertexesInline(ImageVertexes *const vert, - const Image *const image, - int x, int y) const; - - bool inline drawImageInline(const Image *const image, - int dstX, int dstY); - bool mTexture; bool mIsByteColor; Color mByteColor; diff --git a/src/render/sdl2graphics.h b/src/render/sdl2graphics.h index 9f604d9b5..9d341aca8 100644 --- a/src/render/sdl2graphics.h +++ b/src/render/sdl2graphics.h @@ -97,132 +97,17 @@ class SDLGraphics final : public Graphics */ ~SDLGraphics(); - void _beginDraw() override final; - - void _endDraw() override final; - - bool pushClipArea(Rect rect) override final; - - void popClipArea() override final; - - bool drawRescaledImage(const Image *const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) override final; - - void drawPattern(const Image *const image, - const int x, const int y, - const int w, const int h) override final; - - void inline drawPatternInline(const Image *const image, - const int x, const int y, - const int w, const int h); - - void drawRescaledPattern(const Image *const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) override final; - - void calcPattern(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; - - void calcPattern(ImageCollection *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; - - void calcTileVertexes(ImageVertexes *const vert, - const Image *const image, - int x, int y) const override final; - - void calcTileSDL(ImageVertexes *const vert, - int x, int y) const override final; - - void calcTileCollection(ImageCollection *const vertCol, - const Image *const image, - int x, int y) override final; - - void drawTileVertexes(const ImageVertexes *const vert) override final; - - void drawTileCollection(const ImageCollection *const vertCol) - override final; - - void updateScreen() override final; - - SDL_Surface *getScreenshot() override final A_WARN_UNUSED; - - bool drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) override final; - - void calcWindow(ImageCollection *const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &imgRect) override final; - - void fillRectangle(const Rect &rect) override final; - - void drawRectangle(const Rect &rect) override final; - - void drawPoint(int x, int y) override final; - - void drawLine(int x1, int y1, int x2, int y2) override final; - - bool setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame) override final; - void setRendererFlags(const uint32_t flags) { mRendererFlags = flags; } - bool drawImage(const Image *const image, - int dstX, int dstY) override final; - - void drawImageCached(const Image *const image, - int x, int y) override final; + #include "render/graphicsdef.hpp" - void drawPatternCached(const Image *const image, - const int x, const int y, - const int w, const int h) override final; - - void completeCache() override final; - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, int w, int h, - const ImageRect &imgRect); + #include "render/softwaregraphicsdef.hpp" protected: uint32_t mRendererFlags; uint32_t mOldPixel; unsigned int mOldAlpha; - - private: - void inline calcImageRect(ImageVertexes *const vert, - int x, int y, - int w, int h, - const ImageRect &imgRect); - - void inline calcPatternInline(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const; - - void inline calcTileVertexesInline(ImageVertexes *const vert, - const Image *const image, - int x, int y) const; - - bool inline drawImageInline(const Image *const image, - int dstX, int dstY); }; #endif // USE_SDL2 diff --git a/src/render/sdl2softwaregraphics.h b/src/render/sdl2softwaregraphics.h index 6ef750dbd..caf8517be 100644 --- a/src/render/sdl2softwaregraphics.h +++ b/src/render/sdl2softwaregraphics.h @@ -54,111 +54,14 @@ class SDL2SoftwareGraphics final : public Graphics */ ~SDL2SoftwareGraphics(); - void _beginDraw(); - - void _endDraw(); - - bool pushClipArea(Rect rect); - - void popClipArea(); - - bool drawRescaledImage(const Image *const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) override final; - - void drawPattern(const Image *const image, - const int x, const int y, - const int w, const int h) override final; - - void inline drawPatternInline(const Image *const image, - const int x, const int y, - const int w, const int h); - - void drawRescaledPattern(const Image *const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) override final; - - void calcPattern(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; - - void calcPattern(ImageCollection *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; - - void calcTileVertexes(ImageVertexes *const vert, - const Image *const image, - int x, int y) const override final; - - void calcTileSDL(ImageVertexes *const vert, - int x, int y) const override final; - - void calcTileCollection(ImageCollection *const vertCol, - const Image *const image, - int x, int y) override final; - - void drawTileVertexes(const ImageVertexes *const vert) override final; - - void drawTileCollection(const ImageCollection *const vertCol) - override final; - - void updateScreen() override final; - - SDL_Surface *getScreenshot() override final A_WARN_UNUSED; - - bool drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) override final; - - void calcWindow(ImageCollection *const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &imgRect) override final; - - void fillRectangle(const Rect &rect) override final; - - void drawRectangle(const Rect &rect) override final; - - void drawPoint(int x, int y) override final; - - void drawLine(int x1, int y1, int x2, int y2) override final; - - bool setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame) override final; - void setRendererFlags(const uint32_t flags) override final { mRendererFlags = flags; } - bool resizeScreen(const int width, const int height) override final; - - bool drawImage(const Image *const image, - int dstX, int dstY) override final; - - void drawImageCached(const Image *const image, - int x, int y) override final; + #include "render/graphicsdef.hpp" - void drawPatternCached(const Image *const image, - const int x, const int y, - const int w, const int h) override final; + #include "render/softwaregraphicsdef.hpp" - void completeCache() override final; - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, int w, int h, - const ImageRect &imgRect); + bool resizeScreen(const int width, const int height) override final; protected: int SDL_FakeUpperBlit(const SDL_Surface *const src, @@ -174,24 +77,6 @@ class SDL2SoftwareGraphics final : public Graphics SDL_Surface *mSurface; uint32_t mOldPixel; unsigned int mOldAlpha; - - private: - void inline calcImageRect(ImageVertexes *const vert, - const int x, const int y, - const int w, const int h, - const ImageRect &imgRect); - - void inline calcPatternInline(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const; - - void inline calcTileVertexesInline(ImageVertexes *const vert, - const Image *const image, - int x, int y) const; - - bool inline drawImageInline(const Image *const image, - int dstX, int dstY); }; #endif // USE_SDL2 diff --git a/src/render/sdlgraphics.h b/src/render/sdlgraphics.h index 170c0010b..9d023e199 100644 --- a/src/render/sdlgraphics.h +++ b/src/render/sdlgraphics.h @@ -54,106 +54,9 @@ class SDLGraphics final : public Graphics */ ~SDLGraphics(); - void _beginDraw() override final; + #include "render/graphicsdef.hpp" - void _endDraw() override final; - - bool pushClipArea(Rect rect) override final; - - void popClipArea() override final; - - bool drawRescaledImage(const Image *const image, - int dstX, int dstY, - const int desiredWidth, - const int desiredHeight) override final; - - void drawPattern(const Image *const image, - const int x, const int y, - const int w, const int h) override final; - - void inline drawPatternInline(const Image *const image, - const int x, const int y, - const int w, const int h); - - void drawRescaledPattern(const Image *const image, - const int x, const int y, - const int w, const int h, - const int scaledWidth, - const int scaledHeight) override final; - - void calcPattern(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; - - void calcPattern(ImageCollection *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const override final; - - void calcTileVertexes(ImageVertexes *const vert, - const Image *const image, - int x, int y) const override final; - - void calcTileSDL(ImageVertexes *const vert, - int x, int y) const override final; - - void calcTileCollection(ImageCollection *const vertCol, - const Image *const image, - int x, int y) override final; - - void drawTileVertexes(const ImageVertexes *const vert) override final; - - void drawTileCollection(const ImageCollection *const vertCol) - override final; - - void updateScreen() override final; - - SDL_Surface *getScreenshot() override final A_WARN_UNUSED; - - bool drawNet(const int x1, const int y1, - const int x2, const int y2, - const int width, const int height) override final; - - void calcWindow(ImageCollection *const vertCol, - const int x, const int y, - const int w, const int h, - const ImageRect &imgRect) override final; - - void fillRectangle(const Rect &rect) override final; - - void drawRectangle(const Rect &rect) override final; - - void drawPoint(int x, int y) override final; - - void drawLine(int x1, int y1, int x2, int y2) override final; - - bool setVideoMode(const int w, const int h, - const int scale, - const int bpp, - const bool fs, - const bool hwaccel, - const bool resize, - const bool noFrame) override final; - - bool drawImage(const Image *const image, - int dstX, int dstY) override final; - - void drawImageCached(const Image *const image, - int x, int y) override final; - - void drawPatternCached(const Image *const image, - const int x, const int y, - const int w, const int h) override final; - - void completeCache() override final; - - /** - * Draws a rectangle using images. 4 corner images, 4 side images and 1 - * image for the inside. - */ - void drawImageRect(int x, int y, int w, int h, - const ImageRect &imgRect); + #include "render/softwaregraphicsdef.hpp" protected: int SDL_FakeUpperBlit(const SDL_Surface *const src, @@ -167,23 +70,6 @@ class SDLGraphics final : public Graphics uint32_t mOldPixel; unsigned int mOldAlpha; - - private: - void inline calcImageRect(ImageVertexes *const vert, - int x, int y, - int w, int h, - const ImageRect &imgRect); - - void inline calcPatternInline(ImageVertexes *const vert, - const Image *const image, - const int x, const int y, - const int w, const int h) const; - - void inline calcTileVertexesInline(ImageVertexes *const vert, - const Image *const image, - int x, int y) const; - bool inline drawImageInline(const Image *const image, - int dstX, int dstY); }; #endif // USE_SDL2 diff --git a/src/render/softwaregraphicsdef.hpp b/src/render/softwaregraphicsdef.hpp new file mode 100644 index 000000000..db0014635 --- /dev/null +++ b/src/render/softwaregraphicsdef.hpp @@ -0,0 +1,25 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +public: + void calcTileSDL(ImageVertexes *const vert, + int x, int y) const override final; diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp index ff7c196c4..d72550767 100644 --- a/src/resources/imagehelper.cpp +++ b/src/resources/imagehelper.cpp @@ -25,6 +25,8 @@ #include "logger.h" #include "main.h" +#include "resources/dye.h" + #include "utils/sdlcheckutils.h" #include <SDL_image.h> @@ -52,6 +54,68 @@ Image *ImageHelper::load(SDL_RWops *const rw) const return image; } +Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye) const +{ + SDL_Surface *const tmpImage = loadPng(rw); + if (!tmpImage) + { + logger->log("Error, image load failed: %s", IMG_GetError()); + return nullptr; + } + + SDL_PixelFormat rgba; + rgba.palette = nullptr; + rgba.BitsPerPixel = 32; + rgba.BytesPerPixel = 4; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rgba.Rmask = 0x000000FF; + rgba.Gmask = 0x0000FF00; + rgba.Bmask = 0x00FF0000; + rgba.Amask = 0xFF000000; +#else + rgba.Rmask = 0xFF000000; + rgba.Gmask = 0x00FF0000; + rgba.Bmask = 0x0000FF00; + rgba.Amask = 0x000000FF; +#endif + + SDL_Surface *const surf = MSDL_ConvertSurface( + tmpImage, &rgba, SDL_SWSURFACE); + MSDL_FreeSurface(tmpImage); + + uint32_t *const pixels = static_cast<uint32_t *const>(surf->pixels); + const int type = dye.getType(); + + switch (type) + { + case 1: + { + const DyePalette *const pal = dye.getSPalete(); + if (pal) + pal->replaceSColor(pixels, surf->w * surf->h); + break; + } + case 2: + { + const DyePalette *const pal = dye.getAPalete(); + if (pal) + pal->replaceAColor(pixels, surf->w * surf->h); + break; + } + case 0: + default: + { + dye.normalDye(pixels, surf->w * surf->h); + break; + } + } + + Image *const image = load(surf); + MSDL_FreeSurface(surf); + return image; +} + SDL_Surface* ImageHelper::convertTo32Bit(SDL_Surface *const tmpImage) { if (!tmpImage) @@ -138,3 +202,22 @@ SDL_Surface *ImageHelper::loadPng(SDL_RWops *const rw) SDL_RWclose(rw); return nullptr; } + +SDL_Surface *ImageHelper::create32BitSurface(int width, + int height) const +{ +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + const int rmask = 0xff000000; + const int gmask = 0x00ff0000; + const int bmask = 0x0000ff00; + const int amask = 0x000000ff; +#else + const int rmask = 0x000000ff; + const int gmask = 0x0000ff00; + const int bmask = 0x00ff0000; + const int amask = 0xff000000; +#endif + + return MSDL_CreateRGBSurface(SDL_SWSURFACE, + width, height, 32, rmask, gmask, bmask, amask); +} diff --git a/src/resources/imagehelper.h b/src/resources/imagehelper.h index 2e3b96771..f68d8c147 100644 --- a/src/resources/imagehelper.h +++ b/src/resources/imagehelper.h @@ -58,19 +58,16 @@ class ImageHelper */ Image *load(SDL_RWops *const rw) const A_WARN_UNUSED; -#ifdef __GNUC__ virtual Image *load(SDL_RWops *const rw, Dye - const &dye) const A_WARN_UNUSED = 0; + const &dye) const A_WARN_UNUSED; +#ifdef __GNUC__ virtual Image *load(SDL_Surface *const) const A_WARN_UNUSED = 0; virtual Image *createTextSurface(SDL_Surface *const tmpImage, const int width, const int height, float alpha) const A_WARN_UNUSED = 0; #else - virtual Image *load(SDL_RWops *rw, Dye const &dye) const A_WARN_UNUSED - { return nullptr; } - virtual Image *load(SDL_Surface *) const A_WARN_UNUSED { return nullptr; } @@ -84,8 +81,9 @@ class ImageHelper static void dumpSurfaceFormat(const SDL_Surface *const image); - virtual SDL_Surface *create32BitSurface(int width, int height) - const A_WARN_UNUSED = 0; + virtual SDL_Surface *create32BitSurface(int width, + int height) + const A_WARN_UNUSED; static void setEnableAlpha(const bool n) { mEnableAlpha = n; } diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp index 5a0a91fc1..262d839f7 100644 --- a/src/resources/openglimagehelper.cpp +++ b/src/resources/openglimagehelper.cpp @@ -290,7 +290,8 @@ void OpenGLImageHelper::initTextureSampler(const GLint id) } } -SDL_Surface *OpenGLImageHelper::create32BitSurface(int width, int height) const +SDL_Surface *OpenGLImageHelper::create32BitSurface(int width, + int height) const { #if SDL_BYTEORDER == SDL_BIG_ENDIAN const int rmask = 0xff000000; diff --git a/src/resources/sdl2imagehelper.cpp b/src/resources/sdl2imagehelper.cpp index 80110735f..b31622e51 100644 --- a/src/resources/sdl2imagehelper.cpp +++ b/src/resources/sdl2imagehelper.cpp @@ -43,68 +43,6 @@ bool SDLImageHelper::mEnableAlphaCache = false; SDL_Renderer *SDLImageHelper::mRenderer = nullptr; #endif -Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const -{ - SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) - { - logger->log("Error, image load failed: %s", IMG_GetError()); - return nullptr; - } - - SDL_PixelFormat rgba; - rgba.palette = nullptr; - rgba.BitsPerPixel = 32; - rgba.BytesPerPixel = 4; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rgba.Rmask = 0x000000FF; - rgba.Gmask = 0x0000FF00; - rgba.Bmask = 0x00FF0000; - rgba.Amask = 0xFF000000; -#else - rgba.Rmask = 0xFF000000; - rgba.Gmask = 0x00FF0000; - rgba.Bmask = 0x0000FF00; - rgba.Amask = 0x000000FF; -#endif - - SDL_Surface *const surf = MSDL_ConvertSurface( - tmpImage, &rgba, SDL_SWSURFACE); - MSDL_FreeSurface(tmpImage); - - uint32_t *pixels = static_cast<uint32_t *>(surf->pixels); - const int type = dye.getType(); - - switch (type) - { - case 1: - { - const DyePalette *const pal = dye.getSPalete(); - if (pal) - pal->replaceSColor(pixels, surf->w * surf->h); - break; - } - case 2: - { - const DyePalette *const pal = dye.getAPalete(); - if (pal) - pal->replaceAColor(pixels, surf->w * surf->h); - break; - } - case 0: - default: - { - dye.normalDye(pixels, surf->w * surf->h); - break; - } - } - - Image *const image = load(surf); - MSDL_FreeSurface(surf); - return image; -} - Image *SDLImageHelper::load(SDL_Surface *const tmpImage) const { return _SDLload(tmpImage); @@ -145,24 +83,6 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const return new Image(texture, tmpImage->w, tmpImage->h); } -SDL_Surface *SDLImageHelper::create32BitSurface(int width, int height) const -{ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int rmask = 0xff000000; - const int gmask = 0x00ff0000; - const int bmask = 0x0000ff00; - const int amask = 0x000000ff; -#else - const int rmask = 0x000000ff; - const int gmask = 0x0000ff00; - const int bmask = 0x00ff0000; - const int amask = 0xff000000; -#endif - - return MSDL_CreateRGBSurface(SDL_SWSURFACE, - width, height, 32, rmask, gmask, bmask, amask); -} - int SDLImageHelper::combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, diff --git a/src/resources/sdl2imagehelper.h b/src/resources/sdl2imagehelper.h index 70ea9c12f..296b50f8a 100644 --- a/src/resources/sdl2imagehelper.h +++ b/src/resources/sdl2imagehelper.h @@ -52,18 +52,6 @@ class SDLImageHelper final : public ImageHelper { } /** - * Loads an image from an SDL_RWops structure and recolors it. - * - * @param rw The SDL_RWops to load the image from. - * @param dye The dye used to recolor the image. - * - * @return <code>NULL</code> if an error occurred, a valid pointer - * otherwise. - */ - Image *load(SDL_RWops *const rw, - Dye const &dye) const override final A_WARN_UNUSED; - - /** * Loads an image from an SDL surface. */ Image *load(SDL_Surface *const tmpImage) const @@ -83,9 +71,6 @@ class SDLImageHelper final : public ImageHelper static SDL_Surface* SDLDuplicateSurface(SDL_Surface *const tmpImage) A_WARN_UNUSED; - SDL_Surface *create32BitSurface(int width, int height) const - override final; - static int combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, diff --git a/src/resources/sdl2softwareimagehelper.cpp b/src/resources/sdl2softwareimagehelper.cpp index 3e8802f41..fa0a51606 100644 --- a/src/resources/sdl2softwareimagehelper.cpp +++ b/src/resources/sdl2softwareimagehelper.cpp @@ -41,68 +41,6 @@ bool SDL2SoftwareImageHelper::mEnableAlphaCache = false; SDL_PixelFormat *SDL2SoftwareImageHelper::mFormat = nullptr; -Image *SDL2SoftwareImageHelper::load(SDL_RWops *const rw, Dye const &dye) const -{ - SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) - { - logger->log("Error, image load failed: %s", IMG_GetError()); - return nullptr; - } - - SDL_PixelFormat rgba; - rgba.palette = nullptr; - rgba.BitsPerPixel = 32; - rgba.BytesPerPixel = 4; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rgba.Rmask = 0x000000FF; - rgba.Gmask = 0x0000FF00; - rgba.Bmask = 0x00FF0000; - rgba.Amask = 0xFF000000; -#else - rgba.Rmask = 0xFF000000; - rgba.Gmask = 0x00FF0000; - rgba.Bmask = 0x0000FF00; - rgba.Amask = 0x000000FF; -#endif - - SDL_Surface *const surf = MSDL_ConvertSurface( - tmpImage, &rgba, SDL_SWSURFACE); - MSDL_FreeSurface(tmpImage); - - uint32_t *pixels = static_cast<uint32_t *>(surf->pixels); - const int type = dye.getType(); - - switch (type) - { - case 1: - { - const DyePalette *const pal = dye.getSPalete(); - if (pal) - pal->replaceSColor(pixels, surf->w * surf->h); - break; - } - case 2: - { - const DyePalette *const pal = dye.getAPalete(); - if (pal) - pal->replaceAColor(pixels, surf->w * surf->h); - break; - } - case 0: - default: - { - dye.normalDye(pixels, surf->w * surf->h); - break; - } - } - - Image *const image = load(surf); - MSDL_FreeSurface(surf); - return image; -} - Image *SDL2SoftwareImageHelper::load(SDL_Surface *const tmpImage) const { return _SDLload(tmpImage); @@ -140,25 +78,6 @@ Image *SDL2SoftwareImageHelper::_SDLload(SDL_Surface *tmpImage) const return new Image(image, false, nullptr); } -SDL_Surface *SDL2SoftwareImageHelper::create32BitSurface(int width, - int height) const -{ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int rmask = 0xff000000; - const int gmask = 0x00ff0000; - const int bmask = 0x0000ff00; - const int amask = 0x000000ff; -#else - const int rmask = 0x000000ff; - const int gmask = 0x0000ff00; - const int bmask = 0x00ff0000; - const int amask = 0xff000000; -#endif - - return MSDL_CreateRGBSurface(SDL_SWSURFACE, - width, height, 32, rmask, gmask, bmask, amask); -} - int SDL2SoftwareImageHelper::combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, diff --git a/src/resources/sdl2softwareimagehelper.h b/src/resources/sdl2softwareimagehelper.h index 210b0f8b1..41af65fdb 100644 --- a/src/resources/sdl2softwareimagehelper.h +++ b/src/resources/sdl2softwareimagehelper.h @@ -52,18 +52,6 @@ class SDL2SoftwareImageHelper final : public ImageHelper { } /** - * Loads an image from an SDL_RWops structure and recolors it. - * - * @param rw The SDL_RWops to load the image from. - * @param dye The dye used to recolor the image. - * - * @return <code>NULL</code> if an error occurred, a valid pointer - * otherwise. - */ - Image *load(SDL_RWops *const rw, - Dye const &dye) const override final A_WARN_UNUSED; - - /** * Loads an image from an SDL surface. */ Image *load(SDL_Surface *const tmpImage) const @@ -83,9 +71,6 @@ class SDL2SoftwareImageHelper final : public ImageHelper static SDL_Surface* SDLDuplicateSurface(SDL_Surface *const tmpImage) A_WARN_UNUSED; - SDL_Surface *create32BitSurface(int width, - int height) const override final; - static int combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp index cced7ad8a..7b9aeda5e 100644 --- a/src/resources/sdlimagehelper.cpp +++ b/src/resources/sdlimagehelper.cpp @@ -276,24 +276,6 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const return new Image(image, hasAlpha, alphaChannel); } -SDL_Surface *SDLImageHelper::create32BitSurface(int width, int height) const -{ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int rmask = 0xff000000; - const int gmask = 0x00ff0000; - const int bmask = 0x0000ff00; - const int amask = 0x000000ff; -#else - const int rmask = 0x000000ff; - const int gmask = 0x0000ff00; - const int bmask = 0x00ff0000; - const int amask = 0xff000000; -#endif - - return MSDL_CreateRGBSurface(SDL_SWSURFACE, - width, height, 32, rmask, gmask, bmask, amask); -} - int SDLImageHelper::combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, diff --git a/src/resources/sdlimagehelper.h b/src/resources/sdlimagehelper.h index 725b34ebc..42433ec55 100644 --- a/src/resources/sdlimagehelper.h +++ b/src/resources/sdlimagehelper.h @@ -84,9 +84,6 @@ class SDLImageHelper final : public ImageHelper static SDL_Surface* SDLDuplicateSurface(SDL_Surface *const tmpImage) A_WARN_UNUSED; - SDL_Surface *create32BitSurface(int width, - int height) const override final; - static int combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, diff --git a/src/resources/surfaceimagehelper.cpp b/src/resources/surfaceimagehelper.cpp index 740c1c41d..ec7d9af9b 100644 --- a/src/resources/surfaceimagehelper.cpp +++ b/src/resources/surfaceimagehelper.cpp @@ -40,68 +40,6 @@ bool SurfaceImageHelper::mEnableAlphaCache = false; -Image *SurfaceImageHelper::load(SDL_RWops *const rw, Dye const &dye) const -{ - SDL_Surface *const tmpImage = loadPng(rw); - if (!tmpImage) - { - logger->log("Error, image load failed: %s", IMG_GetError()); - return nullptr; - } - - SDL_PixelFormat rgba; - rgba.palette = nullptr; - rgba.BitsPerPixel = 32; - rgba.BytesPerPixel = 4; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rgba.Rmask = 0x000000FF; - rgba.Gmask = 0x0000FF00; - rgba.Bmask = 0x00FF0000; - rgba.Amask = 0xFF000000; -#else - rgba.Rmask = 0xFF000000; - rgba.Gmask = 0x00FF0000; - rgba.Bmask = 0x0000FF00; - rgba.Amask = 0x000000FF; -#endif - - SDL_Surface *const surf = MSDL_ConvertSurface( - tmpImage, &rgba, SDL_SWSURFACE); - MSDL_FreeSurface(tmpImage); - - uint32_t *pixels = static_cast<uint32_t *>(surf->pixels); - const int type = dye.getType(); - - switch (type) - { - case 1: - { - const DyePalette *const pal = dye.getSPalete(); - if (pal) - pal->replaceSColor(pixels, surf->w * surf->h); - break; - } - case 2: - { - const DyePalette *const pal = dye.getAPalete(); - if (pal) - pal->replaceAColor(pixels, surf->w * surf->h); - break; - } - case 0: - default: - { - dye.normalDye(pixels, surf->w * surf->h); - break; - } - } - - Image *const image = load(surf); - MSDL_FreeSurface(surf); - return image; -} - Image *SurfaceImageHelper::load(SDL_Surface *const tmpImage) const { return _SDLload(tmpImage); @@ -148,25 +86,6 @@ RenderType SurfaceImageHelper::useOpenGL() const return RENDER_SOFTWARE; } -SDL_Surface *SurfaceImageHelper::create32BitSurface(int width, - int height) const -{ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int rmask = 0xff000000; - const int gmask = 0x00ff0000; - const int bmask = 0x0000ff00; - const int amask = 0x000000ff; -#else - const int rmask = 0x000000ff; - const int gmask = 0x0000ff00; - const int bmask = 0x00ff0000; - const int amask = 0xff000000; -#endif - - return MSDL_CreateRGBSurface(SDL_SWSURFACE, - width, height, 32, rmask, gmask, bmask, amask); -} - int SurfaceImageHelper::combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, diff --git a/src/resources/surfaceimagehelper.h b/src/resources/surfaceimagehelper.h index fb3649f06..3e595009e 100644 --- a/src/resources/surfaceimagehelper.h +++ b/src/resources/surfaceimagehelper.h @@ -54,18 +54,6 @@ class SurfaceImageHelper final : public ImageHelper { } /** - * Loads an image from an SDL_RWops structure and recolors it. - * - * @param rw The SDL_RWops to load the image from. - * @param dye The dye used to recolor the image. - * - * @return <code>NULL</code> if an error occurred, a valid pointer - * otherwise. - */ - Image *load(SDL_RWops *const rw, - Dye const &dye) const override final A_WARN_UNUSED; - - /** * Loads an image from an SDL surface. */ Image *load(SDL_Surface *const tmpImage) const @@ -91,9 +79,6 @@ class SurfaceImageHelper final : public ImageHelper static SDL_Surface* SDLDuplicateSurface(SDL_Surface *const tmpImage) A_WARN_UNUSED; - SDL_Surface *create32BitSurface(int width, - int height) const override final; - static int combineSurface(SDL_Surface *restrict const src, SDL_Rect *restrict const srcrect, SDL_Surface *restrict const dst, |