aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscript.it/dune10
-rwxr-xr-xscript.it/outline/dune2
-rwxr-xr-xscript.it/script.ml79
-rwxr-xr-xscript.it/script_event/dune8
-rwxr-xr-xscript.it/script_event/out.ml69
5 files changed, 83 insertions, 85 deletions
diff --git a/script.it/dune b/script.it/dune
index dd1f7d2..2b1d446 100755
--- a/script.it/dune
+++ b/script.it/dune
@@ -1,16 +1,8 @@
(executable
(name script)
(libraries
- brr
- brr.note
script_state
- shapes
- elements
- blog
- application
- layer
- worker_messages
- outline
+ script_event
)
(modes js)
(modules script)
diff --git a/script.it/outline/dune b/script.it/outline/dune
index db080a3..73b7998 100755
--- a/script.it/outline/dune
+++ b/script.it/outline/dune
@@ -5,5 +5,3 @@
(modules outline)
(preprocess (pps ppx_hash js_of_ocaml-ppx))
)
-
-
diff --git a/script.it/script.ml b/script.it/script.ml
index bc79a22..200d118 100755
--- a/script.it/script.ml
+++ b/script.it/script.ml
@@ -6,73 +6,6 @@ open Brr_note
module State = Script_state.State
module Selection = Script_state.Selection
-module Out = struct
- type t = { point : float * float
- ; timer : Elements.Timer.t
- ; worker : Brr_webworkers.Worker.t
- }
-
- let apply {point; timer ; worker} state =
- match state.State.mode with
-
- | Edit ->
- let stamp = Elements.Timer.delay timer in
- Elements.Timer.stop timer;
- 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 _ ->
-
- let current = State.insert_or_replace state point stamp state.current in
- let path = Path.Fixed.to_fixed
- (module Path.Path_Builder)
- current in
-
- (* Create a copy from the path with all the interior points *)
- let back = Path.Fixed.map
- path
- (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
-
- let last =
- Outline.{ path
- ; back
- ; id = Outline.get_id ()
- }
- in
-
- (* Send to the worker for a full review *)
- let () = State.post worker (`Complete last) in
-
- let state =
- { state with
- mode = Out
- ; paths = last::state.paths
- ; current = Path.Path_Builder.empty } in
- state
-
- (* Else, check if there is a curve under the cursor, and remove it *)
- | None ->
- let current = Path.Path_Builder.empty in
- begin match Selection.get_from_paths point state.paths with
- | _, None ->
- { state with
- mode = Out
- ; current
- }
- | dist, Some selection ->
- State.select_segment point selection { state with current } dist
-
- end
- end
-
- | mode when Elements.Timer.delay timer < 0.3 ->
- State.click state mode
-
- | _ ->
- State.longClick point state worker state.mode
-
-end
-
let post
: Brr_webworkers.Worker.t -> Worker_messages.to_worker -> unit
= Brr_webworkers.Worker.post
@@ -466,13 +399,11 @@ let page_main id =
`Generic (
State.E
- ( Out.{ point = c
- ; worker
- ; timer
- }
- , (module Out: State.Handler with type t = Out.t)
-
-
+ ( Script_event.Out.{ point = c
+ ; worker
+ ; timer
+ }
+ , (module Script_event.Out: State.Handler with type t = Script_event.Out.t)
)
)
diff --git a/script.it/script_event/dune b/script.it/script_event/dune
new file mode 100755
index 0000000..2271b0a
--- /dev/null
+++ b/script.it/script_event/dune
@@ -0,0 +1,8 @@
+(library
+ (name script_event)
+ (libraries
+ brr
+ script_state
+ )
+ )
+
diff --git a/script.it/script_event/out.ml b/script.it/script_event/out.ml
new file mode 100755
index 0000000..45f05d3
--- /dev/null
+++ b/script.it/script_event/out.ml
@@ -0,0 +1,69 @@
+module State = Script_state.State
+module Selection = Script_state.Selection
+
+(** Handle a click outside of the selection *)
+
+type t = { point : float * float
+ ; timer : Elements.Timer.t
+ ; worker : Brr_webworkers.Worker.t
+ }
+
+let apply {point; timer ; worker} state =
+ match state.State.mode with
+
+ | Edit ->
+ let stamp = Elements.Timer.delay timer in
+ Elements.Timer.stop timer;
+ 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 _ ->
+
+ let current = State.insert_or_replace state point stamp state.current in
+ let path = Path.Fixed.to_fixed
+ (module Path.Path_Builder)
+ current in
+
+ (* Create a copy from the path with all the interior points *)
+ let back = Path.Fixed.map
+ path
+ (fun pt -> Path.Point.copy pt @@ Path.Point.get_coord' pt) in
+
+ let last =
+ Outline.{ path
+ ; back
+ ; id = Outline.get_id ()
+ }
+ in
+
+ (* Send to the worker for a full review *)
+ let () = State.post worker (`Complete last) in
+
+ let state =
+ { state with
+ mode = Out
+ ; paths = last::state.paths
+ ; current = Path.Path_Builder.empty } in
+ state
+
+ (* Else, check if there is a curve under the cursor, and remove it *)
+ | None ->
+ let current = Path.Path_Builder.empty in
+ begin match Selection.get_from_paths point state.paths with
+ | _, None ->
+ { state with
+ mode = Out
+ ; current
+ }
+ | dist, Some selection ->
+ State.select_segment point selection { state with current } dist
+
+ end
+ end
+
+ | mode when Elements.Timer.delay timer < 0.3 ->
+ State.click state mode
+
+ | _ ->
+ State.longClick point state worker state.mode
+