Skip to content

Commit da290f1

Browse files
TrueDoctorKeavon
authored andcommitted
Transform API (#301)
* Enforce cache dirtification * Turn all shapes into one struct * Remove working folder * Remove old shapes * Major restructuring * Refactor Ellipse, Rectangle and ShapeTool * Simplify bounding box calculation for folder * Fix panic in select tool * Refactorselect tool * Refactor Align * Refactor flipping layers * Zoom to fit all * Refactor tools to avoid state keeping * Refactor more tools to use state that is passed along * Fix whitespace + change selection box style * Set viewbox of svg export based on the contents
1 parent a9364f5 commit da290f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2038
-2230
lines changed

Cargo.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/web/src/components/panels/LayerTree.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
<script lang="ts">
118118
import { defineComponent } from "vue";
119119
120-
import { ResponseType, registerResponseHandler, Response, BlendMode, ExpandFolder, LayerPanelEntry } from "@/utilities/response-handler";
120+
import { ResponseType, registerResponseHandler, Response, BlendMode, ExpandFolder, UpdateLayer, LayerPanelEntry } from "@/utilities/response-handler";
121121
import { SeparatorType } from "@/components/widgets/widgets";
122122
123123
import LayoutRow from "@/components/layout/LayoutRow.vue";
@@ -324,6 +324,22 @@ export default defineComponent({
324324
registerResponseHandler(ResponseType.CollapseFolder, (responseData) => {
325325
console.log("CollapseFolder: ", responseData);
326326
});
327+
registerResponseHandler(ResponseType.UpdateLayer, (responseData) => {
328+
const updateData = responseData as UpdateLayer;
329+
if (updateData) {
330+
const responsePath = updateData.path;
331+
const responseLayer = updateData.data;
332+
333+
const index = this.layers.findIndex((layer: LayerPanelEntry) => {
334+
const pathLengthsEqual = responsePath.length === layer.path.length;
335+
return pathLengthsEqual && responsePath.every((layer_id, i) => layer_id === layer.path[i]);
336+
});
337+
if (index >= 0) this.layers[index] = responseLayer;
338+
339+
this.setBlendModeForSelectedLayers();
340+
this.setOpacityForSelectedLayers();
341+
}
342+
});
327343
},
328344
data() {
329345
return {

client/web/src/utilities/response-handler.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export enum ResponseType {
2020
SetActiveDocument = "SetActiveDocument",
2121
UpdateOpenDocumentsList = "UpdateOpenDocumentsList",
2222
UpdateWorkingColors = "UpdateWorkingColors",
23+
UpdateLayer = "UpdateLayer",
2324
SetCanvasZoom = "SetCanvasZoom",
2425
SetCanvasRotation = "SetCanvasRotation",
2526
DisplayConfirmationToCloseDocument = "DisplayConfirmationToCloseDocument",
@@ -61,6 +62,8 @@ function parseResponse(responseType: string, data: any): Response {
6162
return newUpdateOpenDocumentsList(data.UpdateOpenDocumentsList);
6263
case "UpdateCanvas":
6364
return newUpdateCanvas(data.UpdateCanvas);
65+
case "UpdateLayer":
66+
return newUpdateLayer(data.UpdateLayer);
6467
case "SetCanvasZoom":
6568
return newSetCanvasZoom(data.SetCanvasZoom);
6669
case "SetCanvasRotation":
@@ -168,7 +171,18 @@ export interface CollapseFolder {
168171
}
169172
function newCollapseFolder(input: any): CollapseFolder {
170173
return {
171-
path: new BigUint64Array(input.path.map((n: number) => BigInt(n))),
174+
path: newPath(input.path),
175+
};
176+
}
177+
178+
export interface UpdateLayer {
179+
path: BigUint64Array;
180+
data: LayerPanelEntry;
181+
}
182+
function newUpdateLayer(input: any): UpdateLayer {
183+
return {
184+
path: newPath(input.data.path),
185+
data: newLayerPanelEntry(input.data),
172186
};
173187
}
174188

@@ -178,7 +192,7 @@ export interface ExpandFolder {
178192
}
179193
function newExpandFolder(input: any): ExpandFolder {
180194
return {
181-
path: new BigUint64Array(input.path.map((n: number) => BigInt(n))),
195+
path: newPath(input.path),
182196
children: input.children.map((child: any) => newLayerPanelEntry(child)),
183197
};
184198
}
@@ -201,6 +215,12 @@ function newSetCanvasRotation(input: any): SetCanvasRotation {
201215
};
202216
}
203217

218+
function newPath(input: any): BigUint64Array {
219+
// eslint-disable-next-line
220+
const u32CombinedPairs = input.map((n: Array<bigint>) => BigInt((BigInt(n[0]) << BigInt(32)) | BigInt(n[1])));
221+
return new BigUint64Array(u32CombinedPairs);
222+
}
223+
204224
export enum BlendMode {
205225
Normal = "normal",
206226
Multiply = "multiply",
@@ -266,7 +286,7 @@ function newLayerPanelEntry(input: any): LayerPanelEntry {
266286
opacity: newOpacity(input.opacity),
267287
layer_type: newLayerType(input.layer_type),
268288
layer_data: newLayerData(input.layer_data),
269-
path: new BigUint64Array(input.path.map((n: number) => BigInt(n))),
289+
path: newPath(input.path),
270290
thumbnail: input.thumbnail,
271291
};
272292
}

client/web/wasm/src/document.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use editor_core::input::mouse::ScrollDelta;
77
use editor_core::message_prelude::*;
88
use editor_core::misc::EditorError;
99
use editor_core::tool::{tool_options::ToolOptions, tools, ToolType};
10-
use editor_core::{
11-
input::mouse::{MouseState, ViewportPosition},
12-
LayerId,
13-
};
10+
use editor_core::{input::mouse::MouseState, LayerId};
1411
use wasm_bindgen::prelude::*;
1512

1613
fn convert_error(err: editor_core::EditorError) -> JsValue {
@@ -59,44 +56,44 @@ pub fn send_tool_message(tool: String, message: &JsValue) -> Result<(), JsValue>
5956

6057
#[wasm_bindgen]
6158
pub fn select_document(document: usize) -> Result<(), JsValue> {
62-
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SelectDocument(document)).map_err(convert_error))
59+
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentsMessage::SelectDocument(document)).map_err(convert_error))
6360
}
6461

6562
#[wasm_bindgen]
6663
pub fn get_open_documents_list() -> Result<(), JsValue> {
67-
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::GetOpenDocumentsList).map_err(convert_error))
64+
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentsMessage::GetOpenDocumentsList).map_err(convert_error))
6865
}
6966

7067
#[wasm_bindgen]
7168
pub fn new_document() -> Result<(), JsValue> {
72-
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::NewDocument).map_err(convert_error))
69+
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentsMessage::NewDocument).map_err(convert_error))
7370
}
7471

7572
#[wasm_bindgen]
7673
pub fn close_document(document: usize) -> Result<(), JsValue> {
77-
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::CloseDocument(document)).map_err(convert_error))
74+
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentsMessage::CloseDocument(document)).map_err(convert_error))
7875
}
7976

8077
#[wasm_bindgen]
8178
pub fn close_all_documents() -> Result<(), JsValue> {
82-
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::CloseAllDocuments).map_err(convert_error))
79+
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentsMessage::CloseAllDocuments).map_err(convert_error))
8380
}
8481

8582
#[wasm_bindgen]
8683
pub fn close_active_document_with_confirmation() -> Result<(), JsValue> {
87-
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::CloseActiveDocumentWithConfirmation).map_err(convert_error))
84+
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentsMessage::CloseActiveDocumentWithConfirmation).map_err(convert_error))
8885
}
8986

9087
#[wasm_bindgen]
9188
pub fn close_all_documents_with_confirmation() -> Result<(), JsValue> {
92-
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::CloseAllDocumentsWithConfirmation).map_err(convert_error))
89+
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentsMessage::CloseAllDocumentsWithConfirmation).map_err(convert_error))
9390
}
9491

9592
// TODO: Call event when the panels are resized
9693
/// Viewport resized
9794
#[wasm_bindgen]
9895
pub fn viewport_resize(new_width: u32, new_height: u32) -> Result<(), JsValue> {
99-
let ev = InputPreprocessorMessage::ViewportResize(ViewportPosition { x: new_width, y: new_height });
96+
let ev = InputPreprocessorMessage::ViewportResize((new_width, new_height).into());
10097
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(ev)).map_err(convert_error)
10198
}
10299

@@ -106,7 +103,7 @@ pub fn viewport_resize(new_width: u32, new_height: u32) -> Result<(), JsValue> {
106103
pub fn on_mouse_move(x: u32, y: u32, modifiers: u8) -> Result<(), JsValue> {
107104
let mods = ModifierKeys::from_bits(modifiers).expect("invalid modifier keys");
108105
// TODO: Convert these screenspace viewport coordinates to canvas coordinates based on the current zoom and pan
109-
let ev = InputPreprocessorMessage::MouseMove(ViewportPosition { x, y }, mods);
106+
let ev = InputPreprocessorMessage::MouseMove((x, y).into(), mods);
110107
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(ev)).map_err(convert_error)
111108
}
112109

@@ -122,18 +119,16 @@ pub fn on_mouse_scroll(delta_x: i32, delta_y: i32, delta_z: i32, modifiers: u8)
122119
/// A mouse button depressed within screenspace the bounds of the viewport
123120
#[wasm_bindgen]
124121
pub fn on_mouse_down(x: u32, y: u32, mouse_keys: u8, modifiers: u8) -> Result<(), JsValue> {
125-
let pos = ViewportPosition { x, y };
126122
let mods = ModifierKeys::from_bits(modifiers).expect("invalid modifier keys");
127-
let ev = InputPreprocessorMessage::MouseDown(MouseState::from_u8_pos(mouse_keys, pos), mods);
123+
let ev = InputPreprocessorMessage::MouseDown(MouseState::from_u8_pos(mouse_keys, (x, y).into()), mods);
128124
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(ev)).map_err(convert_error)
129125
}
130126

131127
/// A mouse button released
132128
#[wasm_bindgen]
133129
pub fn on_mouse_up(x: u32, y: u32, mouse_keys: u8, modifiers: u8) -> Result<(), JsValue> {
134-
let pos = ViewportPosition { x, y };
135130
let mods = ModifierKeys::from_bits(modifiers).expect("invalid modifier keys");
136-
let ev = InputPreprocessorMessage::MouseUp(MouseState::from_u8_pos(mouse_keys, pos), mods);
131+
let ev = InputPreprocessorMessage::MouseUp(MouseState::from_u8_pos(mouse_keys, (x, y).into()), mods);
137132
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(ev)).map_err(convert_error)
138133
}
139134

@@ -259,14 +254,14 @@ pub fn export_document() -> Result<(), JsValue> {
259254
/// Sets the zoom to the value
260255
#[wasm_bindgen]
261256
pub fn set_zoom(new_zoom: f64) -> Result<(), JsValue> {
262-
let ev = DocumentMessage::SetCanvasZoom(new_zoom);
257+
let ev = MovementMessage::SetCanvasZoom(new_zoom);
263258
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(ev)).map_err(convert_error)
264259
}
265260

266261
/// Sets the rotation to the new value (in radians)
267262
#[wasm_bindgen]
268263
pub fn set_rotation(new_radians: f64) -> Result<(), JsValue> {
269-
let ev = DocumentMessage::SetCanvasRotation(new_radians);
264+
let ev = MovementMessage::SetCanvasRotation(new_radians);
270265
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(ev)).map_err(convert_error)
271266
}
272267

core/document/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ license = "Apache-2.0"
1111
[dependencies]
1212
log = "0.4"
1313

14-
kurbo = {version="0.8", features = ["serde"]}
14+
kurbo = {git="https://github.com/linebender/kurbo", features = ["serde"]}
1515
serde = { version = "1.0", features = ["derive"] }
16-
glam = { version = "0.16", features = ["serde"] }
16+
glam = { version = "0.17", features = ["serde"] }

0 commit comments

Comments
 (0)