Skip to content

Commit

Permalink
Add blur lua event, called when opening another interface window
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Dec 28, 2018
1 parent 9e94abb commit 3b3775a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/gui/game/GameController.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Expand Up @@ -68,6 +68,7 @@ class GameController: public ClientListener
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();
Expand Down
4 changes: 1 addition & 3 deletions src/gui/game/GameView.cpp
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/lua/LuaEvents.h
Expand Up @@ -98,6 +98,12 @@ class TickEvent: public Event
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:
Expand All @@ -116,6 +122,7 @@ class LuaEvents
mousemove,
mousewheel,
tick,
blur,
close
};

Expand Down
1 change: 1 addition & 0 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -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");
}

Expand Down

0 comments on commit 3b3775a

Please sign in to comment.