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

Side by Side Diff: experimental/webtry/templates/index.html

Issue 231853002: Cleaned up the start page, added wait cursor, disabled Run button while waiting for results. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 .waiting, .waiting * {
8 cursor: wait;
9 }
7 textarea { 10 textarea {
8 margin-left: 0; 11 margin-left: 0;
9 border: solid 1px #ccc; 12 border: solid 1px #ccc;
10 color: green; 13 color: green;
11 } 14 }
12 pre, code { 15 pre, code {
13 padding: 0; 16 padding: 0;
14 color: green; 17 color: green;
15 } 18 }
16 #output { 19 #output {
17 color: #333; 20 color: #333;
18 } 21 }
19 </style> 22 </style>
20 </head> 23 </head>
21 <body> 24 <body>
22 <pre><code>#include "SkCanvas.h" 25 <pre><code>#include "SkCanvas.h"
23 #include "SkGraphics.h"
24 #include "SkImageEncoder.h"
25 #include "SkImageInfo.h"
26 #include "SkForceLinking.h"
27 26
28 int main() { 27 void draw(SkCanvas* canvas) {
29 SkForceLinking(false); 28 <textarea name='code' id='code' rows='15' cols='80'>SkPaint p;
mtklein 2014/04/09 21:00:49 Why not 24? Heathen...
30 SkGraphics::Init();
31
32 SkImageInfo info = SkImageInfo::MakeN32(300, 300, kPremul_SkAlphaType);
mtklein 2014/04/09 21:00:49 I kinda liked these hints about what might be need
jcgregorio 2014/04/09 21:09:26 What if I add a download button that wraps the use
mtklein 2014/04/09 21:12:04 Aw, I'm just being grumpy. However you like is go
33 SkAutoTUnref&lt;SkSurface> surface(SkSurface::NewRaster(info));
34 SkCanvas* canvas = surface->getCanvas();
35
36 <textarea name='code' id='code' rows='20' cols='80'>SkPaint p;
37 p.setColor(SK_ColorRED); 29 p.setColor(SK_ColorRED);
38 p.setAntiAlias(true); 30 p.setAntiAlias(true);
39 p.setStyle(SkPaint::kStroke_Style); 31 p.setStyle(SkPaint::kStroke_Style);
40 p.setStrokeWidth(10); 32 p.setStrokeWidth(10);
41 33
42 canvas->drawLine(20, 20, 100, 100, p); 34 canvas->drawLine(20, 20, 100, 100, p);
43 </textarea> 35 </textarea>
44
45 if (!SkImageEncoder::EncodeFile("foo.png", bitmap, SkImageEncoder::kPNG_Type, 100)) {
46 printf("Failed to encode\n");
47 }
48 } 36 }
49 </code></pre> 37 </code></pre>
50 38
51 <input type='button' value='Run' id='run'> 39 <input type='button' value='Run' id='run'>
52 40
53 <p>Image appears here:</p> 41 <p>Image appears here:</p>
54 <img id='img' src=''/> 42 <img id='img' src=''/>
55 43
56 <pre><code id='output'></code></pre> 44 <pre><code id='output'></code></pre>
57 45
58 <script type='text/javascript' charset='utf-8'> 46 <script type='text/javascript' charset='utf-8'>
59 var run = document.getElementById('run'); 47 var run = document.getElementById('run');
60 var code = document.getElementById('code'); 48 var code = document.getElementById('code');
61 var output = document.getElementById('output'); 49 var output = document.getElementById('output');
62 var img = document.getElementById('img'); 50 var img = document.getElementById('img');
63 51
52 function beginWait() {
53 document.body.classList.add('waiting');
54 run.disabled = true;
55 }
56
57 function endWait() {
58 document.body.classList.remove('waiting');
59 run.disabled = false;
60 }
61
64 function codeComplete(e) { 62 function codeComplete(e) {
65 // The response is JSON of the form: 63 // The response is JSON of the form:
66 // { 64 // {
67 // "message": "you had an error...", 65 // "message": "you had an error...",
68 // "img": "<base64 encoded image but only on success>" 66 // "img": "<base64 encoded image but only on success>"
69 // } 67 // }
70 // 68 //
71 // The img is optional and only appears if there is a valid 69 // The img is optional and only appears if there is a valid
72 // image to display. 70 // image to display.
71 endWait();
73 console.log(e.target.response); 72 console.log(e.target.response);
74 body = JSON.parse(e.target.response); 73 body = JSON.parse(e.target.response);
75 output.innerText = body.message; 74 output.innerText = body.message;
76 if (body.hasOwnProperty('img')) { 75 if (body.hasOwnProperty('img')) {
77 img.src = 'data:image/png;base64,' + body.img; 76 img.src = 'data:image/png;base64,' + body.img;
78 } else { 77 } else {
79 img.src = ''; 78 img.src = '';
80 } 79 }
81 } 80 }
82 81
83 function codeError(e) { 82 function codeError(e) {
83 endWait();
84 alert('Something bad happened: ' + e); 84 alert('Something bad happened: ' + e);
85 } 85 }
86 86
87 run.addEventListener('click', onSubmitCode); 87 run.addEventListener('click', onSubmitCode);
88 function onSubmitCode() { 88 function onSubmitCode() {
89 var req = new XMLHttpRequest(); 89 beginWait();
90 req.addEventListener('load', codeComplete); 90 var req = new XMLHttpRequest();
91 req.addEventListener('error', codeError); 91 req.addEventListener('load', codeComplete);
92 req.overrideMimeType('application/json'); 92 req.addEventListener('error', codeError);
93 req.open('POST', '.', true); 93 req.overrideMimeType('application/json');
94 req.send(code.value); 94 req.open('POST', '.', true);
95 req.send(code.value);
95 } 96 }
96 </script> 97 </script>
97 </body> 98 </body>
98 </html> 99 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698