Canvas: add clipping path support.

This commit is contained in:
Mátyás Mustoha 2015-04-21 12:45:28 +02:00
parent 3a1bf45dea
commit 6fd6eefb35
29 changed files with 16 additions and 134 deletions

View file

@ -24,8 +24,9 @@ pub enum Canvas2dMsg {
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
BeginPath,
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
ClosePath,
ClearRect(Rect<f32>),
Clip,
ClosePath,
Fill,
FillRect(Rect<f32>),
GetImageData(Rect<f64>, Size2D<f64>, Sender<Vec<u8>>),

View file

@ -212,6 +212,7 @@ impl<'a> CanvasPaintTask<'a> {
Canvas2dMsg::ClosePath => painter.close_path(),
Canvas2dMsg::Fill => painter.fill(),
Canvas2dMsg::Stroke => painter.stroke(),
Canvas2dMsg::Clip => painter.clip(),
Canvas2dMsg::DrawImage(imagedata, image_size, dest_rect, source_rect, smoothing_enabled) => {
painter.draw_image(imagedata, image_size, dest_rect, source_rect, smoothing_enabled)
}
@ -271,6 +272,7 @@ impl<'a> CanvasPaintTask<'a> {
if let Some(state) = self.saved_states.pop() {
mem::replace(&mut self.state, state);
self.drawtarget.set_transform(&self.state.transform);
self.drawtarget.pop_clip();
}
}
@ -325,6 +327,10 @@ impl<'a> CanvasPaintTask<'a> {
};
}
fn clip(&self) {
self.drawtarget.push_clip(&self.path_builder.finish());
}
fn draw_image(&self, image_data: Vec<u8>, image_size: Size2D<f64>,
dest_rect: Rect<f64>, source_rect: Rect<f64>, smoothing_enabled: bool) {
// We round up the floating pixel values to draw the pixels