diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-05-25 11:08:00 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:22:43 +0100 |
commit | 6a75fb043ed30389fff1ce97fe20ee56b1c95066 (patch) | |
tree | 20e0c2cb39dffcf85449e0b810d773909c405a0e /script.it/script_event/property.ml | |
parent | 90f1f73f08b2d9231b2ee029b9e39dd570e36f36 (diff) |
Update script.it project
Diffstat (limited to 'script.it/script_event/property.ml')
-rwxr-xr-x | script.it/script_event/property.ml | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/script.it/script_event/property.ml b/script.it/script_event/property.ml new file mode 100755 index 0000000..e637ab7 --- /dev/null +++ b/script.it/script_event/property.ml @@ -0,0 +1,52 @@ +module State = Script_state.State +module Selection = Script_state.Selection + +let update_property worker state value f = function + | None -> state + | Some (Selection.Path outline) -> + (* Change width for the whole path *) + let outline = { outline with + Outline.path = Path.Fixed.map outline.Outline.path (fun p -> + f p value) + } in + State.post worker (`Back outline); + state + | Some (Point (outline, point)) -> + let path = Path.Fixed.map + outline.path + (fun pt -> + match Path.Point.id pt = Path.Point.id point with + | false -> pt + | true -> f pt value) + in + let outline = {outline with path} in + State.post worker (`Back outline); + state + +type t = { prop : [`Angle | `Width ] + ; value : float + ; worker : Brr_webworkers.Worker.t + } + +let update { prop; value ; worker } state = + match prop with + | `Angle -> + let angle = value in + begin match state.State.mode with + + | Selection t -> + let state = { state with angle } in + Selection.find_selection t state.paths + |> update_property worker state angle Path.Point.set_angle + | _ -> { state with angle } + end + | `Width -> + let width = value in + begin match state.State.mode with + + | Selection t -> + let state = { state with width } in + Selection.find_selection t state.paths + |> update_property worker state width Path.Point.set_width + | _ -> { state with width } + end |