Add lasso selection mode (#2235)

* add document method to check intersection and insideness with polygon

* impl lasso selection

* impl lasso select to always add to selection

* add hint for lasso selection

* fix calculating selection mode based on direction on each pointer move

* fix lasso polygon lagging behing mouse position

* add overlay to draw lasso polygon with fill color same as quad

* fix comment

* change removing from selection key binding from Sift + Ctrl to just Alt

* impl Alt to shrink selection for quad in path tool

* refactor rename SelectionType to SelectionShape

* impl lasso overlay for path tool

* impl selecting anchors and handles intersection lasso in path tool

* add keys hint info

* fix converting lasso polygon to closed subpath which is has less than two points

* Code review

* impl preferences-based selection mode to the Path tool for only for overlays,

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Priyanshu
2025-01-31 00:37:49 -08:00
committed by GitHub
co-authored by Keavon Chambers
parent f462963a36
commit 6802365e14
7 changed files with 365 additions and 81 deletions
@@ -37,10 +37,22 @@ 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, None);
self.dashed_polygon(&quad.0, color_fill, None, None, None);
}
pub fn dashed_quad(&mut self, quad: Quad, color_fill: Option<&str>, dash_width: Option<f64>, dash_gap_width: Option<f64>, dash_offset: Option<f64>) {
self.dashed_polygon(&quad.0, color_fill, dash_width, dash_gap_width, dash_offset);
}
pub fn polygon(&mut self, polygon: &[DVec2], color_fill: Option<&str>) {
self.dashed_polygon(&polygon, color_fill, None, None, None);
}
pub fn dashed_polygon(&mut self, polygon: &[DVec2], color_fill: Option<&str>, dash_width: Option<f64>, dash_gap_width: Option<f64>, dash_offset: Option<f64>) {
if polygon.len() < 2 {
return;
}
self.start_dpi_aware_transform();
// Set the dash pattern
@@ -63,10 +75,10 @@ impl OverlayContext {
}
self.render_context.begin_path();
self.render_context.move_to(quad.0[3].x.round() - 0.5, quad.0[3].y.round() - 0.5);
self.render_context.move_to(polygon.last().unwrap().x.round() - 0.5, polygon.last().unwrap().y.round() - 0.5);
for i in 0..4 {
self.render_context.line_to(quad.0[i].x.round() - 0.5, quad.0[i].y.round() - 0.5);
for point in polygon {
self.render_context.line_to(point.x.round() - 0.5, point.y.round() - 0.5);
}
if let Some(color_fill) = color_fill {