From 3b3775addfd3870d227a11ec289e898e5d7bbe6a Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 27 Dec 2018 21:17:24 -0500 Subject: [PATCH] Add blur lua event, called when opening another interface window --- src/gui/game/GameController.cpp | 8 ++++++++ src/gui/game/GameController.h | 1 + src/gui/game/GameView.cpp | 4 +--- src/lua/LuaEvents.h | 7 +++++++ src/lua/LuaScriptInterface.cpp | 1 + 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 5b946bb2c..b8aeb5dc4 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -863,6 +863,14 @@ void GameController::Tick() commandInterface->OnTick(); } +void GameController::Blur() +{ + // Tell lua that mouse is up (even if it really isn't) + MouseUp(0, 0, 0, 1); + BlurEvent ev; + commandInterface->HandleEvent(LuaEvents::blur, &ev); +} + void GameController::Exit() { CloseEvent ev; diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 2431d2495..dc020b6f3 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -68,6 +68,7 @@ public: bool KeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); bool KeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt); void Tick(); + void Blur(); void Exit(); void Install(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 7bc68ef47..6535ce061 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1700,9 +1700,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) - if (GetModifiers()) - c->KeyRelease(0, 0, false, false, false, false); + c->Blur(); } void GameView::OnTick(float dt) diff --git a/src/lua/LuaEvents.h b/src/lua/LuaEvents.h index 401e5ce7b..17b5e8cca 100644 --- a/src/lua/LuaEvents.h +++ b/src/lua/LuaEvents.h @@ -98,6 +98,12 @@ public: int PushToStack(lua_State *l) override { return 0; } }; +class BlurEvent: public Event +{ +public: + int PushToStack(lua_State *l) override { return 0; } +}; + class CloseEvent: public Event { public: @@ -116,6 +122,7 @@ public: mousemove, mousewheel, tick, + blur, close }; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 27853aad5..143617511 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -3314,6 +3314,7 @@ void LuaScriptInterface::initEventAPI() lua_pushinteger(l, LuaEvents::mousemove); lua_setfield(l, -2, "mousemove"); lua_pushinteger(l, LuaEvents::mousewheel); lua_setfield(l, -2, "mousewheel"); lua_pushinteger(l, LuaEvents::tick); lua_setfield(l, -2, "tick"); + lua_pushinteger(l, LuaEvents::blur); lua_setfield(l, -2, "blur"); lua_pushinteger(l, LuaEvents::close); lua_setfield(l, -2, "close"); }