OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkLua.h" | 10 #include "SkLua.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 data->unref(); | 68 data->unref(); |
69 this->setImageFilename(fLua->get()); | 69 this->setImageFilename(fLua->get()); |
70 } else { | 70 } else { |
71 fLua->runCode(gMissingCode); | 71 fLua->runCode(gMissingCode); |
72 } | 72 } |
73 } | 73 } |
74 return fLua->get(); | 74 return fLua->get(); |
75 } | 75 } |
76 | 76 |
77 protected: | 77 protected: |
78 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { | 78 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
79 if (SampleCode::TitleQ(*evt)) { | 79 if (SampleCode::TitleQ(*evt)) { |
80 SampleCode::TitleR(evt, "Lua"); | 80 SampleCode::TitleR(evt, "Lua"); |
81 return true; | 81 return true; |
82 } | 82 } |
83 SkUnichar uni; | 83 SkUnichar uni; |
84 if (SampleCode::CharQ(*evt, &uni)) { | 84 if (SampleCode::CharQ(*evt, &uni)) { |
85 lua_State* L = this->ensureLua(); | 85 lua_State* L = this->ensureLua(); |
86 lua_getglobal(L, gUnicharName); | 86 lua_getglobal(L, gUnicharName); |
87 if (lua_isfunction(L, -1)) { | 87 if (lua_isfunction(L, -1)) { |
88 SkString str; | 88 SkString str; |
89 str.appendUnichar(uni); | 89 str.appendUnichar(uni); |
90 fLua->pushString(str.c_str()); | 90 fLua->pushString(str.c_str()); |
91 if (lua_pcall(L, 1, 1, 0) != LUA_OK) { | 91 if (lua_pcall(L, 1, 1, 0) != LUA_OK) { |
92 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); | 92 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
93 } else { | 93 } else { |
94 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { | 94 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { |
95 this->inval(NULL); | 95 this->inval(NULL); |
96 return true; | 96 return true; |
97 } | 97 } |
98 } | 98 } |
99 } | 99 } |
100 } | 100 } |
101 return this->INHERITED::onQuery(evt); | 101 return this->INHERITED::onQuery(evt); |
102 } | 102 } |
103 | 103 |
104 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 104 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
105 lua_State* L = this->ensureLua(); | 105 lua_State* L = this->ensureLua(); |
106 | 106 |
107 lua_getglobal(L, gDrawName); | 107 lua_getglobal(L, gDrawName); |
108 if (!lua_isfunction(L, -1)) { | 108 if (!lua_isfunction(L, -1)) { |
109 int t = lua_type(L, -1); | 109 int t = lua_type(L, -1); |
110 SkDebugf("--- expected %s function %d, ignoring.\n", gDrawName, t); | 110 SkDebugf("--- expected %s function %d, ignoring.\n", gDrawName, t); |
111 lua_pop(L, 1); | 111 lua_pop(L, 1); |
112 } else { | 112 } else { |
113 // does it make sense to try to "cache" the lua version of this | 113 // does it make sense to try to "cache" the lua version of this |
114 // canvas between draws? | 114 // canvas between draws? |
(...skipping 25 matching lines...) Expand all Loading... |
140 this->inval(NULL); | 140 this->inval(NULL); |
141 Click* c = new Click(this); | 141 Click* c = new Click(this); |
142 c->setType(gLuaClickHandlerName); | 142 c->setType(gLuaClickHandlerName); |
143 return c; | 143 return c; |
144 } | 144 } |
145 } | 145 } |
146 } | 146 } |
147 return this->INHERITED::onFindClickHandler(x, y, modi); | 147 return this->INHERITED::onFindClickHandler(x, y, modi); |
148 } | 148 } |
149 | 149 |
150 virtual bool onClick(Click* click) SK_OVERRIDE { | 150 bool onClick(Click* click) SK_OVERRIDE { |
151 if (click->getType() != gLuaClickHandlerName) { | 151 if (click->getType() != gLuaClickHandlerName) { |
152 return this->INHERITED::onClick(click); | 152 return this->INHERITED::onClick(click); |
153 } | 153 } |
154 | 154 |
155 const char* state = NULL; | 155 const char* state = NULL; |
156 switch (click->fState) { | 156 switch (click->fState) { |
157 case Click::kMoved_State: | 157 case Click::kMoved_State: |
158 state = "moved"; | 158 state = "moved"; |
159 break; | 159 break; |
160 case Click::kUp_State: | 160 case Click::kUp_State: |
(...skipping 18 matching lines...) Expand all Loading... |
179 private: | 179 private: |
180 SkLua* fLua; | 180 SkLua* fLua; |
181 | 181 |
182 typedef SampleView INHERITED; | 182 typedef SampleView INHERITED; |
183 }; | 183 }; |
184 | 184 |
185 ////////////////////////////////////////////////////////////////////////////// | 185 ////////////////////////////////////////////////////////////////////////////// |
186 | 186 |
187 static SkView* MyFactory() { return new LuaView; } | 187 static SkView* MyFactory() { return new LuaView; } |
188 static SkViewRegister reg(MyFactory); | 188 static SkViewRegister reg(MyFactory); |
OLD | NEW |