|
1 |
| -use crate::consts::{COLOR_ACCENT, PATH_OUTLINE_WEIGHT}; |
| 1 | +use crate::consts::{COLOR_ACCENT, PATH_OUTLINE_WEIGHT, SELECTION_TOLERANCE}; |
2 | 2 | use crate::document::DocumentMessageHandler;
|
| 3 | +use crate::input::InputPreprocessorMessageHandler; |
3 | 4 | use crate::message_prelude::*;
|
4 | 5 |
|
| 6 | +use graphene::intersection::Quad; |
5 | 7 | use graphene::layers::layer_info::LayerDataType;
|
6 | 8 | use graphene::layers::style::{self, Fill, Stroke};
|
7 | 9 | use graphene::layers::text_layer::FontCache;
|
8 | 10 | use graphene::{LayerId, Operation};
|
9 | 11 |
|
10 |
| -use glam::DAffine2; |
| 12 | +use glam::{DAffine2, DVec2}; |
11 | 13 | use kurbo::{BezPath, Shape};
|
12 | 14 | use std::collections::VecDeque;
|
13 | 15 |
|
@@ -84,16 +86,29 @@ impl PathOutline {
|
84 | 86 | self.hovered_layer_path = None;
|
85 | 87 | }
|
86 | 88 |
|
87 |
| - /// Updates the overlay, generating a new one if necessary |
88 |
| - pub fn update_hovered(&mut self, new_layer_path: Vec<LayerId>, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, font_cache: &FontCache) { |
89 |
| - // Check if we are hovering over a different layer than before |
90 |
| - if self.hovered_layer_path.as_ref().map_or(true, |old| &new_layer_path != old) { |
91 |
| - self.hovered_overlay_path = Self::create_outline(new_layer_path.clone(), self.hovered_overlay_path.take(), document, responses, font_cache); |
92 |
| - if self.hovered_overlay_path.is_none() { |
| 89 | + /// Performs an intersect test and generates a hovered overlay if necessary |
| 90 | + pub fn intersect_test_hovered(&mut self, input: &InputPreprocessorMessageHandler, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, font_cache: &FontCache) { |
| 91 | + // Get the layer the user is hovering over |
| 92 | + let tolerance = DVec2::splat(SELECTION_TOLERANCE); |
| 93 | + let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]); |
| 94 | + let mut intersection = document.graphene_document.intersects_quad_root(quad, font_cache); |
| 95 | + |
| 96 | + // If the user is hovering over a layer they have not already selected, then update outline |
| 97 | + if let Some(path) = intersection.pop() { |
| 98 | + if !document.selected_visible_layers().any(|visible| visible == path.as_slice()) { |
| 99 | + // Updates the overlay, generating a new one if necessary |
| 100 | + self.hovered_overlay_path = Self::create_outline(path.clone(), self.hovered_overlay_path.take(), document, responses, font_cache); |
| 101 | + if self.hovered_overlay_path.is_none() { |
| 102 | + self.clear_hovered(responses); |
| 103 | + } |
| 104 | + |
| 105 | + self.hovered_layer_path = Some(path); |
| 106 | + } else { |
93 | 107 | self.clear_hovered(responses);
|
94 | 108 | }
|
| 109 | + } else { |
| 110 | + self.clear_hovered(responses); |
95 | 111 | }
|
96 |
| - self.hovered_layer_path = Some(new_layer_path); |
97 | 112 | }
|
98 | 113 |
|
99 | 114 | /// Clears overlays for the seleted paths and removes references
|
|
0 commit comments