mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-26 02:08:12 +08:00
Refactor font_cache into render_data; delete image layer type
This commit is contained in:
@@ -4,8 +4,7 @@ use crate::messages::prelude::*;
|
||||
|
||||
use document_legacy::intersection::Quad;
|
||||
use document_legacy::layers::layer_info::LayerDataType;
|
||||
use document_legacy::layers::style::{self, Fill, Stroke};
|
||||
use document_legacy::layers::text_layer::FontCache;
|
||||
use document_legacy::layers::style::{self, Fill, RenderData, Stroke};
|
||||
use document_legacy::{LayerId, Operation};
|
||||
use graphene_std::vector::subpath::Subpath;
|
||||
|
||||
@@ -26,7 +25,7 @@ impl PathOutline {
|
||||
overlay_path: Option<Vec<LayerId>>,
|
||||
document: &DocumentMessageHandler,
|
||||
responses: &mut VecDeque<Message>,
|
||||
font_cache: &FontCache,
|
||||
render_data: &RenderData,
|
||||
) -> Option<Vec<LayerId>> {
|
||||
// Get layer data
|
||||
let document_layer = document.document_legacy.layer(&document_layer_path).ok()?;
|
||||
@@ -35,8 +34,8 @@ impl PathOutline {
|
||||
// Get the bezpath from the shape or text
|
||||
let subpath = match &document_layer.data {
|
||||
LayerDataType::Shape(layer_shape) => Some(layer_shape.shape.clone()),
|
||||
LayerDataType::Text(text) => Some(text.to_subpath_nonmut(font_cache)),
|
||||
_ => document_layer.aabb_for_transform(DAffine2::IDENTITY, font_cache).map(|[p1, p2]| Subpath::new_rect(p1, p2)),
|
||||
LayerDataType::Text(text) => Some(text.to_subpath_nonmut(render_data)),
|
||||
_ => document_layer.aabb_for_transform(DAffine2::IDENTITY, render_data).map(|[p1, p2]| Subpath::new_rect(p1, p2)),
|
||||
}?;
|
||||
|
||||
// Generate a new overlay layer if necessary
|
||||
@@ -74,16 +73,16 @@ impl PathOutline {
|
||||
|
||||
/// Creates an outline of a layer either with a pre-existing overlay or by generating a new one
|
||||
///
|
||||
/// Creates an outline, discarding the overlay on failiure
|
||||
/// Creates an outline, discarding the overlay on failure
|
||||
fn create_outline(
|
||||
document_layer_path: Vec<LayerId>,
|
||||
overlay_path: Option<Vec<LayerId>>,
|
||||
document: &DocumentMessageHandler,
|
||||
responses: &mut VecDeque<Message>,
|
||||
font_cache: &FontCache,
|
||||
render_data: &RenderData,
|
||||
) -> Option<Vec<LayerId>> {
|
||||
let copied_overlay_path = overlay_path.clone();
|
||||
let result = Self::try_create_outline(document_layer_path, overlay_path, document, responses, font_cache);
|
||||
let result = Self::try_create_outline(document_layer_path, overlay_path, document, responses, render_data);
|
||||
if result.is_none() {
|
||||
// Discard the overlay layer if it exists
|
||||
if let Some(overlay_path) = copied_overlay_path {
|
||||
@@ -104,17 +103,17 @@ impl PathOutline {
|
||||
}
|
||||
|
||||
/// Performs an intersect test and generates a hovered overlay if necessary
|
||||
pub fn intersect_test_hovered(&mut self, input: &InputPreprocessorMessageHandler, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, font_cache: &FontCache) {
|
||||
pub fn intersect_test_hovered(&mut self, input: &InputPreprocessorMessageHandler, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, render_data: &RenderData) {
|
||||
// Get the layer the user is hovering over
|
||||
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
|
||||
let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]);
|
||||
let mut intersection = document.document_legacy.intersects_quad_root(quad, font_cache);
|
||||
let mut intersection = document.document_legacy.intersects_quad_root(quad, render_data);
|
||||
|
||||
// If the user is hovering over a layer they have not already selected, then update outline
|
||||
if let Some(path) = intersection.pop() {
|
||||
if !document.selected_visible_layers().any(|visible| visible == path.as_slice()) {
|
||||
// Updates the overlay, generating a new one if necessary
|
||||
self.hovered_overlay_path = Self::create_outline(path.clone(), self.hovered_overlay_path.take(), document, responses, font_cache);
|
||||
self.hovered_overlay_path = Self::create_outline(path.clone(), self.hovered_overlay_path.take(), document, responses, render_data);
|
||||
if self.hovered_overlay_path.is_none() {
|
||||
self.clear_hovered(responses);
|
||||
}
|
||||
@@ -137,11 +136,11 @@ impl PathOutline {
|
||||
}
|
||||
|
||||
/// Updates the selected overlays, generating or removing overlays if necessary
|
||||
pub fn update_selected<'a>(&mut self, selected: impl Iterator<Item = &'a [LayerId]>, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, font_cache: &FontCache) {
|
||||
pub fn update_selected<'a>(&mut self, selected: impl Iterator<Item = &'a [LayerId]>, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, render_data: &RenderData) {
|
||||
let mut old_overlay_paths = std::mem::take(&mut self.selected_overlay_paths);
|
||||
|
||||
for document_layer_path in selected {
|
||||
if let Some(overlay_path) = Self::create_outline(document_layer_path.to_vec(), old_overlay_paths.pop(), document, responses, font_cache) {
|
||||
if let Some(overlay_path) = Self::create_outline(document_layer_path.to_vec(), old_overlay_paths.pop(), document, responses, render_data) {
|
||||
self.selected_overlay_paths.push(overlay_path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ use crate::consts::{COLOR_ACCENT, PIVOT_INNER, PIVOT_OUTER, PIVOT_OUTER_OUTLINE_
|
||||
use crate::messages::layout::utility_types::widgets::assist_widgets::PivotPosition;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use document_legacy::layers::style;
|
||||
use document_legacy::layers::text_layer::FontCache;
|
||||
use document_legacy::layers::style::{self, RenderData};
|
||||
use document_legacy::{LayerId, Operation};
|
||||
|
||||
use glam::{DAffine2, DVec2};
|
||||
@@ -40,8 +39,8 @@ impl Default for Pivot {
|
||||
|
||||
impl Pivot {
|
||||
/// Calculates the transform that gets from normalized pivot to viewspace.
|
||||
fn get_layer_pivot_transform(layer_path: &[LayerId], layer: &document_legacy::layers::layer_info::Layer, document: &DocumentMessageHandler, font_cache: &FontCache) -> DAffine2 {
|
||||
let [mut min, max] = layer.aabb_for_transform(DAffine2::IDENTITY, font_cache).unwrap_or([DVec2::ZERO, DVec2::ONE]);
|
||||
fn get_layer_pivot_transform(layer_path: &[LayerId], layer: &document_legacy::layers::layer_info::Layer, document: &DocumentMessageHandler, render_data: &RenderData) -> DAffine2 {
|
||||
let [mut min, max] = layer.aabb_for_transform(DAffine2::IDENTITY, render_data).unwrap_or([DVec2::ZERO, DVec2::ONE]);
|
||||
|
||||
// If the layer bounds are 0 in either axis then set them to one (to avoid div 0)
|
||||
if (max.x - min.x) < f64::EPSILON * 1000. {
|
||||
@@ -56,7 +55,7 @@ impl Pivot {
|
||||
}
|
||||
|
||||
/// Recomputes the pivot position and transform.
|
||||
fn recalculate_pivot(&mut self, document: &DocumentMessageHandler, font_cache: &FontCache) {
|
||||
fn recalculate_pivot(&mut self, document: &DocumentMessageHandler, render_data: &RenderData) {
|
||||
let mut layers = document.selected_visible_layers();
|
||||
if let Some(first) = layers.next() {
|
||||
// Add one because the first item is consumed above.
|
||||
@@ -66,20 +65,20 @@ impl Pivot {
|
||||
if selected_layers_count == 1 {
|
||||
if let Ok(layer) = document.document_legacy.layer(first) {
|
||||
self.normalized_pivot = layer.pivot;
|
||||
self.transform_from_normalized = Self::get_layer_pivot_transform(first, layer, document, font_cache);
|
||||
self.transform_from_normalized = Self::get_layer_pivot_transform(first, layer, document, render_data);
|
||||
self.pivot = Some(self.transform_from_normalized.transform_point2(layer.pivot));
|
||||
}
|
||||
} else {
|
||||
// If more than one layer is selected we use the AABB with the mean of the pivots
|
||||
let xy_summation = document
|
||||
.selected_visible_layers()
|
||||
.filter_map(|path| document.document_legacy.pivot(path, font_cache))
|
||||
.filter_map(|path| document.document_legacy.pivot(path, render_data))
|
||||
.reduce(|a, b| a + b)
|
||||
.unwrap_or_default();
|
||||
|
||||
let pivot = xy_summation / selected_layers_count as f64;
|
||||
self.pivot = Some(pivot);
|
||||
let [min, max] = document.selected_visible_layers_bounding_box(font_cache).unwrap_or([DVec2::ZERO, DVec2::ONE]);
|
||||
let [min, max] = document.selected_visible_layers_bounding_box(render_data).unwrap_or([DVec2::ZERO, DVec2::ONE]);
|
||||
self.normalized_pivot = (pivot - min) / (max - min);
|
||||
|
||||
self.transform_from_normalized = DAffine2::from_translation(min) * DAffine2::from_scale(max - min);
|
||||
@@ -147,8 +146,8 @@ impl Pivot {
|
||||
responses.push_back(DocumentMessage::Overlays(Operation::TransformLayerInViewport { path: inner, transform }.into()).into());
|
||||
}
|
||||
|
||||
pub fn update_pivot(&mut self, document: &DocumentMessageHandler, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
|
||||
self.recalculate_pivot(document, font_cache);
|
||||
pub fn update_pivot(&mut self, document: &DocumentMessageHandler, render_data: &RenderData, responses: &mut VecDeque<Message>) {
|
||||
self.recalculate_pivot(document, render_data);
|
||||
self.redraw_pivot(responses);
|
||||
}
|
||||
|
||||
@@ -165,10 +164,10 @@ impl Pivot {
|
||||
}
|
||||
|
||||
/// Sets the viewport position of the pivot for all selected layers.
|
||||
pub fn set_viewport_position(&self, position: DVec2, document: &DocumentMessageHandler, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
|
||||
pub fn set_viewport_position(&self, position: DVec2, document: &DocumentMessageHandler, render_data: &RenderData, responses: &mut VecDeque<Message>) {
|
||||
for layer_path in document.selected_visible_layers() {
|
||||
if let Ok(layer) = document.document_legacy.layer(layer_path) {
|
||||
let transform = Self::get_layer_pivot_transform(layer_path, layer, document, font_cache);
|
||||
let transform = Self::get_layer_pivot_transform(layer_path, layer, document, render_data);
|
||||
let pivot = transform.inverse().transform_point2(position);
|
||||
// Only update the pivot when computed position is finite. Infinite can happen when scale is 0.
|
||||
if pivot.is_finite() {
|
||||
@@ -180,8 +179,8 @@ impl Pivot {
|
||||
}
|
||||
|
||||
/// Set the pivot using the normalized transform that is set above.
|
||||
pub fn set_normalized_position(&self, position: DVec2, document: &DocumentMessageHandler, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
|
||||
self.set_viewport_position(self.transform_from_normalized.transform_point2(position), document, font_cache, responses);
|
||||
pub fn set_normalized_position(&self, position: DVec2, document: &DocumentMessageHandler, render_data: &RenderData, responses: &mut VecDeque<Message>) {
|
||||
self.set_viewport_position(self.transform_from_normalized.transform_point2(position), document, render_data, responses);
|
||||
}
|
||||
|
||||
/// Answers if the pointer is currently positioned over the pivot.
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::messages::tool::common_functionality::snapping::SnapManager;
|
||||
|
||||
use document_legacy::layers::text_layer::FontCache;
|
||||
use document_legacy::layers::style::RenderData;
|
||||
use document_legacy::LayerId;
|
||||
use document_legacy::Operation;
|
||||
|
||||
@@ -18,8 +18,8 @@ pub struct Resize {
|
||||
|
||||
impl Resize {
|
||||
/// Starts a resize, assigning the snap targets and snapping the starting position.
|
||||
pub fn start(&mut self, responses: &mut VecDeque<Message>, document: &DocumentMessageHandler, input: &InputPreprocessorMessageHandler, font_cache: &FontCache) {
|
||||
self.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, font_cache), true, true);
|
||||
pub fn start(&mut self, responses: &mut VecDeque<Message>, document: &DocumentMessageHandler, input: &InputPreprocessorMessageHandler, render_data: &RenderData) {
|
||||
self.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, render_data), true, true);
|
||||
self.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
let root_transform = document.document_legacy.root.transform;
|
||||
self.drag_start = root_transform.inverse().transform_point2(self.snap_manager.snap_position(responses, document, input.mouse.position));
|
||||
|
||||
@@ -7,6 +7,7 @@ use crate::messages::prelude::*;
|
||||
use crate::messages::tool::utility_types::ToolType;
|
||||
|
||||
use document_legacy::color::Color;
|
||||
use document_legacy::layers::style::RenderData;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ToolMessageHandler {
|
||||
@@ -21,6 +22,8 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess
|
||||
responses: &mut VecDeque<Message>,
|
||||
(document, document_id, input, persistent_data): (&DocumentMessageHandler, u64, &InputPreprocessorMessageHandler, &PersistentData),
|
||||
) {
|
||||
let render_data = RenderData::new(&persistent_data.font_cache, document.view_mode, None);
|
||||
|
||||
#[remain::sorted]
|
||||
match message {
|
||||
// Messages
|
||||
@@ -73,12 +76,12 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess
|
||||
let mut send_abort_to_tool = |tool_type, update_hints_and_cursor: bool| {
|
||||
if let Some(tool) = tool_data.tools.get_mut(&tool_type) {
|
||||
if let Some(tool_abort_message) = tool.event_to_message_map().tool_abort {
|
||||
tool.process_message(tool_abort_message, responses, (document, document_id, document_data, input, &persistent_data.font_cache));
|
||||
tool.process_message(tool_abort_message, responses, (document, document_id, document_data, input, &render_data));
|
||||
}
|
||||
|
||||
if update_hints_and_cursor {
|
||||
tool.process_message(ToolMessage::UpdateHints, responses, (document, document_id, document_data, input, &persistent_data.font_cache));
|
||||
tool.process_message(ToolMessage::UpdateCursor, responses, (document, document_id, document_data, input, &persistent_data.font_cache));
|
||||
tool.process_message(ToolMessage::UpdateHints, responses, (document, document_id, document_data, input, &render_data));
|
||||
tool.process_message(ToolMessage::UpdateCursor, responses, (document, document_id, document_data, input, &render_data));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -134,10 +137,10 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess
|
||||
// Set initial hints and cursor
|
||||
tool_data
|
||||
.active_tool_mut()
|
||||
.process_message(ToolMessage::UpdateHints, responses, (document, document_id, document_data, input, &persistent_data.font_cache));
|
||||
.process_message(ToolMessage::UpdateHints, responses, (document, document_id, document_data, input, &render_data));
|
||||
tool_data
|
||||
.active_tool_mut()
|
||||
.process_message(ToolMessage::UpdateCursor, responses, (document, document_id, document_data, input, &persistent_data.font_cache));
|
||||
.process_message(ToolMessage::UpdateCursor, responses, (document, document_id, document_data, input, &render_data));
|
||||
}
|
||||
ToolMessage::RefreshToolOptions => {
|
||||
let tool_data = &mut self.tool_state.tool_data;
|
||||
@@ -196,7 +199,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess
|
||||
|
||||
if let Some(tool) = tool_data.tools.get_mut(&tool_type) {
|
||||
if tool_type == tool_data.active_tool_type {
|
||||
tool.process_message(tool_message, responses, (document, document_id, document_data, input, &persistent_data.font_cache));
|
||||
tool.process_message(tool_message, responses, (document, document_id, document_data, input, &render_data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,14 +112,14 @@ impl Fsm for ArtboardToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, _global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, _global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
if let ToolMessage::Artboard(event) = event {
|
||||
match (self, event) {
|
||||
(state, ArtboardToolMessage::DocumentIsDirty) if state != ArtboardToolFsmState::Drawing => {
|
||||
let current_artboard = tool_data.selected_artboard.and_then(|path| document.artboard_bounding_box_and_transform(&[path], font_cache));
|
||||
let current_artboard = tool_data.selected_artboard.and_then(|path| document.artboard_bounding_box_and_transform(&[path], render_data));
|
||||
match (current_artboard, tool_data.bounding_box_overlays.take()) {
|
||||
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(responses),
|
||||
(Some((bounds, transform)), paths) => {
|
||||
@@ -173,11 +173,11 @@ impl Fsm for ArtboardToolFsmState {
|
||||
let artboard = tool_data.selected_artboard.unwrap();
|
||||
tool_data
|
||||
.snap_manager
|
||||
.start_snap(document, input, document.bounding_boxes(None, Some(artboard), font_cache), snap_x, snap_y);
|
||||
.start_snap(document, input, document.bounding_boxes(None, Some(artboard), render_data), snap_x, snap_y);
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
|
||||
if let Some(bounds) = &mut tool_data.bounding_box_overlays {
|
||||
let pivot = document.artboard_message_handler.artboards_document.pivot(&[artboard], font_cache).unwrap_or_default();
|
||||
let pivot = document.artboard_message_handler.artboards_document.pivot(&[artboard], render_data).unwrap_or_default();
|
||||
let root = document.document_legacy.root.transform;
|
||||
let pivot = root.inverse().transform_point2(pivot);
|
||||
bounds.center_of_transformation = pivot;
|
||||
@@ -188,7 +188,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
|
||||
let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]);
|
||||
let intersection = document.artboard_message_handler.artboards_document.intersects_quad_root(quad, font_cache);
|
||||
let intersection = document.artboard_message_handler.artboards_document.intersects_quad_root(quad, render_data);
|
||||
|
||||
responses.push_back(BroadcastEvent::DocumentIsDirty.into());
|
||||
if let Some(intersection) = intersection.last() {
|
||||
@@ -196,7 +196,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
|
||||
tool_data
|
||||
.snap_manager
|
||||
.start_snap(document, input, document.bounding_boxes(None, Some(intersection[0]), font_cache), true, true);
|
||||
.start_snap(document, input, document.bounding_boxes(None, Some(intersection[0]), render_data), true, true);
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
|
||||
responses.push_back(
|
||||
@@ -304,7 +304,7 @@ impl Fsm for ArtboardToolFsmState {
|
||||
let id = generate_uuid();
|
||||
tool_data.selected_artboard = Some(id);
|
||||
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, Some(id), font_cache), true, true);
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, Some(id), render_data), true, true);
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
|
||||
responses.push_back(
|
||||
|
||||
@@ -100,7 +100,7 @@ impl Fsm for EllipseToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -112,7 +112,7 @@ impl Fsm for EllipseToolFsmState {
|
||||
if let ToolMessage::Ellipse(event) = event {
|
||||
match (self, event) {
|
||||
(Ready, DragStart) => {
|
||||
shape_data.start(responses, document, input, font_cache);
|
||||
shape_data.start(responses, document, input, render_data);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
@@ -87,7 +87,7 @@ impl Fsm for EyedropperToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
_tool_data: &mut Self::ToolData,
|
||||
(_document, _document_id, global_tool_data, input, _font_cache): ToolActionHandlerData,
|
||||
(_document, _document_id, global_tool_data, input, _render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
|
||||
@@ -84,7 +84,7 @@ impl Fsm for FillToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
_tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -98,7 +98,7 @@ impl Fsm for FillToolFsmState {
|
||||
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
|
||||
let quad = Quad::from_box([mouse_pos - tolerance, mouse_pos + tolerance]);
|
||||
|
||||
if let Some(path) = document.document_legacy.intersects_quad_root(quad, font_cache).last() {
|
||||
if let Some(path) = document.document_legacy.intersects_quad_root(quad, render_data).last() {
|
||||
let color = match lmb_or_rmb {
|
||||
LeftPointerDown => global_tool_data.primary_color,
|
||||
RightPointerDown => global_tool_data.secondary_color,
|
||||
|
||||
@@ -137,7 +137,7 @@ impl Fsm for FreehandToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, _font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, _render_data): ToolActionHandlerData,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
|
||||
@@ -12,11 +12,10 @@ use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
|
||||
use document_legacy::color::Color;
|
||||
use document_legacy::intersection::Quad;
|
||||
use document_legacy::layers::layer_info::Layer;
|
||||
use document_legacy::layers::style::{Fill, Gradient, GradientType, PathStyle, Stroke};
|
||||
use document_legacy::layers::style::{Fill, Gradient, GradientType, PathStyle, RenderData, Stroke};
|
||||
use document_legacy::LayerId;
|
||||
use document_legacy::Operation;
|
||||
|
||||
use document_legacy::layers::text_layer::FontCache;
|
||||
use glam::{DAffine2, DVec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -130,8 +129,8 @@ enum GradientToolFsmState {
|
||||
}
|
||||
|
||||
/// Computes the transform from gradient space to layer space (where gradient space is 0..1 in layer space)
|
||||
fn gradient_space_transform(path: &[LayerId], layer: &Layer, document: &DocumentMessageHandler, font_cache: &FontCache) -> DAffine2 {
|
||||
let bounds = layer.aabb_for_transform(DAffine2::IDENTITY, font_cache).unwrap();
|
||||
fn gradient_space_transform(path: &[LayerId], layer: &Layer, document: &DocumentMessageHandler, render_data: &RenderData) -> DAffine2 {
|
||||
let bounds = layer.aabb_for_transform(DAffine2::IDENTITY, render_data).unwrap();
|
||||
let bound_transform = DAffine2::from_scale_angle_translation(bounds[1] - bounds[0], 0., bounds[0]);
|
||||
|
||||
let multiplied = document.document_legacy.multiply_transforms(path).unwrap();
|
||||
@@ -195,9 +194,9 @@ impl GradientOverlay {
|
||||
layer: &Layer,
|
||||
document: &DocumentMessageHandler,
|
||||
responses: &mut VecDeque<Message>,
|
||||
font_cache: &FontCache,
|
||||
render_data: &RenderData,
|
||||
) -> Self {
|
||||
let transform = gradient_space_transform(path, layer, document, font_cache);
|
||||
let transform = gradient_space_transform(path, layer, document, render_data);
|
||||
let Gradient { start, end, positions, .. } = fill;
|
||||
let [start, end] = [transform.transform_point2(*start), transform.transform_point2(*end)];
|
||||
|
||||
@@ -261,8 +260,8 @@ struct SelectedGradient {
|
||||
}
|
||||
|
||||
impl SelectedGradient {
|
||||
pub fn new(gradient: Gradient, path: &[LayerId], layer: &Layer, document: &DocumentMessageHandler, font_cache: &FontCache) -> Self {
|
||||
let transform = gradient_space_transform(path, layer, document, font_cache);
|
||||
pub fn new(gradient: Gradient, path: &[LayerId], layer: &Layer, document: &DocumentMessageHandler, render_data: &RenderData) -> Self {
|
||||
let transform = gradient_space_transform(path, layer, document, render_data);
|
||||
Self {
|
||||
path: path.to_vec(),
|
||||
transform,
|
||||
@@ -272,7 +271,7 @@ impl SelectedGradient {
|
||||
}
|
||||
|
||||
/// Update the selected gradient, checking for removal or change of gradient.
|
||||
pub fn update(gradient: &mut Option<Self>, document: &DocumentMessageHandler, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
|
||||
pub fn update(gradient: &mut Option<Self>, document: &DocumentMessageHandler, render_data: &RenderData, responses: &mut VecDeque<Message>) {
|
||||
let Some(inner_gradient) = gradient else {
|
||||
return;
|
||||
};
|
||||
@@ -285,7 +284,7 @@ impl SelectedGradient {
|
||||
};
|
||||
|
||||
// Update transform
|
||||
inner_gradient.transform = gradient_space_transform(&inner_gradient.path, layer, document, font_cache);
|
||||
inner_gradient.transform = gradient_space_transform(&inner_gradient.path, layer, document, render_data);
|
||||
|
||||
// Clear if no longer a gradient
|
||||
let Some(gradient) = layer.style().ok().and_then(|style|style.fill().as_gradient()) else {
|
||||
@@ -384,8 +383,8 @@ struct GradientToolData {
|
||||
drag_start: DVec2,
|
||||
}
|
||||
|
||||
pub fn start_snap(snap_manager: &mut SnapManager, document: &DocumentMessageHandler, input: &InputPreprocessorMessageHandler, font_cache: &FontCache) {
|
||||
snap_manager.start_snap(document, input, document.bounding_boxes(None, None, font_cache), true, true);
|
||||
pub fn start_snap(snap_manager: &mut SnapManager, document: &DocumentMessageHandler, input: &InputPreprocessorMessageHandler, render_data: &RenderData) {
|
||||
snap_manager.start_snap(document, input, document.bounding_boxes(None, None, render_data), true, true);
|
||||
snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
}
|
||||
|
||||
@@ -397,7 +396,7 @@ impl Fsm for GradientToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -409,7 +408,7 @@ impl Fsm for GradientToolFsmState {
|
||||
}
|
||||
|
||||
if self != GradientToolFsmState::Drawing {
|
||||
SelectedGradient::update(&mut tool_data.selected_gradient, document, font_cache, responses);
|
||||
SelectedGradient::update(&mut tool_data.selected_gradient, document, render_data, responses);
|
||||
}
|
||||
|
||||
for path in document.selected_visible_layers() {
|
||||
@@ -423,7 +422,9 @@ impl Fsm for GradientToolFsmState {
|
||||
.selected_gradient
|
||||
.as_ref()
|
||||
.and_then(|selected| if selected.path == path { Some(selected.dragging) } else { None });
|
||||
tool_data.gradient_overlays.push(GradientOverlay::new(gradient, dragging, path, layer, document, responses, font_cache))
|
||||
tool_data
|
||||
.gradient_overlays
|
||||
.push(GradientOverlay::new(gradient, dragging, path, layer, document, responses, render_data))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,7 +494,7 @@ impl Fsm for GradientToolFsmState {
|
||||
|
||||
let layer = document.document_legacy.layer(&overlay.path);
|
||||
if let Ok(layer) = layer {
|
||||
let mut selected_gradient = SelectedGradient::new(gradient, &overlay.path, layer, document, font_cache);
|
||||
let mut selected_gradient = SelectedGradient::new(gradient, &overlay.path, layer, document, render_data);
|
||||
|
||||
// Select the new point
|
||||
selected_gradient.dragging = GradientDragTarget::Step(index);
|
||||
@@ -541,7 +542,7 @@ impl Fsm for GradientToolFsmState {
|
||||
] {
|
||||
if pos.distance_squared(mouse) < tolerance {
|
||||
dragging = true;
|
||||
start_snap(&mut tool_data.snap_manager, document, input, font_cache);
|
||||
start_snap(&mut tool_data.snap_manager, document, input, render_data);
|
||||
tool_data.selected_gradient = Some(SelectedGradient {
|
||||
path: overlay.path.clone(),
|
||||
transform: overlay.transform,
|
||||
@@ -557,7 +558,7 @@ impl Fsm for GradientToolFsmState {
|
||||
} else {
|
||||
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
|
||||
let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]);
|
||||
let intersection = document.document_legacy.intersects_quad_root(quad, font_cache).pop();
|
||||
let intersection = document.document_legacy.intersects_quad_root(quad, render_data).pop();
|
||||
|
||||
if let Some(intersection) = intersection {
|
||||
if !document.selected_layers_contains(&intersection) {
|
||||
@@ -585,11 +586,11 @@ impl Fsm for GradientToolFsmState {
|
||||
tool_options.gradient_type,
|
||||
)
|
||||
};
|
||||
let selected_gradient = SelectedGradient::new(gradient, &intersection, layer, document, font_cache).with_gradient_start(input.mouse.position);
|
||||
let selected_gradient = SelectedGradient::new(gradient, &intersection, layer, document, render_data).with_gradient_start(input.mouse.position);
|
||||
|
||||
tool_data.selected_gradient = Some(selected_gradient);
|
||||
|
||||
start_snap(&mut tool_data.snap_manager, document, input, font_cache);
|
||||
start_snap(&mut tool_data.snap_manager, document, input, render_data);
|
||||
|
||||
GradientToolFsmState::Drawing
|
||||
} else {
|
||||
|
||||
@@ -100,7 +100,7 @@ impl Fsm for ImaginateToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, _global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, _global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -112,7 +112,7 @@ impl Fsm for ImaginateToolFsmState {
|
||||
if let ToolMessage::Imaginate(event) = event {
|
||||
match (self, event) {
|
||||
(Ready, DragStart) => {
|
||||
shape_data.start(responses, document, input, font_cache);
|
||||
shape_data.start(responses, document, input, render_data);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: true }.into());
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
|
||||
@@ -137,7 +137,7 @@ impl Fsm for LineToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -147,7 +147,7 @@ impl Fsm for LineToolFsmState {
|
||||
if let ToolMessage::Line(event) = event {
|
||||
match (self, event) {
|
||||
(Ready, DragStart) => {
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, font_cache), true, true);
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, render_data), true, true);
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
tool_data.drag_start = tool_data.snap_manager.snap_position(responses, document, input.mouse.position);
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ impl Fsm for NavigateToolFsmState {
|
||||
self,
|
||||
message: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(_document, _document_id, _global_tool_data, input, _font_cache): ToolActionHandlerData,
|
||||
(_document, _document_id, _global_tool_data, input, _render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
messages: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
|
||||
@@ -99,7 +99,7 @@ impl Fsm for NodeGraphToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, _global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, _global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -111,7 +111,7 @@ impl Fsm for NodeGraphToolFsmState {
|
||||
if let ToolMessage::NodeGraphFrame(event) = event {
|
||||
match (self, event) {
|
||||
(Ready, DragStart) => {
|
||||
shape_data.start(responses, document, input, font_cache);
|
||||
shape_data.start(responses, document, input, render_data);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: true }.into());
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
|
||||
@@ -120,7 +120,7 @@ impl Fsm for PathToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, _global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, _global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -166,7 +166,7 @@ impl Fsm for PathToolFsmState {
|
||||
let ignore_document = tool_data.shape_editor.selected_layers().clone();
|
||||
tool_data
|
||||
.snap_manager
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&ignore_document), None, font_cache), true, true);
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&ignore_document), None, render_data), true, true);
|
||||
|
||||
// Do not snap against handles when anchor is selected
|
||||
let mut extension = Vec::new();
|
||||
@@ -196,7 +196,7 @@ impl Fsm for PathToolFsmState {
|
||||
// Select shapes directly under our mouse
|
||||
let intersection = document
|
||||
.document_legacy
|
||||
.intersects_quad_root(Quad::from_box([input.mouse.position - selection_size, input.mouse.position + selection_size]), font_cache);
|
||||
.intersects_quad_root(Quad::from_box([input.mouse.position - selection_size, input.mouse.position + selection_size]), render_data);
|
||||
if !intersection.is_empty() {
|
||||
if toggle_add_to_selection {
|
||||
responses.push_back(DocumentMessage::AddSelectedLayers { additional_layers: intersection }.into());
|
||||
|
||||
@@ -158,7 +158,7 @@ impl Fsm for PenToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -190,7 +190,7 @@ impl Fsm for PenToolFsmState {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
// Initialize snapping
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, font_cache), true, true);
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, render_data), true, true);
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
|
||||
// Disable this tool's mirroring
|
||||
|
||||
@@ -100,7 +100,7 @@ impl Fsm for RectangleToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -112,7 +112,7 @@ impl Fsm for RectangleToolFsmState {
|
||||
if let ToolMessage::Rectangle(event) = event {
|
||||
match (self, event) {
|
||||
(Ready, DragStart) => {
|
||||
shape_data.start(responses, document, input, font_cache);
|
||||
shape_data.start(responses, document, input, render_data);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
@@ -285,7 +285,7 @@ impl Fsm for SelectToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, _global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, _global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -295,7 +295,7 @@ impl Fsm for SelectToolFsmState {
|
||||
if let ToolMessage::Select(event) = event {
|
||||
match (self, event) {
|
||||
(_, DocumentIsDirty | SelectionChanged) => {
|
||||
match (document.selected_visible_layers_bounding_box(font_cache), tool_data.bounding_box_overlays.take()) {
|
||||
match (document.selected_visible_layers_bounding_box(render_data), tool_data.bounding_box_overlays.take()) {
|
||||
(None, Some(bounding_box_overlays)) => bounding_box_overlays.delete(responses),
|
||||
(Some(bounds), paths) => {
|
||||
let mut bounding_box_overlays = paths.unwrap_or_else(|| BoundingBoxOverlays::new(responses));
|
||||
@@ -310,9 +310,9 @@ impl Fsm for SelectToolFsmState {
|
||||
(_, _) => {}
|
||||
};
|
||||
|
||||
tool_data.path_outlines.update_selected(document.selected_visible_layers(), document, responses, font_cache);
|
||||
tool_data.path_outlines.intersect_test_hovered(input, document, responses, font_cache);
|
||||
tool_data.pivot.update_pivot(document, font_cache, responses);
|
||||
tool_data.path_outlines.update_selected(document.selected_visible_layers(), document, responses, render_data);
|
||||
tool_data.path_outlines.intersect_test_hovered(input, document, responses, render_data);
|
||||
tool_data.pivot.update_pivot(document, render_data, responses);
|
||||
|
||||
self
|
||||
}
|
||||
@@ -325,7 +325,7 @@ impl Fsm for SelectToolFsmState {
|
||||
let quad = Quad::from_box([mouse_pos - tolerance, mouse_pos + tolerance]);
|
||||
|
||||
// Check the last (top most) intersection layer.
|
||||
if let Some(intersect_layer_path) = document.document_legacy.intersects_quad_root(quad, font_cache).last() {
|
||||
if let Some(intersect_layer_path) = document.document_legacy.intersects_quad_root(quad, render_data).last() {
|
||||
if let Ok(intersect) = document.document_legacy.layer(intersect_layer_path) {
|
||||
match intersect.data {
|
||||
LayerDataType::Text(_) => {
|
||||
@@ -376,7 +376,7 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
let mut selected: Vec<_> = document.selected_visible_layers().map(|path| path.to_vec()).collect();
|
||||
let quad = tool_data.selection_quad();
|
||||
let mut intersection = document.document_legacy.intersects_quad_root(quad, font_cache);
|
||||
let mut intersection = document.document_legacy.intersects_quad_root(quad, render_data);
|
||||
// If the user is dragging the bounding box bounds, go into ResizingBounds mode.
|
||||
// If the user is dragging the rotate trigger, go into RotatingBounds mode.
|
||||
// If the user clicks on a layer that is in their current selection, go into the dragging mode.
|
||||
@@ -385,7 +385,7 @@ impl Fsm for SelectToolFsmState {
|
||||
let state = if tool_data.pivot.is_over(input.mouse.position) {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, font_cache), true, true);
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, render_data), true, true);
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
|
||||
DraggingPivot
|
||||
@@ -397,7 +397,7 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
tool_data
|
||||
.snap_manager
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&selected), None, font_cache), snap_x, snap_y);
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&selected), None, render_data), snap_x, snap_y);
|
||||
tool_data
|
||||
.snap_manager
|
||||
.add_all_document_handles(document, input, &[], &selected.iter().map(|x| x.as_slice()).collect::<Vec<_>>(), &[]);
|
||||
@@ -409,7 +409,7 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
let selected = &tool_data.layers_dragging.iter().collect::<Vec<_>>();
|
||||
let mut selected = Selected::new(&mut bounds.original_transforms, &mut bounds.center_of_transformation, selected, responses, document);
|
||||
bounds.center_of_transformation = selected.mean_average_of_pivots(font_cache);
|
||||
bounds.center_of_transformation = selected.mean_average_of_pivots(render_data);
|
||||
}
|
||||
|
||||
ResizingBounds
|
||||
@@ -420,7 +420,7 @@ impl Fsm for SelectToolFsmState {
|
||||
let selected = selected.iter().collect::<Vec<_>>();
|
||||
let mut selected = Selected::new(&mut bounds.original_transforms, &mut bounds.center_of_transformation, &selected, responses, &document.document_legacy);
|
||||
|
||||
bounds.center_of_transformation = selected.mean_average_of_pivots(font_cache);
|
||||
bounds.center_of_transformation = selected.mean_average_of_pivots(render_data);
|
||||
}
|
||||
|
||||
tool_data.layers_dragging = selected;
|
||||
@@ -433,7 +433,7 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
tool_data
|
||||
.snap_manager
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&tool_data.layers_dragging), None, font_cache), true, true);
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&tool_data.layers_dragging), None, render_data), true, true);
|
||||
|
||||
Dragging
|
||||
} else {
|
||||
@@ -449,7 +449,7 @@ impl Fsm for SelectToolFsmState {
|
||||
tool_data.layers_dragging.append(&mut selected);
|
||||
tool_data
|
||||
.snap_manager
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&tool_data.layers_dragging), None, font_cache), true, true);
|
||||
.start_snap(document, input, document.bounding_boxes(Some(&tool_data.layers_dragging), None, render_data), true, true);
|
||||
|
||||
Dragging
|
||||
} else {
|
||||
@@ -472,7 +472,7 @@ impl Fsm for SelectToolFsmState {
|
||||
let snap = tool_data
|
||||
.layers_dragging
|
||||
.iter()
|
||||
.filter_map(|path| document.document_legacy.viewport_bounding_box(path, font_cache).ok()?)
|
||||
.filter_map(|path| document.document_legacy.viewport_bounding_box(path, render_data).ok()?)
|
||||
.flat_map(snapping::expand_bounds)
|
||||
.collect();
|
||||
|
||||
@@ -546,7 +546,7 @@ impl Fsm for SelectToolFsmState {
|
||||
(DraggingPivot, PointerMove { .. }) => {
|
||||
let mouse_position = input.mouse.position;
|
||||
let snapped_mouse_position = tool_data.snap_manager.snap_position(responses, document, mouse_position);
|
||||
tool_data.pivot.set_viewport_position(snapped_mouse_position, document, font_cache, responses);
|
||||
tool_data.pivot.set_viewport_position(snapped_mouse_position, document, render_data, responses);
|
||||
|
||||
DraggingPivot
|
||||
}
|
||||
@@ -575,7 +575,7 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
// Generate the select outline (but not if the user is going to use the bound overlays)
|
||||
if cursor == MouseCursorIcon::Default {
|
||||
tool_data.path_outlines.intersect_test_hovered(input, document, responses, font_cache);
|
||||
tool_data.path_outlines.intersect_test_hovered(input, document, responses, render_data);
|
||||
} else {
|
||||
tool_data.path_outlines.clear_hovered(responses);
|
||||
}
|
||||
@@ -639,7 +639,7 @@ impl Fsm for SelectToolFsmState {
|
||||
let quad = tool_data.selection_quad();
|
||||
responses.push_front(
|
||||
DocumentMessage::AddSelectedLayers {
|
||||
additional_layers: document.document_legacy.intersects_quad_root(quad, font_cache),
|
||||
additional_layers: document.document_legacy.intersects_quad_root(quad, render_data),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
@@ -708,7 +708,7 @@ impl Fsm for SelectToolFsmState {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let pos: Option<DVec2> = position.into();
|
||||
tool_data.pivot.set_normalized_position(pos.unwrap(), document, font_cache, responses);
|
||||
tool_data.pivot.set_normalized_position(pos.unwrap(), document, render_data, responses);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ impl Fsm for ShapeToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -151,7 +151,7 @@ impl Fsm for ShapeToolFsmState {
|
||||
if let ToolMessage::Shape(event) = event {
|
||||
match (self, event) {
|
||||
(Ready, DragStart) => {
|
||||
shape_data.start(responses, document, input, font_cache);
|
||||
shape_data.start(responses, document, input, render_data);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
@@ -146,7 +146,7 @@ impl Fsm for SplineToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -162,7 +162,7 @@ impl Fsm for SplineToolFsmState {
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
tool_data.path = Some(document.get_path_for_new_layer());
|
||||
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, font_cache), true, true);
|
||||
tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(None, None, render_data), true, true);
|
||||
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
|
||||
let snapped_position = tool_data.snap_manager.snap_position(responses, document, input.mouse.position);
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ use crate::messages::tool::utility_types::{EventToMessageMap, Fsm, ToolActionHan
|
||||
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
|
||||
|
||||
use document_legacy::intersection::Quad;
|
||||
use document_legacy::layers::style::{self, Fill, Stroke};
|
||||
use document_legacy::layers::text_layer::FontCache;
|
||||
use document_legacy::layers::style::{self, Fill, RenderData, Stroke};
|
||||
use document_legacy::LayerId;
|
||||
use document_legacy::Operation;
|
||||
|
||||
@@ -213,7 +212,7 @@ fn resize_overlays(overlays: &mut Vec<Vec<LayerId>>, responses: &mut VecDeque<Me
|
||||
}
|
||||
}
|
||||
|
||||
fn update_overlays(document: &DocumentMessageHandler, tool_data: &mut TextToolData, responses: &mut VecDeque<Message>, font_cache: &FontCache) {
|
||||
fn update_overlays(document: &DocumentMessageHandler, tool_data: &mut TextToolData, responses: &mut VecDeque<Message>, render_data: &RenderData) {
|
||||
let visible_text_layers = document.selected_visible_text_layers().collect::<Vec<_>>();
|
||||
resize_overlays(&mut tool_data.overlays, responses, visible_text_layers.len());
|
||||
|
||||
@@ -225,7 +224,7 @@ fn update_overlays(document: &DocumentMessageHandler, tool_data: &mut TextToolDa
|
||||
.document_legacy
|
||||
.layer(layer_path)
|
||||
.unwrap()
|
||||
.aabb_for_transform(document.document_legacy.multiply_transforms(layer_path).unwrap(), font_cache)
|
||||
.aabb_for_transform(document.document_legacy.multiply_transforms(layer_path).unwrap(), render_data)
|
||||
.map(|bounds| (bounds, overlay_path))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -250,7 +249,7 @@ impl Fsm for TextToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, _document_id, global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, global_tool_data, input, render_data): ToolActionHandlerData,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -260,7 +259,7 @@ impl Fsm for TextToolFsmState {
|
||||
if let ToolMessage::Text(event) = event {
|
||||
match (self, event) {
|
||||
(state, DocumentIsDirty) => {
|
||||
update_overlays(document, tool_data, responses, font_cache);
|
||||
update_overlays(document, tool_data, responses, render_data);
|
||||
|
||||
state
|
||||
}
|
||||
@@ -272,7 +271,7 @@ impl Fsm for TextToolFsmState {
|
||||
// Check if the user has selected an existing text layer
|
||||
let new_state = if let Some(clicked_text_layer_path) = document
|
||||
.document_legacy
|
||||
.intersects_quad_root(quad, font_cache)
|
||||
.intersects_quad_root(quad, render_data)
|
||||
.last()
|
||||
.filter(|l| document.document_legacy.layer(l).map(|l| l.as_text().is_ok()).unwrap_or(false))
|
||||
{
|
||||
@@ -367,7 +366,7 @@ impl Fsm for TextToolFsmState {
|
||||
(Editing, UpdateBounds { new_text }) => {
|
||||
resize_overlays(&mut tool_data.overlays, responses, 1);
|
||||
let text = document.document_legacy.layer(&tool_data.layer_path).unwrap().as_text().unwrap();
|
||||
let quad = text.bounding_box(&new_text, text.load_face(font_cache));
|
||||
let quad = text.bounding_box(&new_text, text.load_face(render_data));
|
||||
|
||||
let transformed_quad = document.document_legacy.multiply_transforms(&tool_data.layer_path).unwrap() * quad;
|
||||
let bounds = transformed_quad.bounding_box();
|
||||
|
||||
@@ -10,12 +10,12 @@ use crate::messages::layout::utility_types::widgets::label_widgets::{Separator,
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use document_legacy::color::Color;
|
||||
use document_legacy::layers::text_layer::FontCache;
|
||||
use document_legacy::layers::style::RenderData;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{self, Debug};
|
||||
|
||||
pub type ToolActionHandlerData<'a> = (&'a DocumentMessageHandler, u64, &'a DocumentToolData, &'a InputPreprocessorMessageHandler, &'a FontCache);
|
||||
pub type ToolActionHandlerData<'a> = (&'a DocumentMessageHandler, u64, &'a DocumentToolData, &'a InputPreprocessorMessageHandler, &'a RenderData<'a>);
|
||||
|
||||
pub trait ToolCommon: for<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> + PropertyHolder + ToolTransition + ToolMetadata {}
|
||||
impl<T> ToolCommon for T where T: for<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> + PropertyHolder + ToolTransition + ToolMetadata {}
|
||||
|
||||
Reference in New Issue
Block a user