aboutsummaryrefslogtreecommitdiff
path: root/state.ml
diff options
context:
space:
mode:
Diffstat (limited to 'state.ml')
-rwxr-xr-xstate.ml42
1 files changed, 21 insertions, 21 deletions
diff --git a/state.ml b/state.ml
index 57007b3..52fe5a6 100755
--- a/state.ml
+++ b/state.ml
@@ -12,7 +12,7 @@ type mode =
| Selection of int
| Out
-type current = Paths.Path_Builder.t
+type current = Path.Path_Builder.t
(** Events *)
@@ -40,7 +40,7 @@ type events =
*)
type state =
{ mode : mode
- ; paths : Paths.Fixed.t list
+ ; paths : Path.Fixed.t list
; current : current
; width : float
; angle : float
@@ -50,9 +50,9 @@ let insert_or_replace state ((x, y) as p) path =
let width = state.width
and angle = state.angle in
let point = Path.Point.create ~x ~y ~angle ~width in
- match Paths.Path_Builder.peek path with
+ match Path.Path_Builder.peek path with
| None ->
- Paths.Path_Builder.add_point
+ Path.Path_Builder.add_point
point
path
| Some p1 ->
@@ -64,7 +64,7 @@ let insert_or_replace state ((x, y) as p) path =
if dist < 5. then (
path
) else (
- Paths.Path_Builder.add_point
+ Path.Path_Builder.add_point
point
path
)
@@ -72,14 +72,14 @@ let insert_or_replace state ((x, y) as p) path =
let threshold = 20.
let check_selection
- : (float * float) -> Paths.Fixed.t list -> (Gg.v2 * Paths.Fixed.t) option
+ : (float * float) -> Path.Fixed.t list -> (Gg.v2 * Path.Fixed.t) option
= fun position paths ->
let point = Gg.V2.of_tuple position in
(* If the user click on a curve, select it *)
let _, res = List.fold_left paths
~init:(threshold, None)
~f:(fun (dist, selection) path ->
- match Paths.Fixed.distance point path with
+ match Path.Fixed.distance point path with
| Some (point', p) when p < dist ->
dist, Some (point', path)
| _ -> dist, selection
@@ -92,10 +92,10 @@ let update_selection id state f =
let paths = List.map state.paths
~f:(fun path ->
- let id' = Paths.Fixed.id path in
+ let id' = Path.Fixed.id path in
match id = id' with
| false -> path
- | true -> Paths.Fixed.map_point path f
+ | true -> Path.Fixed.map_point path f
) in
{ state with paths}
@@ -130,7 +130,7 @@ let do_action
Path.Point.create ~x ~y ~angle ~width
in
- let current = Paths.Path_Builder.add_point
+ let current = Path.Path_Builder.add_point
point
state.current in
{ state with current; mode = Edit }
@@ -146,7 +146,7 @@ let do_action
(* Start the timer in order to handle the mouse moves *)
- let id = Paths.Fixed.id selected in
+ let id = Path.Fixed.id selected in
Elements.Timer.start timer 0.3;
{ state with
mode = (Selection id)}
@@ -154,7 +154,7 @@ let do_action
| `Out point, Edit ->
Elements.Timer.stop timer;
- begin match Paths.Path_Builder.peek2 state.current with
+ begin match Path.Path_Builder.peek2 state.current with
(* If there is at last two points selected, handle this as a curve
creation. And we add the new point in the current path *)
| Some _ ->
@@ -167,19 +167,19 @@ let do_action
let current = insert_or_replace state point state.current in
let paths =
- let last = Paths.Fixed.to_fixed
- (module Paths.Path_Builder)
+ let last = Path.Fixed.to_fixed
+ (module Path.Path_Builder)
current
in
last::state.paths
- and current = Paths.Path_Builder.empty in
+ and current = Path.Path_Builder.empty in
{ state with
mode = Out
; paths; current }
(* Else, check if there is a curve undre the cursor, and remove it *)
| None ->
- let current = Paths.Path_Builder.empty in
+ let current = Path.Path_Builder.empty in
begin match check_selection point state.paths with
| None ->
{ state with
@@ -187,14 +187,14 @@ let do_action
; current
}
| Some (_, selected) ->
- let id = Paths.Fixed.id selected in
+ let id = Path.Fixed.id selected in
{ state with
mode = (Selection id)
; current }
end
end
| `Delete, Selection id ->
- let paths = List.filter state.paths ~f:(fun p -> Paths.Fixed.id p != id) in
+ let paths = List.filter state.paths ~f:(fun p -> Path.Fixed.id p != id) in
{ state with paths ; mode = Out}
@@ -211,9 +211,9 @@ let do_action
(List.map state.paths
~f:(fun path ->
- Paths.to_svg
+ Path.to_svg
~color:backgroundColor
- (module Paths.Fixed)
+ (module Path.Fixed)
path
`Fill
@@ -262,7 +262,7 @@ let do_action
let init =
{ paths = []
- ; current = Paths.Path_Builder.empty
+ ; current = Path.Path_Builder.empty
; mode = Out
; angle = 30.
; width = 10.