🔧 Refactor RenderState scale calculation

This commit is contained in:
Elena Torro 2025-03-20 14:36:45 +01:00
parent 2d61644b05
commit e60e36a0e2
4 changed files with 29 additions and 28 deletions

View file

@ -378,14 +378,10 @@ impl RenderState {
for stroke in shape.strokes().rev() {
strokes::render(self, &shape, stroke);
}
let scale = self.get_scale();
for shadow in shape.inner_shadows().rev().filter(|s| !s.hidden()) {
shadows::render_inner_shadow(
self,
shadow,
self.viewbox.zoom * self.options.dpr(),
shape.fills().len() > 0,
);
shadows::render_inner_shadow(self, shadow, scale, shape.fills().len() > 0);
}
shadows::render_drop_shadows(self, &shape);
@ -419,14 +415,12 @@ impl RenderState {
self.cancel_animation_frame(frame_id);
}
}
let scale = self.get_scale();
self.reset_canvas();
self.surfaces.apply_mut(
&[SurfaceId::Fills, SurfaceId::Strokes, SurfaceId::DropShadows],
|s| {
s.canvas().scale((
self.viewbox.zoom * self.options.dpr(),
self.viewbox.zoom * self.options.dpr(),
));
s.canvas().scale((scale, scale));
},
);
@ -517,7 +511,7 @@ impl RenderState {
.save_layer(&mask_rec);
}
if let Some(image_filter) = element.image_filter(self.viewbox.zoom * self.options.dpr()) {
if let Some(image_filter) = element.image_filter(self.get_scale()) {
paint.set_image_filter(image_filter);
}
@ -546,9 +540,9 @@ impl RenderState {
pub fn get_current_tile_bounds(&mut self) -> Rect {
let (tile_x, tile_y) = self.current_tile.unwrap();
let zoom = self.viewbox.zoom * self.options.dpr();
let offset_x = self.viewbox.area.left * zoom;
let offset_y = self.viewbox.area.top * zoom;
let scale = self.get_scale();
let offset_x = self.viewbox.area.left * scale;
let offset_y = self.viewbox.area.top * scale;
Rect::from_xywh(
(tile_x as f32 * tiles::TILE_SIZE) - offset_x,
(tile_y as f32 * tiles::TILE_SIZE) - offset_y,
@ -782,4 +776,8 @@ impl RenderState {
}
}
}
pub fn get_scale(&self) -> f32 {
self.viewbox.zoom() * self.options.dpr()
}
}