Skip to content

Commit

Permalink
Merge branch 'master' into path-tool-update
Browse files Browse the repository at this point in the history
  • Loading branch information
bakayu authored Jan 19, 2025
2 parents 6575148 + b36521e commit c7adf74
Show file tree
Hide file tree
Showing 92 changed files with 916 additions and 467 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ Learn more from the [website](https://graphite.rs/), subscribe to the [newslette

## Screenshots

[!["Painted Dreams" vector artwork](https://static.graphite.rs/content/index/gui-demo-painted-dreams__2.png)](https://editor.graphite.rs/#demo/painted-dreams)
[!["Painted Dreams" vector artwork](https://static.graphite.rs/content/index/gui-demo-painted-dreams__3.png)](https://editor.graphite.rs/#demo/painted-dreams)

![Magazine spread](https://static.graphite.rs/content/index/magazine-page-layout.png)
![Magazine spread](https://static.graphite.rs/content/index/magazine-page-layout__2.png)

[!["Valley of Spires" vector artwork](https://static.graphite.rs/content/index/gui-demo-node-graph-valley-of-spires__2.png)](https://editor.graphite.rs/#demo/valley-of-spires)
[!["Isometric Fountain" vector artwork](https://static.graphite.rs/content/index/gui-demo-node-graph-isometric-fountain.png)](https://editor.graphite.rs/#demo/isometric-fountain)

!["Marbled Mandelbrot" fractal raster artwork](https://static.graphite.rs/content/index/gui-demo-fractal__2.png)
!["Marbled Mandelbrot" fractal raster artwork](https://static.graphite.rs/content/index/gui-demo-fractal__3.png)

## Contributing/building the code

Expand Down
17 changes: 0 additions & 17 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,7 @@ pub enum FrontendMessage {
#[serde(rename = "commitDate")]
commit_date: String,
},
TriggerCopyToClipboardBlobUrl {
#[serde(rename = "blobUrl")]
blob_url: String,
},
TriggerDelayedZoomCanvasToFitAll,
TriggerDownloadBlobUrl {
#[serde(rename = "layerName")]
layer_name: String,
#[serde(rename = "blobUrl")]
blob_url: String,
},
TriggerDownloadImage {
svg: String,
name: String,
Expand Down Expand Up @@ -99,9 +89,6 @@ pub enum FrontendMessage {
TriggerLoadPreferences,
TriggerOpenDocument,
TriggerPaste,
TriggerRevokeBlobUrl {
url: String,
},
TriggerSavePreferences {
preferences: PreferencesMessageHandler,
},
Expand Down Expand Up @@ -294,8 +281,4 @@ pub enum FrontendMessage {
layout_target: LayoutTarget,
diff: Vec<WidgetDiff>,
},
UpdateZoomWithScroll {
#[serde(rename = "zoomWithScroll")]
zoom_with_scroll: bool,
},
}
2 changes: 2 additions & 0 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ pub fn input_mappings() -> Mapping {
entry!(KeyDown(MouseRight); action_dispatch=PenToolMessage::Confirm),
entry!(KeyDown(Escape); action_dispatch=PenToolMessage::Confirm),
entry!(KeyDown(Enter); action_dispatch=PenToolMessage::Confirm),
entry!(KeyDown(Delete); action_dispatch=PenToolMessage::RemovePreviousHandle),
entry!(KeyDown(Backspace); action_dispatch=PenToolMessage::RemovePreviousHandle),
//
// FreehandToolMessage
entry!(PointerMove; action_dispatch=FreehandToolMessage::PointerMove),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ impl DocumentMessageHandler {
.unwrap_or(0)
}

/// Loads layer resources such as creating the blob URLs for the images and loading all of the fonts in the document.
/// Loads all of the fonts in the document.
pub fn load_layer_resources(&self, responses: &mut VecDeque<Message>) {
let mut fonts = HashSet::new();
for (_node_id, node) in self.document_network().recursive_nodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ pub fn path_overlays(document: &DocumentMessageHandler, shape_editor: &mut Shape
bezier_rs::BezierHandles::Quadratic { handle } if not_under_anchor(handle, bezier.start) && not_under_anchor(handle, bezier.end) => {
overlay_context.line(handle, bezier.start, None);
overlay_context.line(handle, bezier.end, None);
overlay_context.manipulator_handle(handle, is_selected(selected, ManipulatorPointId::PrimaryHandle(segment_id)));
overlay_context.manipulator_handle(handle, is_selected(selected, ManipulatorPointId::PrimaryHandle(segment_id)), None);
}
bezier_rs::BezierHandles::Cubic { handle_start, handle_end } => {
if not_under_anchor(handle_start, bezier.start) {
overlay_context.line(handle_start, bezier.start, None);
overlay_context.manipulator_handle(handle_start, is_selected(selected, ManipulatorPointId::PrimaryHandle(segment_id)));
overlay_context.manipulator_handle(handle_start, is_selected(selected, ManipulatorPointId::PrimaryHandle(segment_id)), None);
}
if not_under_anchor(handle_end, bezier.end) {
overlay_context.line(handle_end, bezier.end, None);
overlay_context.manipulator_handle(handle_end, is_selected(selected, ManipulatorPointId::EndHandle(segment_id)));
overlay_context.manipulator_handle(handle_end, is_selected(selected, ManipulatorPointId::EndHandle(segment_id)), None);
}
}
_ => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl OverlayContext {
}
}

pub fn manipulator_handle(&mut self, position: DVec2, selected: bool) {
pub fn manipulator_handle(&mut self, position: DVec2, selected: bool, color: Option<&str>) {
let position = position.round() - DVec2::splat(0.5);

self.render_context.begin_path();
Expand All @@ -137,7 +137,7 @@ impl OverlayContext {

let fill = if selected { COLOR_OVERLAY_BLUE } else { COLOR_OVERLAY_WHITE };
self.render_context.set_fill_style_str(fill);
self.render_context.set_stroke_style_str(COLOR_OVERLAY_BLUE);
self.render_context.set_stroke_style_str(color.unwrap_or(COLOR_OVERLAY_BLUE));
self.render_context.fill();
self.render_context.stroke();
}
Expand Down
26 changes: 7 additions & 19 deletions editor/src/messages/portfolio/document/utility_types/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ impl SnappingState {
match target {
SnapTarget::BoundingBox(target) => match target {
BoundingBoxSnapTarget::CornerPoint => self.bounding_box.corner_point,
BoundingBoxSnapTarget::AlongEdge => self.bounding_box.along_edge,
BoundingBoxSnapTarget::EdgeMidpoint => self.bounding_box.edge_midpoint,
BoundingBoxSnapTarget::CenterPoint => self.bounding_box.center_point,
},
Expand All @@ -106,7 +105,7 @@ impl SnappingState {
SnapTarget::Artboard(_) => self.artboards,
SnapTarget::Grid(_) => self.grid_snapping,
SnapTarget::Alignment(AlignmentSnapTarget::AlignWithAnchorPoint) => self.path.align_with_anchor_point,
SnapTarget::Alignment(_) => self.bounding_box.align_with_corner_point,
SnapTarget::Alignment(_) => self.bounding_box.align_with_edges,
SnapTarget::DistributeEvenly(_) => self.bounding_box.distribute_evenly,
_ => false,
}
Expand All @@ -119,8 +118,7 @@ pub struct BoundingBoxSnapping {
pub center_point: bool,
pub corner_point: bool,
pub edge_midpoint: bool,
pub along_edge: bool,
pub align_with_corner_point: bool,
pub align_with_edges: bool,
pub distribute_evenly: bool,
}

Expand All @@ -130,8 +128,7 @@ impl Default for BoundingBoxSnapping {
center_point: true,
corner_point: true,
edge_midpoint: true,
along_edge: true,
align_with_corner_point: true,
align_with_edges: true,
distribute_evenly: true,
}
}
Expand Down Expand Up @@ -378,13 +375,11 @@ impl fmt::Display for SnapSource {
}

type GetSnapState = for<'a> fn(&'a mut SnappingState) -> &'a mut bool;
pub const SNAP_FUNCTIONS_FOR_BOUNDING_BOXES: [(&str, GetSnapState, &str); 6] = [
pub const SNAP_FUNCTIONS_FOR_BOUNDING_BOXES: [(&str, GetSnapState, &str); 5] = [
(
// TODO: Rename to "Beyond Edges" and update behavior to snap to an infinite extension of the bounding box edges
// TODO: (even when the layer is locally rotated) instead of horizontally/vertically aligning with the corner points
"Align with Corner Points",
(|snapping_state| &mut snapping_state.bounding_box.align_with_corner_point) as GetSnapState,
"Snaps to horizontal/vertical alignment with the corner points of any layer's bounding box",
"Align with Edges",
(|snapping_state| &mut snapping_state.bounding_box.align_with_edges) as GetSnapState,
"Snaps to horizontal/vertical alignment with the edges of any layer's bounding box",
),
(
"Corner Points",
Expand All @@ -401,11 +396,6 @@ pub const SNAP_FUNCTIONS_FOR_BOUNDING_BOXES: [(&str, GetSnapState, &str); 6] = [
(|snapping_state| &mut snapping_state.bounding_box.edge_midpoint) as GetSnapState,
"Snaps to any of the four points at the middle of the edges of any layer's bounding box",
),
(
"Along Edges",
(|snapping_state| &mut snapping_state.bounding_box.along_edge) as GetSnapState,
"Snaps anywhere along the four edges of any layer's bounding box",
),
(
"Distribute Evenly",
(|snapping_state| &mut snapping_state.bounding_box.distribute_evenly) as GetSnapState,
Expand Down Expand Up @@ -463,7 +453,6 @@ pub enum BoundingBoxSnapTarget {
CornerPoint,
CenterPoint,
EdgeMidpoint,
AlongEdge,
}

impl fmt::Display for BoundingBoxSnapTarget {
Expand All @@ -472,7 +461,6 @@ impl fmt::Display for BoundingBoxSnapTarget {
BoundingBoxSnapTarget::CornerPoint => write!(f, "Bounding Box: Corner Point"),
BoundingBoxSnapTarget::CenterPoint => write!(f, "Bounding Box: Center Point"),
BoundingBoxSnapTarget::EdgeMidpoint => write!(f, "Bounding Box: Edge Midpoint"),
BoundingBoxSnapTarget::AlongEdge => write!(f, "Bounding Box: Along Edge"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/src/messages/portfolio/portfolio_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
let () = fut.await;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(module = "/../frontend/src/wasm-communication/editor.ts")]
#[wasm_bindgen(module = "/../frontend/src/editor.ts")]
extern "C" {
#[wasm_bindgen(js_name = injectImaginatePollServerStatus)]
fn inject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ impl MessageHandler<PreferencesMessage, ()> for PreferencesMessageHandler {
true => MappingVariant::ZoomWithScroll,
};
responses.add(KeyMappingMessage::ModifyMapping(variant));
responses.add(FrontendMessage::UpdateZoomWithScroll { zoom_with_scroll });
}
}

Expand Down
14 changes: 14 additions & 0 deletions editor/src/messages/tool/common_functionality/shape_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ impl ClosestSegment {
(stroke_width_sq + tolerance_sq) < dist_sq
}

pub fn handle_positions(&self, document_metadata: &DocumentMetadata) -> (Option<DVec2>, Option<DVec2>) {
// Transform to viewport space
let transform = document_metadata.transform_to_viewport(self.layer);

// Split the Bezier at the parameter `t`
let [first, second] = self.bezier.split(TValue::Parametric(self.t));

// Transform the handle positions to viewport space
let first_handle = first.handle_end().map(|handle| transform.transform_point2(handle));
let second_handle = second.handle_start().map(|handle| transform.transform_point2(handle));

(first_handle, second_handle)
}

pub fn adjusted_insert(&self, responses: &mut VecDeque<Message>) -> PointId {
let layer = self.layer;
let [first, second] = self.bezier.split(TValue::Parametric(self.t));
Expand Down
13 changes: 3 additions & 10 deletions editor/src/messages/tool/common_functionality/snapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use {alignment_snapper::*, distribution_snapper::*, grid_snapper::*, layer_s
use crate::consts::{COLOR_OVERLAY_BLUE, COLOR_OVERLAY_SNAP_BACKGROUND, COLOR_OVERLAY_WHITE};
use crate::messages::portfolio::document::overlays::utility_types::{OverlayContext, Pivot};
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::portfolio::document::utility_types::misc::{BoundingBoxSnapTarget, GridSnapTarget, PathSnapTarget, SnapTarget};
use crate::messages::portfolio::document::utility_types::misc::{GridSnapTarget, PathSnapTarget, SnapTarget};
use crate::messages::prelude::*;

use bezier_rs::{Subpath, TValue};
Expand Down Expand Up @@ -135,14 +135,7 @@ fn get_closest_line(lines: &[SnappedLine]) -> Option<&SnappedPoint> {
fn get_closest_intersection(snap_to: DVec2, curves: &[SnappedCurve]) -> Option<SnappedPoint> {
let mut best = None;
for curve_i in curves {
if curve_i.point.target == SnapTarget::BoundingBox(BoundingBoxSnapTarget::AlongEdge) {
continue;
}

for curve_j in curves {
if curve_j.point.target == SnapTarget::BoundingBox(BoundingBoxSnapTarget::AlongEdge) {
continue;
}
if curve_i.start == curve_j.start && curve_i.layer == curve_j.layer {
continue;
}
Expand Down Expand Up @@ -468,10 +461,10 @@ impl SnapManager {
overlay_context.line(viewport, target, None);
}
for &target in align.iter().flatten() {
overlay_context.manipulator_handle(target, false);
overlay_context.manipulator_handle(target, false, None);
}
if any_align {
overlay_context.manipulator_handle(viewport, false);
overlay_context.manipulator_handle(viewport, false, None);
}

if !any_align && ind.distribution_equal_distance_x.is_none() && ind.distribution_equal_distance_y.is_none() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl AlignmentSnapper {
let document = snap_data.document;

self.bounding_box_points.clear();
if !document.snapping_state.bounding_box.align_with_corner_point {
if !document.snapping_state.bounding_box.align_with_edges {
return;
}

Expand Down Expand Up @@ -74,7 +74,9 @@ impl AlignmentSnapper {
Quad::intersect_rays(target_point.document_point, DVec2::X, origin, direction),
]
} else {
[DVec2::new(point.document_point.x, target_position.y), DVec2::new(target_position.x, point.document_point.y)].map(Some)
let Some(quad) = target_point.quad.map(|quad| quad.0) else { continue };
let edges = [quad[1] - quad[0], quad[3] - quad[0]];
edges.map(|edge| edge.try_normalize().map(|edge| (point.document_point - target_position).project_onto(edge) + target_position))
};

let target_path = matches!(target_point.target, SnapTarget::Path(_));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ impl LayerSnapper {
}
}
}
if !snap_data.ignore_bounds(layer) {
self.add_layer_bounds(document, layer, SnapTarget::BoundingBox(BoundingBoxSnapTarget::AlongEdge));
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions editor/src/messages/tool/tool_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
self.tool_is_active = true;

// Send the old and new tools a transition to their FSM Abort states
let mut send_abort_to_tool = |tool_type, update_hints_and_cursor: bool| {
if let Some(tool) = tool_data.tools.get_mut(&tool_type) {
let mut send_abort_to_tool = |old_tool: ToolType, new_tool: ToolType, update_hints_and_cursor: bool| {
if let Some(tool) = tool_data.tools.get_mut(&new_tool) {
let mut data = ToolActionHandlerData {
document,
document_id,
Expand All @@ -101,9 +101,14 @@ impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
tool.process_message(ToolMessage::UpdateCursor, responses, &mut data);
}
}

if matches!(old_tool, ToolType::Path | ToolType::Select) {
responses.add(TransformLayerMessage::CancelTransformOperation);
}
};
send_abort_to_tool(tool_type, true);
send_abort_to_tool(old_tool, false);

send_abort_to_tool(old_tool, tool_type, true);
send_abort_to_tool(old_tool, old_tool, false);

// Unsubscribe old tool from the broadcaster
tool_data.tools.get(&tool_type).unwrap().deactivate(responses);
Expand Down
6 changes: 3 additions & 3 deletions editor/src/messages/tool/tool_messages/gradient_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ impl Fsm for GradientToolFsmState {
let (start, end) = (transform.transform_point2(start), transform.transform_point2(end));

overlay_context.line(start, end, None);
overlay_context.manipulator_handle(start, dragging == Some(GradientDragTarget::Start));
overlay_context.manipulator_handle(end, dragging == Some(GradientDragTarget::End));
overlay_context.manipulator_handle(start, dragging == Some(GradientDragTarget::Start), None);
overlay_context.manipulator_handle(end, dragging == Some(GradientDragTarget::End), None);

for (index, (position, _)) in stops.0.into_iter().enumerate() {
if position.abs() < f64::EPSILON * 1000. || (1. - position).abs() < f64::EPSILON * 1000. {
continue;
}

overlay_context.manipulator_handle(start.lerp(end, position), dragging == Some(GradientDragTarget::Step(index)));
overlay_context.manipulator_handle(start.lerp(end, position), dragging == Some(GradientDragTarget::Step(index)), None);
}
}

Expand Down
Loading

0 comments on commit c7adf74

Please sign in to comment.