Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Unified Diff: samplecode/SampleLua.cpp

Issue 712613002: add patch and clicktracking to lua (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/utils/SkLua.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
« no previous file with comments | « no previous file | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698