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" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 | 12 |
13 extern "C" { | 13 extern "C" { |
14 #include "lua.h" | 14 #include "lua.h" |
15 #include "lualib.h" | 15 #include "lualib.h" |
16 #include "lauxlib.h" | 16 #include "lauxlib.h" |
17 } | 17 } |
18 | 18 |
19 static const char gDrawName[] = "onDrawContent"; | 19 static const char gDrawName[] = "onDrawContent"; |
20 | 20 |
21 static const char gCode[] = "" | 21 static const char gCode[] = "" |
| 22 "require \"math\" " |
| 23 "" |
22 "local r = { left = 10, top = 10, right = 100, bottom = 80 } " | 24 "local r = { left = 10, top = 10, right = 100, bottom = 80 } " |
23 "local x = 0;" | 25 "local x = 0;" |
24 "" | 26 "" |
25 "local paint = Sk.newPaint();" | 27 "local paint = Sk.newPaint();" |
26 "paint:setAntiAlias(true);" | 28 "paint:setAntiAlias(true);" |
27 "" | 29 "" |
28 "local color = {a = 1, r = 1, g = 0, b = 0};" | 30 "local color = {a = 1, r = 1, g = 0, b = 0};" |
29 "" | 31 "" |
| 32 "function rnd(range) " |
| 33 " return math.random() * range;" |
| 34 "end " |
| 35 "" |
| 36 "rndX = function () return rnd(640) end " |
| 37 "rndY = function () return rnd(480) end " |
| 38 "" |
| 39 "function draw_rand_path(canvas);" |
| 40 " if not path_paint then " |
| 41 " path_paint = Sk.newPaint();" |
| 42 " path_paint:setAntiAlias(true);" |
| 43 " end " |
| 44 " path_paint:setColor({a = 1, r = math.random(), g = math.random(), b = ma
th.random() });" |
| 45 "" |
| 46 " local path = Sk.newPath();" |
| 47 " path:moveTo(rndX(), rndY());" |
| 48 " for i = 0, 50 do " |
| 49 " path:quadTo(rndX(), rndY(), rndX(), rndY());" |
| 50 " end " |
| 51 " canvas:drawPath(path, path_paint);" |
| 52 "end " |
| 53 "" |
30 "function onDrawContent(canvas) " | 54 "function onDrawContent(canvas) " |
| 55 " draw_rand_path(canvas);" |
31 " color.g = x / 100;" | 56 " color.g = x / 100;" |
32 " paint:setColor(color) " | 57 " paint:setColor(color) " |
33 " canvas:translate(x, 0);" | 58 " canvas:translate(x, 0);" |
34 " canvas:drawOval(r, paint) " | 59 " canvas:drawOval(r, paint) " |
35 " x = x + 1;" | 60 " x = x + 1;" |
36 " if x > 100 then x = 0 end;" | 61 " if x > 100 then x = 0 end;" |
37 "end"; | 62 "end"; |
38 | 63 |
39 class LuaView : public SampleView { | 64 class LuaView : public SampleView { |
40 public: | 65 public: |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 private: | 126 private: |
102 SkLua* fLua; | 127 SkLua* fLua; |
103 | 128 |
104 typedef SampleView INHERITED; | 129 typedef SampleView INHERITED; |
105 }; | 130 }; |
106 | 131 |
107 ////////////////////////////////////////////////////////////////////////////// | 132 ////////////////////////////////////////////////////////////////////////////// |
108 | 133 |
109 static SkView* MyFactory() { return new LuaView; } | 134 static SkView* MyFactory() { return new LuaView; } |
110 static SkViewRegister reg(MyFactory); | 135 static SkViewRegister reg(MyFactory); |
OLD | NEW |