From fae31bdb659b4b14322136e045ea565d38bbd04f Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 29 Dec 2020 21:41:47 +0100 Subject: Dynamic width --- state.ml | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'state.ml') diff --git a/state.ml b/state.ml index 60796c8..e41c328 100755 --- a/state.ml +++ b/state.ml @@ -5,8 +5,7 @@ module Path_Builder = Paths.Path_Builder module SVGRepr = Path.WireFramePrinter.Make(Layer.Svg) module SVG_Fixed_Printer = Path_Builder.DrawFixed(SVGRepr) - -let expected_host = [%static_hash ""] +let expected_host = Blog.Hash_host.expected_host let backgroundColor = Blog.Nord.nord0 @@ -40,7 +39,7 @@ type events = ] (* - The state cannt hold functionnal values, and thus cannot be used to store + The state cant hold functionnal values, and thus cannot be used to store elements like timer *) type state = @@ -94,6 +93,20 @@ let check_selection end ) +(** Update the path in the selection with the given function applied to + every point *) +let update_selection s state f = + let s = Path_Builder.map_point s f + and id = Path_Builder.id s in + + let paths = List.map state.paths + ~f:(fun path -> + let id' = Path_Builder.id path in + match id = id' with + | false -> path + | true -> s + ) in + { state with mode = Selection s ; paths} let do_action : events -> state -> state @@ -205,12 +218,30 @@ let do_action ); state + (* Change the select curve with the appropriate setting *) + | `Angle angle, Selection s -> + let state = { state with angle } in + update_selection s state (fun p -> Path.Point.set_angle p angle) + | `Width width, Selection s -> + let state = { state with width } in + update_selection s state (fun p -> Path.Point.set_width p width) + | `Angle angle, _ -> { state with angle} | `Width width, _ -> { state with width} - | _ -> state + | `Delete, Out + -> state + + (* Some non possible cases *) + | `Out _, Out + | `Point _, Out + | `Point _, Selection _ + | `Out _, Selection _ + | `Click _, Edit + | `Delete, Edit + -> state let init = { paths = [] -- cgit v1.2.3