mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Flesh out the Painting API a bit.
This exposes most methods from Skia's C canvas API to Dart. For now, SkRect and SkMatrix are represented simply as an array of floats, which requires a conversion at the bindings layer. More complex types like SkPath are still TODO. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/1144483002
This commit is contained in:
parent
a0609d1f4e
commit
769cef59ba
46
examples/raw/painting.sky
Normal file
46
examples/raw/painting.sky
Normal file
@ -0,0 +1,46 @@
|
||||
<sky>
|
||||
<style>
|
||||
div {
|
||||
height: 200px;
|
||||
background-color: lightblue;
|
||||
}
|
||||
</style>
|
||||
<div id="canvas" />
|
||||
<script>
|
||||
import 'dart:math' as math;
|
||||
import 'dart:sky';
|
||||
|
||||
void main() {
|
||||
var element = document.getElementById('canvas');
|
||||
element.requestPaint((PaintingContext context) {
|
||||
Paint paint = new Paint();
|
||||
double radius = math.min(context.width, context.height) / 2.0;
|
||||
|
||||
context.save();
|
||||
|
||||
context.clipRect([0.0, 0.0, context.width, radius]);
|
||||
|
||||
context.translate(context.width / 2.0, context.height / 2.0);
|
||||
paint.setARGB(128, 255, 0, 255);
|
||||
context.rotateDegrees(45.0);
|
||||
context.drawRect([-radius, -radius, radius, radius], paint);
|
||||
|
||||
// Scale x and y by 0.5.
|
||||
var scaleMatrix = [
|
||||
0.5, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0,
|
||||
0.0, 0.0, 1.0
|
||||
];
|
||||
context.concat(scaleMatrix);
|
||||
paint.setARGB(128, 0, 255, 0);
|
||||
context.drawCircle(0.0, 0.0, radius, paint);
|
||||
|
||||
context.restore();
|
||||
|
||||
context.drawCircle(0.0, 0.0, radius, paint);
|
||||
|
||||
context.commit();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</sky>
|
||||
Loading…
x
Reference in New Issue
Block a user