Canvas: implement rectangle drawing.

This commit is contained in:
Mátyás Mustoha 2015-04-21 14:22:06 +02:00
parent e4b620ea54
commit 5287cb7fba
34 changed files with 21 additions and 155 deletions

View file

@ -640,6 +640,15 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::LineTo(Point2D(x as f32, y as f32)))).unwrap();
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rect
fn Rect(self, x: f64, y: f64, width: f64, height: f64) {
if [x, y, width, height].iter().all(|val| val.is_finite()) {
let rect = Rect(Point2D(x as f32, y as f32),
Size2D(width as f32, height as f32));
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Rect(rect))).unwrap();
}
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-quadraticcurveto
fn QuadraticCurveTo(self, cpx: f64, cpy: f64, x: f64, y: f64) {
if !(cpx.is_finite() && cpy.is_finite() &&

View file

@ -171,7 +171,7 @@ interface CanvasPathMethods {
unrestricted double radius);
// NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation);
//void rect(double x, double y, double w, double h);
void rect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
[Throws]
void arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false);