OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Skia WebTry</title> | 4 <title>Skia WebTry</title> |
5 <meta charset='utf-8' /> | 5 <meta charset='utf-8' /> |
6 <style type="text/css" media="screen"> | 6 <style type="text/css" media="screen"> |
7 textarea { | 7 textarea { |
8 margin-left: 0; | 8 margin-left: 0; |
9 border: solid 1px #ccc; | 9 border: solid 1px #ccc; |
10 color: green; | 10 color: green; |
11 } | 11 } |
12 pre, code { | 12 pre, code { |
13 padding: 0; | 13 padding: 0; |
14 color: green; | 14 color: green; |
15 } | 15 } |
| 16 #output { |
| 17 color: #333; |
| 18 } |
16 </style> | 19 </style> |
17 </head> | 20 </head> |
18 <body> | 21 <body> |
19 <pre><code>#include "SkCanvas.h" | 22 <pre><code>#include "SkCanvas.h" |
20 #include "SkGraphics.h" | 23 #include "SkGraphics.h" |
21 #include "SkImageEncoder.h" | 24 #include "SkImageEncoder.h" |
22 #include "SkImageInfo.h" | 25 #include "SkImageInfo.h" |
23 #include "SkForceLinking.h" | 26 #include "SkForceLinking.h" |
24 | 27 |
25 int main() { | 28 int main() { |
26 SkForceLinking(false); | 29 SkForceLinking(false); |
27 SkGraphics::Init(); | 30 SkGraphics::Init(); |
28 | 31 |
29 SkImageInfo info = SkImageInfo::MakeN32(300, 300, kPremul_SkAlphaType); | 32 SkImageInfo info = SkImageInfo::MakeN32(300, 300, kPremul_SkAlphaType); |
30 SkBitmap bitmap; | 33 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
31 bitmap.setConfig(info); | 34 SkCanvas* canvas = surface->getCanvas(); |
32 bitmap.allocPixels(); | |
33 SkCanvas c(bitmap); | |
34 c.drawColor(SK_ColorWHITE); | |
35 | 35 |
36 <textarea name='code' id='code' rows='20' cols='80'>SkPaint p; | 36 <textarea name='code' id='code' rows='20' cols='80'>SkPaint p; |
37 p.setColor(SK_ColorRED); | 37 p.setColor(SK_ColorRED); |
38 p.setAntiAlias(true); | 38 p.setAntiAlias(true); |
39 p.setStyle(SkPaint::kStroke_Style); | 39 p.setStyle(SkPaint::kStroke_Style); |
40 p.setStrokeWidth(10); | 40 p.setStrokeWidth(10); |
41 | 41 |
42 c.drawLine(20, 20, 100, 100, p); | 42 canvas->drawLine(20, 20, 100, 100, p); |
43 </textarea> | 43 </textarea> |
44 | 44 |
45 if (!SkImageEncoder::EncodeFile("foo.png", bitmap, SkImageEncoder::kPNG_Type,
100)) { | 45 if (!SkImageEncoder::EncodeFile("foo.png", bitmap, SkImageEncoder::kPNG_Type,
100)) { |
46 printf("Failed to encode\n"); | 46 printf("Failed to encode\n"); |
47 } | 47 } |
48 } | 48 } |
49 </code></pre> | 49 </code></pre> |
50 | 50 |
| 51 <input type='button' value='Run' id='run'> |
| 52 |
51 <p>Image appears here:</p> | 53 <p>Image appears here:</p> |
52 <img id='img' src=''/> | 54 <img id='img' src=''/> |
53 | 55 |
54 <pre><code id='output'></code></pre> | 56 <pre><code id='output'></code></pre> |
55 | 57 |
56 <input type='button' value='Run' id='run'> | |
57 <script type='text/javascript' charset='utf-8'> | 58 <script type='text/javascript' charset='utf-8'> |
58 var run = document.getElementById('run'); | 59 var run = document.getElementById('run'); |
59 var code = document.getElementById('code'); | 60 var code = document.getElementById('code'); |
60 var output = document.getElementById('output'); | 61 var output = document.getElementById('output'); |
61 var img = document.getElementById('img'); | 62 var img = document.getElementById('img'); |
62 | 63 |
63 function codeComplete(e) { | 64 function codeComplete(e) { |
64 // The response is JSON of the form: | 65 // The response is JSON of the form: |
65 // { | 66 // { |
66 // "message": "you had an error...", | 67 // "message": "you had an error...", |
(...skipping 16 matching lines...) Expand all Loading... |
83 alert('Something bad happened: ' + e); | 84 alert('Something bad happened: ' + e); |
84 } | 85 } |
85 | 86 |
86 run.addEventListener('click', onSubmitCode); | 87 run.addEventListener('click', onSubmitCode); |
87 function onSubmitCode() { | 88 function onSubmitCode() { |
88 var req = new XMLHttpRequest(); | 89 var req = new XMLHttpRequest(); |
89 req.addEventListener('load', codeComplete); | 90 req.addEventListener('load', codeComplete); |
90 req.addEventListener('error', codeError); | 91 req.addEventListener('error', codeError); |
91 req.overrideMimeType('application/json'); | 92 req.overrideMimeType('application/json'); |
92 req.open('POST', '.', true); | 93 req.open('POST', '.', true); |
93 req.send(code.value + '\r\nEOF\r\n'); | 94 req.send(code.value); |
94 } | 95 } |
95 </script> | 96 </script> |
96 </body> | 97 </body> |
97 </html> | 98 </html> |
OLD | NEW |