sdl2-demo: fix envelope/mesh sizes

This commit is contained in:
Tomasz Cichoń 2024-03-08 13:05:15 +01:00
parent 164a2230ee
commit b661047ca8
2 changed files with 7 additions and 7 deletions

View File

@ -392,11 +392,11 @@ fn render_times(
};
let shape = node.primitive(layout).shape();
painter.paint_shape(&shape, color);
painter.paint_shape(&shape, color, view.zoom);
}
for ghost in ghosts {
painter.paint_shape(&ghost, ColorU::new(75, 75, 150, 255));
painter.paint_shape(&ghost, ColorU::new(75, 75, 150, 255), view.zoom);
}
if let Some(ref mesh) = maybe_mesh {
@ -417,7 +417,7 @@ fn render_times(
ColorU::new(125, 125, 125, 255)
};
painter.paint_edge(from, to, color);
painter.paint_edge(from, to, color, view.zoom);
}
}
//});

View File

@ -13,7 +13,7 @@ impl<'a> Painter<'a> {
Self { canvas }
}
pub fn paint_shape(&mut self, shape: &Shape, color: ColorU) {
pub fn paint_shape(&mut self, shape: &Shape, color: ColorU, zoom: f32) {
self.canvas.set_stroke_style(color);
self.canvas.set_fill_style(color);
@ -60,19 +60,19 @@ impl<'a> Painter<'a> {
// XXX: points represented as arrays can't be conveniently converted to vector types
let topleft = vec2f(envelope.lower()[0] as f32, envelope.lower()[1] as f32);
let bottomright = vec2f(envelope.upper()[0] as f32, envelope.upper()[1] as f32);
self.canvas.set_line_width(1.0);
self.canvas.set_line_width(2.0/zoom);
self.canvas
.set_stroke_style(ColorU::new(100, 100, 100, 255));
self.canvas
.stroke_rect(RectF::new(topleft, bottomright - topleft));
}
pub fn paint_edge(&mut self, from: Point, to: Point, color: ColorU) {
pub fn paint_edge(&mut self, from: Point, to: Point, color: ColorU, zoom: f32) {
let mut path = Path2D::new();
path.move_to(vec2f(from.x() as f32, from.y() as f32));
path.line_to(vec2f(to.x() as f32, to.y() as f32));
self.canvas.set_stroke_style(color);
self.canvas.set_line_width(1.0);
self.canvas.set_line_width(2.0/zoom);
self.canvas.stroke_path(path);
}
}