mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 19:08:05 +08:00
* #82 path-tool: WIP selecting control point working * Fix bug where duplication with Ctrl+D doesn't properly duplicate (#423) * bug fix: duplication didn't properly duplicate * cargo fmt * changed the formatting slightly for readability * Small cleanups, changed color of handles upon selection * Fix changes from merge * Remove duplicate anchor points on top of one another * Fix possible issues with thumbnails not being updated from Graphene operations * path-tool: attempt to move control points on click * Add dragging for control points * Editing shape anchors functional. Handles next. * Comment cleanup & slight cleanup of closest_anchor(..) * Removing conflict with master * Tiny code tweaks Co-authored-by: Keavon Chambers <keavon@keavon.com> Co-authored-by: caleb <56044292+caleb-ad@users.noreply.github.com> Co-authored-by: otdavies <oliver@psyfer.io> Co-authored-by: Dennis <dennis@kobert.dev>
168 lines
3.2 KiB
Rust
168 lines
3.2 KiB
Rust
use std::{
|
|
collections::hash_map::DefaultHasher,
|
|
hash::{Hash, Hasher},
|
|
};
|
|
|
|
use crate::{
|
|
color::Color,
|
|
layers::{style, BlendMode, Layer},
|
|
LayerId,
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[repr(C)]
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
|
pub enum Operation {
|
|
AddEllipse {
|
|
path: Vec<LayerId>,
|
|
insert_index: isize,
|
|
transform: [f64; 6],
|
|
style: style::PathStyle,
|
|
},
|
|
AddOverlayEllipse {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
style: style::PathStyle,
|
|
},
|
|
AddRect {
|
|
path: Vec<LayerId>,
|
|
insert_index: isize,
|
|
transform: [f64; 6],
|
|
style: style::PathStyle,
|
|
},
|
|
AddOverlayRect {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
style: style::PathStyle,
|
|
},
|
|
AddLine {
|
|
path: Vec<LayerId>,
|
|
insert_index: isize,
|
|
transform: [f64; 6],
|
|
style: style::PathStyle,
|
|
},
|
|
AddOverlayLine {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
style: style::PathStyle,
|
|
},
|
|
AddPen {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
insert_index: isize,
|
|
points: Vec<(f64, f64)>,
|
|
style: style::PathStyle,
|
|
},
|
|
AddNgon {
|
|
path: Vec<LayerId>,
|
|
insert_index: isize,
|
|
transform: [f64; 6],
|
|
sides: u8,
|
|
style: style::PathStyle,
|
|
},
|
|
AddOverlayShape {
|
|
path: Vec<LayerId>,
|
|
bez_path: kurbo::BezPath,
|
|
style: style::PathStyle,
|
|
closed: bool,
|
|
},
|
|
DeleteLayer {
|
|
path: Vec<LayerId>,
|
|
},
|
|
DuplicateLayer {
|
|
path: Vec<LayerId>,
|
|
},
|
|
RenameLayer {
|
|
path: Vec<LayerId>,
|
|
name: String,
|
|
},
|
|
InsertLayer {
|
|
layer: Layer,
|
|
destination_path: Vec<LayerId>,
|
|
insert_index: isize,
|
|
},
|
|
CreateFolder {
|
|
path: Vec<LayerId>,
|
|
},
|
|
TransformLayer {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
},
|
|
TransformLayerInViewport {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
},
|
|
SetLayerTransformInViewport {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
},
|
|
SetShapePath {
|
|
path: Vec<LayerId>,
|
|
bez_path: kurbo::BezPath,
|
|
},
|
|
SetShapePathInViewport {
|
|
path: Vec<LayerId>,
|
|
bez_path: kurbo::BezPath,
|
|
transform: [f64; 6],
|
|
},
|
|
TransformLayerInScope {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
scope: [f64; 6],
|
|
},
|
|
SetLayerTransformInScope {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
scope: [f64; 6],
|
|
},
|
|
SetLayerTransform {
|
|
path: Vec<LayerId>,
|
|
transform: [f64; 6],
|
|
},
|
|
ToggleLayerVisibility {
|
|
path: Vec<LayerId>,
|
|
},
|
|
SetLayerVisibility {
|
|
path: Vec<LayerId>,
|
|
visible: bool,
|
|
},
|
|
SetLayerBlendMode {
|
|
path: Vec<LayerId>,
|
|
blend_mode: BlendMode,
|
|
},
|
|
SetLayerOpacity {
|
|
path: Vec<LayerId>,
|
|
opacity: f64,
|
|
},
|
|
SetLayerStyle {
|
|
path: Vec<LayerId>,
|
|
style: style::PathStyle,
|
|
},
|
|
SetLayerFill {
|
|
path: Vec<LayerId>,
|
|
color: Color,
|
|
},
|
|
}
|
|
|
|
impl Operation {
|
|
/// Returns the byte representation of the message.
|
|
///
|
|
/// # Safety
|
|
/// This function reads from uninitialized memory!!!
|
|
/// Only use if you know what you are doing
|
|
unsafe fn as_slice(&self) -> &[u8] {
|
|
core::slice::from_raw_parts(self as *const Operation as *const u8, std::mem::size_of::<Operation>())
|
|
}
|
|
/// Returns a pseudo hash that should uniquely identify the operation.
|
|
/// This is needed because `Hash` is not implemented for f64s
|
|
///
|
|
/// # Safety
|
|
/// This function reads from uninitialized memory but the generated value should be fine.
|
|
pub fn pseudo_hash(&self) -> u64 {
|
|
let mut s = DefaultHasher::new();
|
|
unsafe { self.as_slice() }.hash(&mut s);
|
|
s.finish()
|
|
}
|
|
}
|