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 bool onQuery(SkEvent* evt) SK_OVERRIDE { | 78 bool onQuery(SkEvent* evt) 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 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 104 void onDrawContent(SkCanvas* canvas) 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? |
115 fLua->pushCanvas(canvas); | 115 fLua->pushCanvas(canvas); |
116 fLua->pushScalar(this->width()); | 116 fLua->pushScalar(this->width()); |
117 fLua->pushScalar(this->height()); | 117 fLua->pushScalar(this->height()); |
118 if (lua_pcall(L, 3, 1, 0) != LUA_OK) { | 118 if (lua_pcall(L, 3, 1, 0) != LUA_OK) { |
119 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); | 119 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
120 } else { | 120 } else { |
121 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { | 121 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { |
122 this->inval(NULL); | 122 this->inval(NULL); |
123 } | 123 } |
124 } | 124 } |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, | 128 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, |
129 unsigned modi) SK_OVERRIDE { | 129 unsigned modi) override { |
130 lua_State* L = this->ensureLua(); | 130 lua_State* L = this->ensureLua(); |
131 lua_getglobal(L, gClickName); | 131 lua_getglobal(L, gClickName); |
132 if (lua_isfunction(L, -1)) { | 132 if (lua_isfunction(L, -1)) { |
133 fLua->pushScalar(x); | 133 fLua->pushScalar(x); |
134 fLua->pushScalar(y); | 134 fLua->pushScalar(y); |
135 fLua->pushString("down"); | 135 fLua->pushString("down"); |
136 if (lua_pcall(L, 3, 1, 0) != LUA_OK) { | 136 if (lua_pcall(L, 3, 1, 0) != LUA_OK) { |
137 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); | 137 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
138 } else { | 138 } else { |
139 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { | 139 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { |
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 bool onClick(Click* click) SK_OVERRIDE { | 150 bool onClick(Click* click) 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 |