From a63662059215a26db627c4b76147a3c9338f5b74 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 6 Jan 2021 22:09:53 +0100 Subject: Point suppression --- script.it/script.ml | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'script.it/script.ml') diff --git a/script.it/script.ml b/script.it/script.ml index 95272fb..e91dc92 100755 --- a/script.it/script.ml +++ b/script.it/script.ml @@ -144,7 +144,7 @@ let set_sidebar El.select [ El.option ~at:At.[value (Jstr.v "1")] [ txt' "Fill"] - ; El.option ~at:At.[value (Jstr.v "2")] + ; El.option ~at:At.[value (Jstr.v "3")] [ txt' "Ductus"] ] in @@ -212,7 +212,6 @@ let on_change canva mouse_position timer state = Cd2d.set_stroke_style context (Cd2d.color white); Cd2d.set_fill_style context (Cd2d.color white); - (* If we are in edit mode, we add a point under the cursor. Otherwise, we would only display the previous registered point, which can @@ -236,7 +235,8 @@ let on_change canva mouse_position timer state = ~f:(fun path -> let () = match state.mode with - | Selection id -> + | Selection (Path id) + | Selection (Point (id, _)) -> begin match id = (Path.Fixed.id path) with | true -> (* If the element is the selected one, change the color *) @@ -251,6 +251,42 @@ let on_change canva mouse_position timer state = Layer.Paths.to_canva (module Path.Fixed) path context state.rendering ); + + let () = match state.mode with + | Selection (Path id) -> + Cd2d.set_stroke_style context (Cd2d.color white); + List.iter + state.paths + ~f:(fun path -> + if id = Path.Fixed.id path then + Layer.Paths.to_canva (module Path.Fixed) path context `Line + ) + | Selection (Point (id, point)) -> + (* As before, mark the selected path *) + Cd2d.set_stroke_style context (Cd2d.color white); + List.iter + state.paths + ~f:(fun path -> + if id = Path.Fixed.id path then + Layer.Paths.to_canva (module Path.Fixed) path context `Line + ); + + (* Now draw the selected point *) + + let x, y = Gg.V2.to_tuple @@ Path.Point.get_coord point in + Cd2d.stroke_rect + ~x:(x -. 5.) + ~y:(y -. 5.) + ~w:10. + ~h:10. + context; + + + + | _ -> () + in + + () let spawn_worker () = -- cgit v1.2.3