diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-01-07 18:41:30 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2021-01-07 18:48:28 +0100 |
commit | 6e5c6bf7beadc72e64e5d929e301b473b01c9303 (patch) | |
tree | 02919ca31644a58d8b12e35c0072b38e8fab335a /script.it | |
parent | 21c386fee208adb7b494d2677d9f49ed49a1c1ce (diff) |
Update
Diffstat (limited to 'script.it')
-rwxr-xr-x | script.it/script.ml | 2 | ||||
-rwxr-xr-x | script.it/selection.ml | 4 | ||||
-rwxr-xr-x | script.it/state.ml | 31 |
3 files changed, 24 insertions, 13 deletions
diff --git a/script.it/script.ml b/script.it/script.ml index fc64d1e..ede47be 100755 --- a/script.it/script.ml +++ b/script.it/script.ml @@ -281,11 +281,13 @@ let on_change canva mouse_position timer state = ~h:10. context; +(* Cd2d.stroke_text context (Jstr.of_float @@ Path.Point.get_stamp point) ~x:(x +. 15.) ~y; +*) | _ -> () in diff --git a/script.it/selection.ml b/script.it/selection.ml index c0360fb..591ea38 100755 --- a/script.it/selection.ml +++ b/script.it/selection.ml @@ -15,8 +15,8 @@ let get_from_paths ~init:(threshold, None) ~f:(fun (dist, selection) path -> match Path.Fixed.distance point path with - | Some (point', p, p0, p1) when p < dist -> - dist, Some (point', path, p0, p1) + | Some { closest_point ; distance; p0; p1 ; ratio} when distance < dist -> + ratio, Some (closest_point, path, p0, p1) | _ -> dist, selection ) diff --git a/script.it/state.ml b/script.it/state.ml index 585ca32..185be4f 100755 --- a/script.it/state.ml +++ b/script.it/state.ml @@ -111,8 +111,8 @@ let select_segment _ (_, selected, p0, p1) state dist = let point' = Path.Point.mix dist (Path.Point.get_coord p0) p0 p1 in - let angle = Path.Point.get_angle point' - and width = Path.Point.get_width point' in + let angle = (Float.round @@ 10. *. Path.Point.get_angle point') /. 10. + and width = (Float.round @@ 10. *. Path.Point.get_width point') /. 10. in let id = Selection.select_path selected in { state with @@ -175,8 +175,9 @@ let angle angle state = {state with paths } (* Change angle localy *) | Selection (Point (s, point)) -> - update_point_selection state s point - (fun p -> Path.Point.set_angle p angle) + let state = update_point_selection state s point + (fun p -> Path.Point.set_angle p angle) in + { state with angle } | _ -> { state with angle} @@ -187,8 +188,9 @@ let width width state = let paths = update_path_selection s state.paths (fun p -> Path.Point.set_width p width) in {state with paths } | Selection (Point (s, point)) -> - update_point_selection state s point - (fun p -> Path.Point.set_width p width) + let state = update_point_selection state s point + (fun p -> Path.Point.set_width p width) in + { state with width } | _ -> { state with width } @@ -239,10 +241,17 @@ let do_action else (* On the same segment, check for a point *) let selection = Selection.select_point path (Gg.V2.of_tuple position) in - - (* In order to handle the point move, start the timer *) - Elements.Timer.start timer 0.3; - {state with mode= Selection selection} + match selection with + | Path _ -> + { state with mode = Selection selection } + | Point (_, pt) -> + (* In order to handle the point move, start the timer *) + Elements.Timer.start timer 0.3; + { state with + mode = Selection selection + ; angle = Path.Point.get_angle pt + ; width = Path.Point.get_width pt + } end | `Out point, Edit -> @@ -344,7 +353,7 @@ let do_action match id = id' with | false -> path | true -> - Path.Fixed.update path paths + (Path.Fixed.update path paths) ) in { state with paths } |