Permalink
Browse files

allow lua mousepress event to cancel drawing, fixes #229

  • Loading branch information...
jacob1 committed Nov 7, 2014
1 parent 5bb1d48 commit a801f0a0b4c021eee2488cee71c3d2cd0037fd5b
@@ -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)
@@ -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();
@@ -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();
@@ -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);
@@ -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();
@@ -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);
}
@@ -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);

0 comments on commit a801f0a

Please sign in to comment.