OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import "dart:math" as math; | 5 import "dart:math" as math; |
6 import 'dart:sky'; | 6 import 'dart:sky'; |
7 | 7 |
8 import 'package:sky/rendering/object.dart'; | |
abarth-chromium
2015/06/23 02:28:45
ditto
iansf
2015/06/23 22:46:09
Done.
| |
9 | |
8 double timeBase = null; | 10 double timeBase = null; |
9 LayoutRoot layoutRoot = new LayoutRoot(); | 11 LayoutRoot layoutRoot = new LayoutRoot(); |
10 | 12 |
11 void beginFrame(double timeStamp) { | 13 void beginFrame(double timeStamp) { |
12 if (timeBase == null) | 14 if (timeBase == null) |
13 timeBase = timeStamp; | 15 timeBase = timeStamp; |
14 double delta = timeStamp - timeBase; | 16 double delta = timeStamp - timeBase; |
15 PictureRecorder canvas = new PictureRecorder(view.width, view.height); | 17 PictureRecorder recorder = new PictureRecorder(); |
18 RenderCanvas canvas = new RenderCanvas(recorder, view.width, view.height); | |
16 canvas.translate(view.width / 2.0, view.height / 2.0); | 19 canvas.translate(view.width / 2.0, view.height / 2.0); |
17 canvas.rotate(math.PI * delta / 1800); | 20 canvas.rotate(math.PI * delta / 1800); |
18 canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), | 21 canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0), |
19 new Paint()..color = const Color.fromARGB(255, 0, 255, 0)); | 22 new Paint()..color = const Color.fromARGB(255, 0, 255, 0)); |
20 | 23 |
21 double sin = math.sin(delta / 200); | 24 double sin = math.sin(delta / 200); |
22 layoutRoot.maxWidth = 150.0 + (50 * sin); | 25 layoutRoot.maxWidth = 150.0 + (50 * sin); |
23 layoutRoot.layout(); | 26 layoutRoot.layout(); |
24 | 27 |
25 canvas.translate(layoutRoot.maxWidth / -2.0, (layoutRoot.maxWidth / 2.0) - 125 ); | 28 canvas.translate(layoutRoot.maxWidth / -2.0, (layoutRoot.maxWidth / 2.0) - 125 ); |
26 layoutRoot.paint(canvas); | 29 layoutRoot.paint(canvas); |
27 | 30 |
28 view.picture = canvas.endRecording(); | 31 view.picture = recorder.endRecording(); |
29 view.scheduleFrame(); | 32 view.scheduleFrame(); |
30 } | 33 } |
31 | 34 |
32 void main() { | 35 void main() { |
33 var document = new Document(); | 36 var document = new Document(); |
34 var arabic = document.createText("هذا هو قليلا طويلة من النص الذي يجب التفاف . "); | 37 var arabic = document.createText("هذا هو قليلا طويلة من النص الذي يجب التفاف . "); |
35 var more = document.createText(" و أكثر قليلا لجعله أطول. "); | 38 var more = document.createText(" و أكثر قليلا لجعله أطول. "); |
36 var block = document.createElement('p'); | 39 var block = document.createElement('p'); |
37 block.style['display'] = 'paragraph'; | 40 block.style['display'] = 'paragraph'; |
38 block.style['direction'] = 'rtl'; | 41 block.style['direction'] = 'rtl'; |
39 block.style['unicode-bidi'] = 'plaintext'; | 42 block.style['unicode-bidi'] = 'plaintext'; |
40 block.appendChild(arabic); | 43 block.appendChild(arabic); |
41 block.appendChild(more); | 44 block.appendChild(more); |
42 | 45 |
43 layoutRoot.rootElement = block; | 46 layoutRoot.rootElement = block; |
44 | 47 |
45 view.setBeginFrameCallback(beginFrame); | 48 view.setBeginFrameCallback(beginFrame); |
46 view.scheduleFrame(); | 49 view.scheduleFrame(); |
47 } | 50 } |
OLD | NEW |