Index: samplecode/SampleLua.cpp |
diff --git a/samplecode/SampleLua.cpp b/samplecode/SampleLua.cpp |
index 921931b20cedb6454d229dc35e279c343c88b157..81ac6aef0d9ee096cde6ef9da6a1ac94cec8ee3a 100644 |
--- a/samplecode/SampleLua.cpp |
+++ b/samplecode/SampleLua.cpp |
@@ -25,6 +25,8 @@ static const char gDrawName[] = "onDrawContent"; |
static const char gClickName[] = "onClickHandler"; |
static const char gUnicharName[] = "onCharHandler"; |
+static const char gLuaClickHandlerName[] = "lua-click-handler"; |
+ |
static const char gMissingCode[] = "" |
"local paint = Sk.newPaint()" |
"paint:setAntiAlias(true)" |
@@ -130,11 +132,15 @@ protected: |
if (lua_isfunction(L, -1)) { |
fLua->pushScalar(x); |
fLua->pushScalar(y); |
- if (lua_pcall(L, 2, 1, 0) != LUA_OK) { |
+ fLua->pushString("down"); |
+ if (lua_pcall(L, 3, 1, 0) != LUA_OK) { |
SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
} else { |
if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { |
this->inval(NULL); |
+ Click* c = new Click(this); |
+ c->setType(gLuaClickHandlerName); |
+ return c; |
} |
} |
} |
@@ -142,7 +148,32 @@ protected: |
} |
virtual bool onClick(Click* click) SK_OVERRIDE { |
- return this->INHERITED::onClick(click); |
+ if (click->getType() != gLuaClickHandlerName) { |
+ return this->INHERITED::onClick(click); |
+ } |
+ |
+ const char* state = NULL; |
+ switch (click->fState) { |
+ case Click::kMoved_State: |
+ state = "moved"; |
+ break; |
+ case Click::kUp_State: |
+ state = "up"; |
+ break; |
+ default: |
+ break; |
+ } |
+ if (state) { |
+ this->inval(NULL); |
+ lua_State* L = fLua->get(); |
+ lua_getglobal(L, gClickName); |
+ fLua->pushScalar(click->fCurr.x()); |
+ fLua->pushScalar(click->fCurr.y()); |
+ fLua->pushString(state); |
+ lua_pcall(L, 3, 1, 0); |
+ return lua_isboolean(L, -1) && lua_toboolean(L, -1); |
+ } |
+ return true; |
} |
private: |