Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow lua mousepress event to cancel drawing, fixes #229
  • Loading branch information
jacob1 committed Nov 7, 2014
1 parent 5bb1d48 commit a801f0a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/gui/game/GameController.cpp
Expand Up @@ -727,6 +727,11 @@ bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl
return ret;
}

bool GameController::MouseTick()
{
return commandInterface->OnMouseTick();
}

void GameController::Tick()
{
if(firstTick)
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Expand Up @@ -68,6 +68,7 @@ class GameController: public ClientListener
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);
bool MouseTick();
void Tick();
void Exit();

Expand Down
13 changes: 13 additions & 0 deletions src/gui/game/GameView.cpp
Expand Up @@ -1729,6 +1729,19 @@ void GameView::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bo
Window::DoKeyRelease(key, character, shift, ctrl, alt);
}

void GameView::DoTick(float dt)
{
//mouse events trigger every frame when mouse is held down, needs to happen here (before things are drawn) so it can clear the point queue if false is returned from a lua mouse event
if (!c->MouseTick())
{
isMouseDown = false;
drawMode = DrawPoints;
while (!pointQueue.empty())
pointQueue.pop();
}
Window::DoTick(dt);
}

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

//Top-level handlers, for Lua interface
virtual void DoTick(float dt);
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
3 changes: 2 additions & 1 deletion src/lua/CommandInterface.h
Expand Up @@ -29,7 +29,8 @@ class CommandInterface {
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;}
virtual void OnTick() {}
virtual bool OnMouseTick() { return true; }
virtual void OnTick() { }
virtual int Command(std::string command);
virtual std::string FormatCommand(std::string command);
std::string GetLastError();
Expand Down
10 changes: 8 additions & 2 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -3004,14 +3004,20 @@ bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, boo
return luacon_keyevent(key, modifiers, LUACON_KUP);
}

bool LuaScriptInterface::OnMouseTick()
{
ui::Engine::Ref().LastTick(gettime());
if (luacon_mousedown)
return luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);
return true;
}

void LuaScriptInterface::OnTick()
{
lua_getglobal(l, "simulation");
lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, -2, "NUM_PARTS");
lua_pop(l, 1);
ui::Engine::Ref().LastTick(gettime());
if(luacon_mousedown)
luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);
luacon_step(luacon_mousex, luacon_mousey);
}

Expand Down
1 change: 1 addition & 0 deletions src/lua/LuaScriptInterface.h
Expand Up @@ -161,6 +161,7 @@ class LuaScriptInterface: public CommandInterface
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);
virtual bool OnMouseTick();
virtual void OnTick();
virtual void Init();
virtual void SetWindow(ui::Window * window);
Expand Down

0 comments on commit a801f0a

Please sign in to comment.