Add close event

This commit is contained in:
Tamás Bálint Misius 2018-11-16 22:15:09 +01:00 committed by jacob1
parent 3de68c4346
commit e48bd482f6
6 changed files with 19 additions and 1 deletions

View File

@ -304,6 +304,7 @@ void EventProcess(SDL_Event event)
switch (event.type) switch (event.type)
{ {
case SDL_QUIT: case SDL_QUIT:
engine->onClose();
if (engine->GetFastQuit() || engine->CloseWindow()) if (engine->GetFastQuit() || engine->CloseWindow())
engine->Exit(); engine->Exit();
break; break;

View File

@ -865,6 +865,8 @@ void GameController::Tick()
void GameController::Exit() void GameController::Exit()
{ {
CloseEvent ev;
commandInterface->HandleEvent(LuaEvents::close, &ev);
gameView->CloseActiveWindow(); gameView->CloseActiveWindow();
HasDone = true; HasDone = true;
} }

View File

@ -1855,6 +1855,12 @@ void GameView::DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctr
Window::DoKeyRelease(key, scan, repeat, shift, ctrl, alt); Window::DoKeyRelease(key, scan, repeat, shift, ctrl, alt);
} }
void GameView::DoExit()
{
Window::DoExit();
c->Exit();
}
void GameView::DoDraw() void GameView::DoDraw()
{ {
Window::DoDraw(); Window::DoDraw();

View File

@ -198,6 +198,7 @@ public:
virtual void OnBlur(); virtual void OnBlur();
//Top-level handlers, for Lua interface //Top-level handlers, for Lua interface
virtual void DoExit();
virtual void DoDraw(); virtual void DoDraw();
virtual void DoMouseMove(int x, int y, int dx, int dy); virtual void DoMouseMove(int x, int y, int dx, int dy);
virtual void DoMouseDown(int x, int y, unsigned button); virtual void DoMouseDown(int x, int y, unsigned button);

View File

@ -98,6 +98,12 @@ public:
int PushToStack(lua_State *l) override { return 0; } int PushToStack(lua_State *l) override { return 0; }
}; };
class CloseEvent: public Event
{
public:
int PushToStack(lua_State *l) override { return 0; }
};
class LuaEvents class LuaEvents
{ {
public: public:
@ -109,7 +115,8 @@ public:
mouseup, mouseup,
mousemove, mousemove,
mousewheel, mousewheel,
tick tick,
close
}; };
static int RegisterEventHook(lua_State* l, ByteString eventName); static int RegisterEventHook(lua_State* l, ByteString eventName);

View File

@ -3311,6 +3311,7 @@ void LuaScriptInterface::initEventAPI()
lua_pushinteger(l, LuaEvents::mousemove); lua_setfield(l, -2, "mousemove"); lua_pushinteger(l, LuaEvents::mousemove); lua_setfield(l, -2, "mousemove");
lua_pushinteger(l, LuaEvents::mousewheel); lua_setfield(l, -2, "mousewheel"); lua_pushinteger(l, LuaEvents::mousewheel); lua_setfield(l, -2, "mousewheel");
lua_pushinteger(l, LuaEvents::tick); lua_setfield(l, -2, "tick"); lua_pushinteger(l, LuaEvents::tick); lua_setfield(l, -2, "tick");
lua_pushinteger(l, LuaEvents::close); lua_setfield(l, -2, "close");
} }
int LuaScriptInterface::event_register(lua_State * l) int LuaScriptInterface::event_register(lua_State * l)