diff --git a/editor/src/messages/portfolio/document/overlays/grid_overlays.rs b/editor/src/messages/portfolio/document/overlays/grid_overlays.rs index 3c3c0530..ad6eb18b 100644 --- a/editor/src/messages/portfolio/document/overlays/grid_overlays.rs +++ b/editor/src/messages/portfolio/document/overlays/grid_overlays.rs @@ -183,7 +183,8 @@ fn grid_overlay_isometric_dot(document: &DocumentMessageHandler, overlay_context document_to_viewport.transform_point2(start), document_to_viewport.transform_point2(end), Some(&("#".to_string() + &grid_color.rgba_hex())), - Some((spacing_x / cos_a) * document_to_viewport.matrix2.x_axis.length()), + Some(1.), + Some((spacing_x / cos_a) * document_to_viewport.matrix2.x_axis.length() - 1.), None, ); } diff --git a/editor/src/messages/portfolio/document/overlays/utility_types.rs b/editor/src/messages/portfolio/document/overlays/utility_types.rs index 9bde14ea..f35f8418 100644 --- a/editor/src/messages/portfolio/document/overlays/utility_types.rs +++ b/editor/src/messages/portfolio/document/overlays/utility_types.rs @@ -32,16 +32,23 @@ impl core::hash::Hash for OverlayContext { impl OverlayContext { pub fn quad(&mut self, quad: Quad, color_fill: Option<&str>) { - self.dashed_quad(quad, color_fill, None, None); + self.dashed_quad(quad, color_fill, None, None, None); } - pub fn dashed_quad(&mut self, quad: Quad, color_fill: Option<&str>, dash_width: Option, gap_width: Option) { + pub fn dashed_quad(&mut self, quad: Quad, color_fill: Option<&str>, dash_width: Option, dash_gap_width: Option, dash_offset: Option) { // Set the dash pattern if let Some(dash_width) = dash_width { - let gap_width = gap_width.unwrap_or(1.); + let dash_gap_width = dash_gap_width.unwrap_or(1.); let array = js_sys::Array::new(); - array.push(&JsValue::from(dash_width - 1.)); - array.push(&JsValue::from(gap_width)); + array.push(&JsValue::from(dash_width)); + array.push(&JsValue::from(dash_gap_width)); + + if let Some(dash_offset) = dash_offset { + if dash_offset != 0. { + self.render_context.set_line_dash_offset(dash_offset); + } + } + self.render_context .set_line_dash(&JsValue::from(array)) .map_err(|error| log::warn!("Error drawing dashed line: {:?}", error)) @@ -70,19 +77,29 @@ impl OverlayContext { .map_err(|error| log::warn!("Error drawing dashed line: {:?}", error)) .ok(); } + if dash_offset.is_some() && dash_offset != Some(0.) { + self.render_context.set_line_dash_offset(0.); + } } pub fn line(&mut self, start: DVec2, end: DVec2, color: Option<&str>) { - self.dashed_line(start, end, color, None, None) + self.dashed_line(start, end, color, None, None, None) } - pub fn dashed_line(&mut self, start: DVec2, end: DVec2, color: Option<&str>, dash_width: Option, gap_width: Option) { + pub fn dashed_line(&mut self, start: DVec2, end: DVec2, color: Option<&str>, dash_width: Option, dash_gap_width: Option, dash_offset: Option) { // Set the dash pattern if let Some(dash_width) = dash_width { - let gap_width = gap_width.unwrap_or(1.); + let dash_gap_width = dash_gap_width.unwrap_or(1.); let array = js_sys::Array::new(); - array.push(&JsValue::from(dash_width - 1.)); - array.push(&JsValue::from(gap_width)); + array.push(&JsValue::from(dash_width)); + array.push(&JsValue::from(dash_gap_width)); + + if let Some(dash_offset) = dash_offset { + if dash_offset != 0. { + self.render_context.set_line_dash_offset(dash_offset); + } + } + self.render_context .set_line_dash(&JsValue::from(array)) .map_err(|error| log::warn!("Error drawing dashed line: {:?}", error)) @@ -105,6 +122,9 @@ impl OverlayContext { .map_err(|error| log::warn!("Error drawing dashed line: {:?}", error)) .ok(); } + if dash_offset.is_some() && dash_offset != Some(0.) { + self.render_context.set_line_dash_offset(0.); + } } pub fn manipulator_handle(&mut self, position: DVec2, selected: bool) { diff --git a/editor/src/messages/tool/common_functionality/measure.rs b/editor/src/messages/tool/common_functionality/measure.rs index 773cc47e..563a2503 100644 --- a/editor/src/messages/tool/common_functionality/measure.rs +++ b/editor/src/messages/tool/common_functionality/measure.rs @@ -9,7 +9,7 @@ fn draw_dashed_line(line_start: DVec2, line_end: DVec2, transform: DAffine2, ove let min_viewport = transform.transform_point2(line_start); let max_viewport = transform.transform_point2(line_end); - overlay_context.dashed_line(min_viewport, max_viewport, None, Some(2.), Some(3.)); + overlay_context.dashed_line(min_viewport, max_viewport, None, Some(2.), Some(2.), Some(0.5)); } /// Draws a solid line with a length annotation between two points transformed by the given affine transformations. fn draw_line_with_length(line_start: DVec2, line_end: DVec2, transform: DAffine2, document_to_viewport: DAffine2, overlay_context: &mut OverlayContext, label_alignment: LabelAlignment) { diff --git a/editor/src/messages/tool/tool_messages/select_tool.rs b/editor/src/messages/tool/tool_messages/select_tool.rs index f459fa9f..d2bf877d 100644 --- a/editor/src/messages/tool/tool_messages/select_tool.rs +++ b/editor/src/messages/tool/tool_messages/select_tool.rs @@ -432,7 +432,7 @@ impl Fsm for SelectToolFsmState { let quad = Quad::from_box([DVec2::ZERO, far]); let transformed_quad = document.metadata().transform_to_viewport(layer) * quad; - overlay_context.dashed_quad(transformed_quad, None, Some(7.), Some(5.)); + overlay_context.dashed_quad(transformed_quad, None, Some(4.), Some(4.), Some(0.5)); } }