diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-07-12 14:27:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-07-12 14:27:09 +0300 |
commit | 36027fc87b99b8f048265f6ac470227a1c32d481 (patch) | |
tree | 617b39aaf314fa9660b02fd849d994fde19f7959 /src/gui | |
parent | d0c97c8a12b0904c00a492acd129aebffd7816c8 (diff) | |
download | plus-36027fc87b99b8f048265f6ac470227a1c32d481.tar.gz plus-36027fc87b99b8f048265f6ac470227a1c32d481.tar.bz2 plus-36027fc87b99b8f048265f6ac470227a1c32d481.tar.xz plus-36027fc87b99b8f048265f6ac470227a1c32d481.zip |
add option for enable/disable double click support.
New option: setup / misc / other / Enable double clicks
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 58 | ||||
-rw-r--r-- | src/gui/gui.h | 6 | ||||
-rw-r--r-- | src/gui/setup_other.cpp | 4 |
3 files changed, 61 insertions, 7 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 1032e7e4e..2a838069b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -68,11 +68,12 @@ class GuiConfigListener final : public ConfigListener void optionChanged(const std::string &name) { - if (name == "customcursor" && mGui) - { - const bool bCustomCursor = config.getBoolValue("customcursor"); - mGui->setUseCustomCursor(bCustomCursor); - } + if (!mGui) + return; + if (name == "customcursor") + mGui->setUseCustomCursor(config.getBoolValue("customcursor")); + else if (name == "doubleClick") + mGui->setDoubleClick(config.getBoolValue("doubleClick")); } private: Gui *mGui; @@ -97,7 +98,8 @@ Gui::Gui(Graphics *const graphics) : mFocusListeners(), mForegroundColor(Theme::getThemeColor(Theme::TEXT)), mForegroundColor2(Theme::getThemeColor(Theme::TEXT_OUTLINE)), - mCustomCursor(false) + mCustomCursor(false), + mDoubleClick(true) { logger->log1("Initializing GUI..."); // Set graphics @@ -236,12 +238,14 @@ Gui::Gui(Graphics *const graphics) : // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getBoolValue("customcursor")); + setDoubleClick(config.getBoolValue("doubleClick")); config.addListener("customcursor", mConfigListener); + config.addListener("doubleClick", mConfigListener); } Gui::~Gui() { - config.removeListener("customcursor", mConfigListener); + config.removeListeners(mConfigListener); delete mConfigListener; mConfigListener = nullptr; @@ -522,6 +526,46 @@ void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput) mMouseInactivityTimer = 0; } +void Gui::handleMousePressed(const gcn::MouseInput &mouseInput) +{ + const int x = mouseInput.getX(); + const int y = mouseInput.getY(); + const unsigned int button = mouseInput.getButton(); + const int timeStamp = mouseInput.getTimeStamp(); + + gcn::Widget *sourceWidget = getMouseEventSource(x, y); + + if (mFocusHandler->getDraggedWidget()) + sourceWidget = mFocusHandler->getDraggedWidget(); + + int sourceWidgetX, sourceWidgetY; + sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY); + + if ((mFocusHandler->getModalFocused() + && sourceWidget->isModalFocused()) + || !mFocusHandler->getModalFocused()) + { + sourceWidget->requestFocus(); + } + + if (mDoubleClick && timeStamp - mLastMousePressTimeStamp < 250 + && mLastMousePressButton == button) + { + mClickCount ++; + } + else + { + mClickCount = 1; + } + + distributeMouseEvent(sourceWidget, MouseEvent::PRESSED, button, x, y); + mFocusHandler->setLastWidgetPressed(sourceWidget); + mFocusHandler->setDraggedWidget(sourceWidget); + mLastMouseDragButton = button; + mLastMousePressButton = button; + mLastMousePressTimeStamp = timeStamp; +} + void Gui::updateFonts() { const int fontSize = config.getIntValue("fontSize"); diff --git a/src/gui/gui.h b/src/gui/gui.h index 129dedfce..0b4b4a292 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -134,6 +134,9 @@ class Gui final : public gcn::Gui void setCursorType(const int index) { mCursorType = index; } + void setDoubleClick(const bool b) + { mDoubleClick = b; } + void updateFonts(); bool handleInput(); @@ -159,6 +162,8 @@ class Gui final : public gcn::Gui void handleMouseReleased(const gcn::MouseInput &mouseInput); + void handleMousePressed(const gcn::MouseInput &mouseInput); + void handleMouseInput(); void distributeMouseEvent(gcn::Widget* source, int type, int button, @@ -186,6 +191,7 @@ class Gui final : public gcn::Gui gcn::Color mForegroundColor; gcn::Color mForegroundColor2; bool mCustomCursor; /**< Show custom cursor */ + bool mDoubleClick; }; extern Gui *gui; /**< The GUI system */ diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index f26378630..ae6f6f6bb 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -323,6 +323,10 @@ Setup_Other::Setup_Other(const Widget2 *const widget) : "serverAttack", this, "serverAttackEvent"); // TRANSLATORS: settings option + new SetupItemCheckBox(_("Enable double clicks"), "", + "doubleClick", this, "doubleClickEvent"); + + // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable bot checker"), "", "enableBotCheker", this, "enableBotChekerEvent"); |