Skip to content

Commit

Permalink
Add close event
Browse files Browse the repository at this point in the history
  • Loading branch information
LBPHacker authored and jacob1 committed Nov 17, 2018
1 parent 3de68c4 commit e48bd48
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/PowderToySDL.cpp
Expand Up @@ -304,6 +304,7 @@ void EventProcess(SDL_Event event)
switch (event.type)
{
case SDL_QUIT:
engine->onClose();
if (engine->GetFastQuit() || engine->CloseWindow())
engine->Exit();
break;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/game/GameController.cpp
Expand Up @@ -865,6 +865,8 @@ void GameController::Tick()

void GameController::Exit()
{
CloseEvent ev;
commandInterface->HandleEvent(LuaEvents::close, &ev);
gameView->CloseActiveWindow();
HasDone = true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/game/GameView.cpp
Expand Up @@ -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);
}

void GameView::DoExit()
{
Window::DoExit();
c->Exit();
}

void GameView::DoDraw()
{
Window::DoDraw();
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameView.h
Expand Up @@ -198,6 +198,7 @@ class GameView: public ui::Window
virtual void OnBlur();

//Top-level handlers, for Lua interface
virtual void DoExit();
virtual void DoDraw();
virtual void DoMouseMove(int x, int y, int dx, int dy);
virtual void DoMouseDown(int x, int y, unsigned button);
Expand Down
9 changes: 8 additions & 1 deletion src/lua/LuaEvents.h
Expand Up @@ -98,6 +98,12 @@ class TickEvent: public Event
int PushToStack(lua_State *l) override { return 0; }
};

class CloseEvent: public Event
{
public:
int PushToStack(lua_State *l) override { return 0; }
};

class LuaEvents
{
public:
Expand All @@ -109,7 +115,8 @@ class LuaEvents
mouseup,
mousemove,
mousewheel,
tick
tick,
close
};

static int RegisterEventHook(lua_State* l, ByteString eventName);
Expand Down
1 change: 1 addition & 0 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -3311,6 +3311,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::close); lua_setfield(l, -2, "close");
}

int LuaScriptInterface::event_register(lua_State * l)
Expand Down

0 comments on commit e48bd48

Please sign in to comment.