From 32618a5ce8e2b306af102e4c16711b090c36b840 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 7 Jan 2021 21:54:46 +0100 Subject: Allow point movement --- script.it/state.ml | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'script.it/state.ml') diff --git a/script.it/state.ml b/script.it/state.ml index 185be4f..da97b13 100755 --- a/script.it/state.ml +++ b/script.it/state.ml @@ -25,7 +25,7 @@ type render_event = type worker_event = [ `Basic of Jv.t - | `Complete of (int * (Path.Fixed.path array)) + | `Complete of Path.Fixed.t ] type events = @@ -74,18 +74,15 @@ let insert_or_replace state ((x, y) as p) stamp path = path ) -let threshold = 20. - (** Update the path in the selection with the given function applied to every point *) let update_path_selection id paths f = - List.map paths ~f:(fun path -> let id' = Path.Fixed.id path in match id = id' with | false -> path - | true -> Path.Fixed.map_point path f + | true -> Path.Fixed.map path f ) let update_point_selection state path_id point f = @@ -94,7 +91,7 @@ let update_point_selection state path_id point f = match Path.Fixed.id p = path_id with | false -> p | true -> - Path.Fixed.map_point + Path.Fixed.map p (fun p -> if (Path.Point.id p = Path.Point.id point) then @@ -143,7 +140,7 @@ let delete state worker = | false -> () | true -> (* Send the job to the worker *) - Brr_webworkers.Worker.post worker (`DeletePoint (id, point, p)) + Brr_webworkers.Worker.post worker (`DeletePoint (point, p)) ); { state with mode = Selection (Path id) } | _ -> @@ -269,13 +266,10 @@ let do_action current in - let id = Path.Fixed.id last - and path = Path.Fixed.path last in - let () = Brr_webworkers.Worker.post worker (`Complete (id, path)) in + let () = Brr_webworkers.Worker.post worker (`Complete last) in last::state.paths and current = Path.Path_Builder.empty in - { state with mode = Out ; paths; current } @@ -294,6 +288,25 @@ let do_action end end + + | `Out mouse_coord, Selection (Point (id, point)) -> + let mouse_v2 = Gg.V2.of_tuple mouse_coord in + if Elements.Timer.delay timer < 0.3 then + state + else + let point' = Path.Point.copy point mouse_v2 in + List.iter state.paths + ~f:(fun path -> + let id' = Path.Fixed.id path in + match id = id' with + | false -> () + | true -> + Option.iter + (fun p -> Brr_webworkers.Worker.post worker (`Complete p)) + (Path.Fixed.replace_point path point') + ); + + { state with mode = Selection (Path id) } | `Delete, _ -> delete state worker @@ -346,14 +359,15 @@ let do_action Console.(log [t]); state - | `Complete (id, paths), _ -> + | `Complete path, _ -> + let id = Path.Fixed.id path in let paths = List.map state.paths - ~f:(fun path -> - let id' = Path.Fixed.id path in + ~f:(fun path' -> + let id' = Path.Fixed.id path' in match id = id' with - | false -> path + | false -> path' | true -> - (Path.Fixed.update path paths) + path ) in { state with paths } -- cgit v1.2.3