Skip to content

Commit 9732c02

Browse files
committed
Code review
1 parent 37fee50 commit 9732c02

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

Diff for: editor/src/messages/portfolio/document/node_graph/node_properties.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,7 @@ pub fn stroke_properties(node_id: NodeId, context: &mut NodePropertiesContext) -
24602460
};
24612461
let number_input = NumberInput::default().min(0.).disabled(line_join_val != &LineJoin::Miter);
24622462
let miter_limit = number_widget(document_node, node_id, miter_limit_index, "Miter Limit", number_input, true);
2463+
24632464
vec![
24642465
color,
24652466
LayoutGroup::Row { widgets: weight },

Diff for: node-graph/gcore/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::raster::Color;
22

33
// RENDERING
44
pub const LAYER_OUTLINE_STROKE_COLOR: Color = Color::BLACK;
5-
pub const LAYER_OUTLINE_STROKE_WEIGHT: f64 = 1.;
5+
pub const LAYER_OUTLINE_STROKE_WEIGHT: f64 = 0.5;
66

77
// Fonts
88
pub const DEFAULT_FONT_FAMILY: &str = "Cabin";

Diff for: node-graph/gcore/src/graphic_element/renderer.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ impl GraphicElementRendered for GraphicGroupTable {
332332

333333
let mut layer = false;
334334
if let Some(bounds) = self.instances().filter_map(|element| element.instance.bounding_box(transform)).reduce(Quad::combine_bounds) {
335-
// Always respect opacity, but use different blend modes based on view mode
336335
let blend_mode = match render_params.view_mode {
337336
ViewMode::Outline => peniko::Mix::Normal,
338337
_ => alpha_blending.blend_mode.into(),
@@ -466,12 +465,11 @@ impl GraphicElementRendered for VectorDataTable {
466465

467466
#[cfg(feature = "vello")]
468467
fn render_to_vello(&self, scene: &mut Scene, parent_transform: DAffine2, _: &mut RenderContext, render_params: &RenderParams) {
469-
use crate::vector::style::GradientType;
468+
use crate::vector::style::{GradientType, LineCap, LineJoin};
469+
use vello::kurbo::{Cap, Join};
470470
use vello::peniko;
471471

472472
for instance in self.instances() {
473-
let mut layer = false;
474-
475473
let multiplied_transform = parent_transform * *instance.transform;
476474
let has_real_stroke = instance.instance.style.stroke().filter(|stroke| stroke.weight() > 0.);
477475
let set_stroke_transform = has_real_stroke.map(|stroke| stroke.transform).filter(|transform| transform.matrix2.determinant() != 0.);
@@ -485,25 +483,33 @@ impl GraphicElementRendered for VectorDataTable {
485483
for subpath in instance.instance.stroke_bezier_paths() {
486484
subpath.to_vello_path(applied_stroke_transform, &mut path);
487485
}
486+
487+
// If we're using opacity or a blend mode, we need to push a layer
488+
let blend_mode = match render_params.view_mode {
489+
ViewMode::Outline => peniko::Mix::Normal,
490+
_ => instance.alpha_blending.blend_mode.into(),
491+
};
492+
let mut layer = false;
493+
if instance.alpha_blending.opacity < 1. || instance.alpha_blending.blend_mode != BlendMode::default() {
494+
layer = true;
495+
scene.push_layer(
496+
peniko::BlendMode::new(blend_mode, peniko::Compose::SrcOver),
497+
instance.alpha_blending.opacity,
498+
kurbo::Affine::new(multiplied_transform.to_cols_array()),
499+
&kurbo::Rect::new(layer_bounds[0].x, layer_bounds[0].y, layer_bounds[1].x, layer_bounds[1].y),
500+
);
501+
}
502+
503+
// Render the path
488504
match render_params.view_mode {
489505
ViewMode::Outline => {
490-
if instance.alpha_blending.opacity < 1. {
491-
layer = true;
492-
scene.push_layer(
493-
peniko::BlendMode::new(peniko::Mix::Normal, peniko::Compose::SrcOver),
494-
instance.alpha_blending.opacity,
495-
kurbo::Affine::new(multiplied_transform.to_cols_array()),
496-
&kurbo::Rect::new(layer_bounds[0].x, layer_bounds[0].y, layer_bounds[1].x, layer_bounds[1].y),
497-
);
498-
}
499-
500506
let outline_stroke = kurbo::Stroke {
501507
width: LAYER_OUTLINE_STROKE_WEIGHT,
502-
miter_limit: 4.0,
508+
miter_limit: 4.,
503509
join: kurbo::Join::Miter,
504510
start_cap: kurbo::Cap::Butt,
505511
end_cap: kurbo::Cap::Butt,
506-
dash_pattern: vec![].into(),
512+
dash_pattern: Default::default(),
507513
dash_offset: 0.,
508514
};
509515
let outline_color = peniko::Color::new([
@@ -516,15 +522,6 @@ impl GraphicElementRendered for VectorDataTable {
516522
scene.stroke(&outline_stroke, kurbo::Affine::new(element_transform.to_cols_array()), outline_color, None, &path);
517523
}
518524
_ => {
519-
if instance.alpha_blending.opacity < 1. || instance.alpha_blending.blend_mode != BlendMode::default() {
520-
layer = true;
521-
scene.push_layer(
522-
peniko::BlendMode::new(instance.alpha_blending.blend_mode.into(), peniko::Compose::SrcOver),
523-
instance.alpha_blending.opacity,
524-
kurbo::Affine::new(multiplied_transform.to_cols_array()),
525-
&kurbo::Rect::new(layer_bounds[0].x, layer_bounds[0].y, layer_bounds[1].x, layer_bounds[1].y),
526-
);
527-
}
528525
match instance.instance.style.fill() {
529526
Fill::Solid(color) => {
530527
let fill = peniko::Brush::Solid(peniko::Color::new([color.r(), color.g(), color.b(), color.a()]));
@@ -573,16 +570,14 @@ impl GraphicElementRendered for VectorDataTable {
573570
let brush_transform = kurbo::Affine::new((inverse_element_transform * parent_transform).to_cols_array());
574571
scene.fill(peniko::Fill::NonZero, kurbo::Affine::new(element_transform.to_cols_array()), &fill, Some(brush_transform), &path);
575572
}
576-
Fill::None => (),
573+
Fill::None => {}
577574
};
578575

579576
if let Some(stroke) = instance.instance.style.stroke() {
580577
let color = match stroke.color {
581578
Some(color) => peniko::Color::new([color.r(), color.g(), color.b(), color.a()]),
582579
None => peniko::Color::TRANSPARENT,
583580
};
584-
use crate::vector::style::{LineCap, LineJoin};
585-
use vello::kurbo::{Cap, Join};
586581
let cap = match stroke.line_cap {
587582
LineCap::Butt => Cap::Butt,
588583
LineCap::Round => Cap::Round,
@@ -602,12 +597,16 @@ impl GraphicElementRendered for VectorDataTable {
602597
dash_pattern: stroke.dash_lengths.into(),
603598
dash_offset: stroke.dash_offset,
604599
};
600+
601+
// Draw the stroke if it's visible
605602
if stroke.width > 0. {
606603
scene.stroke(&stroke, kurbo::Affine::new(element_transform.to_cols_array()), color, None, &path);
607604
}
608605
}
609606
}
610607
}
608+
609+
// If we pushed a layer for opacity or a blend mode, we need to pop it
611610
if layer {
612611
scene.pop_layer();
613612
}

0 commit comments

Comments
 (0)