Refactor font_cache into render_data; delete image layer type

This commit is contained in:
Keavon Chambers
2023-01-29 20:31:14 -08:00
parent 7ab601c0c6
commit beab0f01c6
41 changed files with 395 additions and 554 deletions
@@ -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.