aboutsummaryrefslogtreecommitdiff
path: root/state.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2020-12-29 21:41:47 +0100
committerSébastien Dailly <sebastien@chimrod.com>2020-12-29 21:41:47 +0100
commitfae31bdb659b4b14322136e045ea565d38bbd04f (patch)
treeb08636d488b85e0532e84135f39da33f5e47af91 /state.ml
parent9d65e5e6a5bd8666baf0d7d3e0474c721cafc683 (diff)
Dynamic width
Diffstat (limited to 'state.ml')
-rwxr-xr-xstate.ml39
1 files changed, 35 insertions, 4 deletions
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 = []