From e25b7797708c19cbaef68c14ebef8738de44c2d9 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 30 Dec 2020 11:41:01 +0100 Subject: Refactor --- script.ml | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'script.ml') diff --git a/script.ml b/script.ml index a250c7f..d7d969c 100755 --- a/script.ml +++ b/script.ml @@ -3,12 +3,9 @@ open Note open Brr open Brr_note -module CanvaRepr = Path.FillPrinter.Make(Layer.CanvaPrinter) -module Path_Printer = Paths.Path_Builder.Draw(CanvaRepr) -module Fixed_Printer = Paths.Path_Builder.DrawFixed(CanvaRepr) - -type canva_signal = Path.Point.t +module Path_Printer = Paths.Path_Builder.Draw(Paths.CanvaRepr) +module Fixed_Printer = Paths.Fixed.DrawFixed(Paths.CanvaRepr) module Mouse = Brr_note_kit.Mouse @@ -195,32 +192,29 @@ let on_change canva mouse_position state = *) let pos = S.rough_value mouse_position in - let current, paths = + let current = begin match state.State.mode, pos with | Edit, Some point -> - begin match State.insert_or_replace state point state.current with - | current, None -> current, state.paths - | current, Some p -> current, p::state.paths - end + State.insert_or_replace state point state.current | _ -> - state.current, state.paths + state.current end in - let path = CanvaRepr.get + let path = Paths.CanvaRepr.get @@ Path_Printer.draw current - (* (CanvaRepr.create_path (fun p -> fill context p)) in *) - (CanvaRepr.create_path (fun _ -> () )) in + (Paths.CanvaRepr.create_path (fun p -> fill context p)) in stroke context path; - List.iter paths + List.iter state.paths ~f:(fun path -> let () = match state.mode with | Selection s -> - begin match (Paths.Path_Builder.id s) = (Paths.Path_Builder.id path) with + begin match (Paths.Fixed.id s) = (Paths.Fixed.id path) with | true -> + (* If the element is the selected one, change the color *) set_fill_style context (color Blog.Nord.nord8); set_stroke_style context (color Blog.Nord.nord8) | false -> @@ -230,10 +224,10 @@ let on_change canva mouse_position state = | _ -> () in - let path = CanvaRepr.get + let path = Paths.CanvaRepr.get @@ Fixed_Printer.draw path - (CanvaRepr.create_path (fun p -> fill context p)) in + (Paths.CanvaRepr.create_path (fun p -> fill context p)) in stroke context path; ); () @@ -241,7 +235,6 @@ let on_change canva mouse_position state = let page_main id = - let delete_event', angle_signal', width_signal', export_event' = begin match Blog.Sidebar.get () with | None -> -- cgit v1.2.3