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:
Matt Perry 2015-05-13 17:17:26 -04:00
parent a0609d1f4e
commit 769cef59ba

46
examples/raw/painting.sky Normal file
View 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>