summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp58
-rw-r--r--src/gui/gui.h6
-rw-r--r--src/gui/setup_other.cpp4
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");