allow lua mousepress event to cancel drawing, fixes #229

This commit is contained in:
jacob1 2014-11-06 20:06:45 -05:00
parent 5bb1d484d0
commit a801f0a0b4
7 changed files with 31 additions and 3 deletions

View File

@ -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)

View File

@ -68,6 +68,7 @@ public:
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();

View File

@ -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();

View File

@ -188,6 +188,7 @@ public:
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);

View File

@ -29,7 +29,8 @@ public:
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();

View File

@ -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);
}

View File

@ -161,6 +161,7 @@ public:
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);