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

Side by Side Diff: samplecode/SampleLua.cpp

Issue 642353005: add drawImageRect to lua, update sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/utils/SkLua.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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\" " 22 "local r = { left = 10, top = 10, right = 100, bottom = 80 } \n"
23 "" 23 "local x = 0;\n"
24 "local r = { left = 10, top = 10, right = 100, bottom = 80 } " 24 "\n"
25 "local x = 0;" 25 "local paint = Sk.newPaint();\n"
26 "" 26 "paint:setAntiAlias(true);\n"
27 "local paint = Sk.newPaint();" 27 "\n"
28 "paint:setAntiAlias(true);" 28 "local image = Sk.loadImage('/skia/sailboat.jpg');\n"
29 "" 29 "\n"
30 "local image = Sk.loadImage('/skia/trunk/sailboat.jpg');" 30 "local color = {a = 1, r = 1, g = 0, b = 0};\n"
31 "" 31 "\n"
32 "local color = {a = 1, r = 1, g = 0, b = 0};" 32 "function rnd(range) \n"
33 "" 33 " return math.random() * range;\n"
34 "function rnd(range) " 34 "end \n"
35 " return math.random() * range;" 35 "\n"
36 "end " 36 "rndX = function () return rnd(640) end \n"
37 "" 37 "rndY = function () return rnd(480) end \n"
38 "rndX = function () return rnd(640) end " 38 "\n"
39 "rndY = function () return rnd(480) end " 39 "function draw_rand_path(canvas);\n"
40 "" 40 " if not path_paint then \n"
41 "function draw_rand_path(canvas);" 41 " path_paint = Sk.newPaint();\n"
42 " if not path_paint then " 42 " path_paint:setAntiAlias(true);\n"
43 " path_paint = Sk.newPaint();" 43 " end \n"
44 " path_paint:setAntiAlias(true);" 44 " path_paint:setColor({a = 1, r = math.random(), g = math.random(), b = ma th.random() });\n"
45 " end " 45 "\n"
46 " path_paint:setColor({a = 1, r = math.random(), g = math.random(), b = ma th.random() });" 46 " local path = Sk.newPath();\n"
47 "" 47 " path:moveTo(rndX(), rndY());\n"
48 " local path = Sk.newPath();" 48 " for i = 0, 50 do \n"
49 " path:moveTo(rndX(), rndY());" 49 " path:quadTo(rndX(), rndY(), rndX(), rndY());\n"
50 " for i = 0, 50 do " 50 " end \n"
51 " path:quadTo(rndX(), rndY(), rndX(), rndY());" 51 " canvas:drawPath(path, path_paint);\n"
52 " end " 52 "\n"
53 " canvas:drawPath(path, path_paint);" 53 " paint:setColor{a=1,r=0,g=0,b=1};\n"
54 "" 54 " local align = { 'left', 'center', 'right' };\n"
55 " paint:setColor{a=1,r=0,g=0,b=1};" 55 " paint:setTextSize(30);\n"
56 " local align = { 'left', 'center', 'right' };" 56 " for k, v in next, align do \n"
57 " paint:setTextSize(30);" 57 " paint:setTextAlign(v);\n"
58 " for k, v in next, align do " 58 " canvas:drawText('Hamburgefons', 320, 200 + 30*k, paint);\n"
59 " paint:setTextAlign(v);" 59 " end \n"
60 " canvas:drawText('Hamburgefons', 320, 200 + 30*k, paint);" 60 "end \n"
61 " end " 61 "\n"
62 "end " 62 "function onStartup() \n"
63 "" 63 " local paint = Sk.newPaint();\n"
64 "function onStartup() " 64 " paint:setColor{a=1, r=1, g=0, b=0};\n"
65 " local paint = Sk.newPaint();" 65 " local doc = Sk.newDocumentPDF('/skia/trunk/test.pdf');\n"
66 " paint:setColor{a=1, r=1, g=0, b=0};" 66 " local canvas = doc:beginPage(72*8.5, 72*11);\n"
67 " local doc = Sk.newDocumentPDF('/skia/trunk/test.pdf');" 67 " canvas:drawText('Hello Lua', 300, 300, paint);\n"
68 " local canvas = doc:beginPage(72*8.5, 72*11);" 68 " doc:close();\n"
69 " canvas:drawText('Hello Lua', 300, 300, paint);" 69 " doc = nil;\n"
70 " doc:close();" 70 "end \n"
71 " doc = nil;" 71 "\n"
72 "end " 72 "function onDrawContent(canvas) \n"
73 "" 73 " draw_rand_path(canvas);\n"
74 "function onDrawContent(canvas) " 74 " color.g = x / 100;\n"
75 " draw_rand_path(canvas);" 75 " paint:setColor(color) \n"
76 " color.g = x / 100;" 76 " canvas:translate(x, 0);\n"
77 " paint:setColor(color) " 77 " canvas:drawOval(r, paint) \n"
78 " canvas:translate(x, 0);" 78 " x = x + 1;\n"
79 " canvas:drawOval(r, paint) " 79 " local r2 = {}\n"
80 " x = x + 1;" 80 " r2.left = x;\n"
81 " canvas:drawImage(image, x, r.bottom + 50, 0.5);" 81 " r2.top = r.bottom + 50;\n"
82 " if x > 100 then x = 0 end;" 82 " r2.right = r2.left + image:width() * 0.1;\n"
83 "end " 83 " r2.bottom = r2.top + image:height() * 0.1;\n"
84 "" 84 " canvas:drawImageRect(image, nil, r2, 0.75);\n"
85 "onStartup();"; 85 " if x > 100 then x = 0 end;\n"
86 "end \n"
87 "\n"
88 "onStartup();\n";
86 89
87 class LuaView : public SampleView { 90 class LuaView : public SampleView {
88 public: 91 public:
89 LuaView() : fLua(NULL) {} 92 LuaView() : fLua(NULL) {}
90 93
91 virtual ~LuaView() { 94 virtual ~LuaView() {
92 SkDELETE(fLua); 95 SkDELETE(fLua);
93 } 96 }
94 97
95 lua_State* ensureLua() { 98 lua_State* ensureLua() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 private: 148 private:
146 SkLua* fLua; 149 SkLua* fLua;
147 150
148 typedef SampleView INHERITED; 151 typedef SampleView INHERITED;
149 }; 152 };
150 153
151 ////////////////////////////////////////////////////////////////////////////// 154 //////////////////////////////////////////////////////////////////////////////
152 155
153 static SkView* MyFactory() { return new LuaView; } 156 static SkView* MyFactory() { return new LuaView; }
154 static SkViewRegister reg(MyFactory); 157 static SkViewRegister reg(MyFactory);
OLDNEW
« 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