From b661047ca8cb1e98a72bfadce5448ae995c19135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Cicho=C5=84?= Date: Fri, 8 Mar 2024 13:05:15 +0100 Subject: [PATCH] sdl2-demo: fix envelope/mesh sizes --- src/bin/topola-sdl2-demo/main.rs | 6 +++--- src/bin/topola-sdl2-demo/painter.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/topola-sdl2-demo/main.rs b/src/bin/topola-sdl2-demo/main.rs index fc53698..d8b40e3 100644 --- a/src/bin/topola-sdl2-demo/main.rs +++ b/src/bin/topola-sdl2-demo/main.rs @@ -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); } } //}); diff --git a/src/bin/topola-sdl2-demo/painter.rs b/src/bin/topola-sdl2-demo/painter.rs index 4b0b070..410cd1a 100644 --- a/src/bin/topola-sdl2-demo/painter.rs +++ b/src/bin/topola-sdl2-demo/painter.rs @@ -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); } }