diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 2a06d37452..e0ded7bb21 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -594,9 +594,11 @@ bool GameController::MouseDown(int x, int y, unsigned button) return ret; } -bool GameController::MouseUp(int x, int y, unsigned button) +bool GameController::MouseUp(int x, int y, unsigned button, char type) { - bool ret = commandInterface->OnMouseUp(x, y, button); + bool ret = commandInterface->OnMouseUp(x, y, button, type); + if (type) + return ret; if (ret && foundSign && yGetPlacingSave()) { ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y)); diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 64744d9b7a..87d20d8532 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -61,7 +61,7 @@ class GameController: public ClientListener bool MouseMove(int x, int y, int dx, int dy); bool MouseDown(int x, int y, unsigned button); - bool MouseUp(int x, int y, unsigned button); + bool MouseUp(int x, int y, unsigned button, char type); bool MouseWheel(int x, int y, int d); bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index c9ea797a73..8d73984d9f 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -480,7 +480,7 @@ class GameView::MenuAction: public ui::ButtonAction } void MouseEnterCallback(ui::Button * sender) { - if(!needsClick && !ui::Engine::Ref().GetMouseButton()) + if(!needsClick && !v->GetMouseDown()) v->c->SetActiveMenu(menuID); } void ActionCallback(ui::Button * sender) @@ -1075,7 +1075,10 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy) } } else if (drawMode == DrawPoints || drawMode == DrawFill) + { isMouseDown = false; + c->MouseUp(x, y, 0, 2); + } } mouseInZoom = newMouseInZoom; } @@ -1614,6 +1617,7 @@ void GameView::OnBlur() disableShiftBehaviour(); isMouseDown = false; drawMode = DrawPoints; + c->MouseUp(0, 0, 0, 1); // tell lua that mouse is up (even if it really isn't) } void GameView::OnTick(float dt) @@ -1773,7 +1777,7 @@ void GameView::DoMouseDown(int x, int y, unsigned button) void GameView::DoMouseUp(int x, int y, unsigned button) { - if(c->MouseUp(x, y, button)) + if(c->MouseUp(x, y, button, 0)) Window::DoMouseUp(x, y, button); } diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 0ca9afba82..60c799b843 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -147,6 +147,7 @@ class GameView: public ui::Window void BeginStampSelection(); //all of these are only here for one debug lines + bool GetMouseDown() { return isMouseDown; } bool GetDrawingLine() { return drawMode == DrawLine && isMouseDown; } bool GetDrawSnap() { return drawSnap; } ui::Point GetLineStartCoords() { return drawPoint1; } diff --git a/src/lua/CommandInterface.h b/src/lua/CommandInterface.h index ffcfedd727..cd3b4596fe 100644 --- a/src/lua/CommandInterface.h +++ b/src/lua/CommandInterface.h @@ -24,7 +24,7 @@ class CommandInterface { virtual bool OnActiveToolChanged(int toolSelection, Tool * tool) {return true;} virtual bool OnMouseMove(int x, int y, int dx, int dy) {return true;} virtual bool OnMouseDown(int x, int y, unsigned button) {return true;} - virtual bool OnMouseUp(int x, int y, unsigned button) {return true;} + virtual bool OnMouseUp(int x, int y, unsigned button, char type) {return true;} virtual bool OnMouseWheel(int x, int y, int d) {return true;} virtual bool OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {return true;} virtual bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {return true;} diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index d0f7ef2cbb..cafd2efd22 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3220,13 +3220,29 @@ bool LuaScriptInterface::OnMouseDown(int x, int y, unsigned button) return luacon_mouseevent(x, y, button, LUACON_MDOWN, 0); } -bool LuaScriptInterface::OnMouseUp(int x, int y, unsigned button) +bool LuaScriptInterface::OnMouseUp(int x, int y, unsigned button, char type) { + luacon_mousebutton = 0; if (button == 3) button = 4; + + // mouse was never down, probably due to fake mouse event + if (!luacon_mousedown) + { + return true; + } + + // fake mouseup event, triggered when mouse drawing is canceled due to moving in / out of the zoom window + if (type == 2) + return luacon_mouseevent(x, y, button, LUACON_MUPZOOM, 0); + luacon_mousedown = false; - luacon_mousebutton = 0; - return luacon_mouseevent(x, y, button, LUACON_MUP, 0); + + // fake mouseup event, triggered when user enters another interface while the mouse is down + if (type == 1) + return luacon_mouseevent(x, y, button, LUACON_MUPALT, 0); + else + return luacon_mouseevent(x, y, button, LUACON_MUP, 0); } bool LuaScriptInterface::OnMouseWheel(int x, int y, int d) diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index 091d8f9341..6f970c41d9 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -18,6 +18,8 @@ class Tool; #define LUACON_MDOWN 1 #define LUACON_MUP 2 #define LUACON_MPRESS 3 +#define LUACON_MUPALT 4 +#define LUACON_MUPZOOM 5 #define LUACON_KDOWN 1 #define LUACON_KUP 2 @@ -171,7 +173,7 @@ class LuaScriptInterface: public CommandInterface virtual bool OnActiveToolChanged(int toolSelection, Tool * tool); virtual bool OnMouseMove(int x, int y, int dx, int dy); virtual bool OnMouseDown(int x, int y, unsigned button); - virtual bool OnMouseUp(int x, int y, unsigned button); + virtual bool OnMouseUp(int x, int y, unsigned button, char type); virtual bool OnMouseWheel(int x, int y, int d); virtual bool OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); virtual bool OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);