Skip to content

Commit

Permalink
two new lua mouse up events (4 & 5) for some corner cases
Browse files Browse the repository at this point in the history
Also fixes mouse held event being stuck in one of those cases
  • Loading branch information
jacob1 committed Sep 21, 2015
1 parent cd97d63 commit 16781bc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/gui/game/GameController.cpp
Expand Up @@ -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 && y<YRES && x<XRES && !gameView->GetPlacingSave())
{
ui::Point point = gameModel->AdjustZoomCoords(ui::Point(x, y));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/GameController.h
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/gui/game/GameView.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameView.h
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/lua/CommandInterface.h
Expand Up @@ -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;}
Expand Down
22 changes: 19 additions & 3 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/lua/LuaScriptInterface.h
Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 16781bc

Please sign in to comment.