| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 this->inval(NULL); | 93 this->inval(NULL); |
| 94 return true; | 94 return true; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 return this->INHERITED::onQuery(evt); | 99 return this->INHERITED::onQuery(evt); |
| 100 } | 100 } |
| 101 | 101 |
| 102 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 102 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
| 103 SkMatrix matrix; | |
| 104 matrix.setRectToRect(SkRect::MakeWH(640, 480), | |
| 105 SkRect::MakeWH(this->width(), this->height()), | |
| 106 SkMatrix::kCenter_ScaleToFit); | |
| 107 canvas->concat(matrix); | |
| 108 | |
| 109 lua_State* L = this->ensureLua(); | 103 lua_State* L = this->ensureLua(); |
| 110 | 104 |
| 111 lua_getglobal(L, gDrawName); | 105 lua_getglobal(L, gDrawName); |
| 112 if (!lua_isfunction(L, -1)) { | 106 if (!lua_isfunction(L, -1)) { |
| 113 int t = lua_type(L, -1); | 107 int t = lua_type(L, -1); |
| 114 SkDebugf("--- expected %s function %d, ignoring.\n", gDrawName, t); | 108 SkDebugf("--- expected %s function %d, ignoring.\n", gDrawName, t); |
| 115 lua_pop(L, 1); | 109 lua_pop(L, 1); |
| 116 } else { | 110 } else { |
| 117 // does it make sense to try to "cache" the lua version of this | 111 // does it make sense to try to "cache" the lua version of this |
| 118 // canvas between draws? | 112 // canvas between draws? |
| 119 fLua->pushCanvas(canvas); | 113 fLua->pushCanvas(canvas); |
| 120 if (lua_pcall(L, 1, 1, 0) != LUA_OK) { | 114 fLua->pushScalar(this->width()); |
| 115 fLua->pushScalar(this->height()); |
| 116 if (lua_pcall(L, 3, 1, 0) != LUA_OK) { |
| 121 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); | 117 SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
| 122 } else { | 118 } else { |
| 123 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { | 119 if (lua_isboolean(L, -1) && lua_toboolean(L, -1)) { |
| 124 this->inval(NULL); | 120 this->inval(NULL); |
| 125 } | 121 } |
| 126 } | 122 } |
| 127 } | 123 } |
| 128 } | 124 } |
| 129 | 125 |
| 130 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, | 126 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 152 private: | 148 private: |
| 153 SkLua* fLua; | 149 SkLua* fLua; |
| 154 | 150 |
| 155 typedef SampleView INHERITED; | 151 typedef SampleView INHERITED; |
| 156 }; | 152 }; |
| 157 | 153 |
| 158 ////////////////////////////////////////////////////////////////////////////// | 154 ////////////////////////////////////////////////////////////////////////////// |
| 159 | 155 |
| 160 static SkView* MyFactory() { return new LuaView; } | 156 static SkView* MyFactory() { return new LuaView; } |
| 161 static SkViewRegister reg(MyFactory); | 157 static SkViewRegister reg(MyFactory); |
| OLD | NEW |