9 Commits

Author SHA1 Message Date
cqc
9d1ccb93b5 little re-arranging 2022-11-17 20:16:15 -06:00
cqc
3fc8125d42 lol browser requests github repo via cors proxy (via npm, run with ./cors_proxy.sh) but then stack overflows 2022-11-08 22:06:58 -06:00
cqc
3b09bb1c11 works 2022-10-06 14:29:57 -05:00
cqc
281351371d Irmin_git.KV (Irmin_git.Mem) (Git.Mem.Sync (Irmin_git.Mem)) results in a.caml_thread_initialize is not a function 2022-10-06 12:18:32 -05:00
cqc
fec4249d9f irmin 2022-10-04 23:36:25 -05:00
cqc
65aa7ff901 character insertion 2022-09-03 15:20:22 -05:00
cqc
39193ff253 cursor works 2022-09-03 11:24:34 -05:00
cqc
399280d9c4 correct? rendering 2022-09-02 21:34:47 -05:00
cqc
6a484c3a06 it renders text, but wrong 2022-09-02 19:22:06 -05:00
7 changed files with 1461 additions and 1499 deletions

View File

@ -1 +0,0 @@
profile = compact

View File

@ -1,6 +1,14 @@
open Js_of_ocaml open Js_of_ocaml
open Lwt.Infix
module NVG = Graphv_webgl module NVG = Graphv_webgl
let _ =
Logs.set_reporter (Human.Logs_reporter.console_reporter ());
Logs.set_level (Some Debug);
Logs.debug (fun m -> m "hello")
module Log = (val Logs.src_log Logs.default : Logs.LOG)
(* This scales the canvas to match the DPI of the window, (* This scales the canvas to match the DPI of the window,
it prevents blurriness when rendering to the canvas *) it prevents blurriness when rendering to the canvas *)
let scale_canvas (canvas : Dom_html.canvasElement Js.t) = let scale_canvas (canvas : Dom_html.canvasElement Js.t) =
@ -8,48 +16,55 @@ let scale_canvas (canvas : Dom_html.canvasElement Js.t) =
let rect = canvas##getBoundingClientRect in let rect = canvas##getBoundingClientRect in
let width = rect##.right -. rect##.left in let width = rect##.right -. rect##.left in
let height = rect##.bottom -. rect##.top in let height = rect##.bottom -. rect##.top in
canvas##.width := width *. dpr |> int_of_float ; canvas##.width := width *. dpr |> int_of_float;
canvas##.height := height *. dpr |> int_of_float ; canvas##.height := height *. dpr |> int_of_float;
let width = let width =
Printf.sprintf "%dpx" (int_of_float width) |> Js.string in Printf.sprintf "%dpx" (int_of_float width) |> Js.string
in
let height = let height =
Printf.sprintf "%dpx" (int_of_float height) |> Js.string in Printf.sprintf "%dpx" (int_of_float height) |> Js.string
canvas##.style##.width := width ; in
canvas##.style##.width := width;
canvas##.style##.height := height canvas##.style##.height := height
let _ = let _ =
let canvas = let canvas =
Js.Unsafe.coerce (Dom_html.getElementById_exn "canvas") in Js.Unsafe.coerce (Dom_html.getElementById_exn "canvas")
scale_canvas canvas ; in
scale_canvas canvas;
let webgl_ctx = let webgl_ctx =
(* Graphv requires a stencil buffer to work properly *) (* Graphv requires a stencil buffer to work properly *)
let attrs = WebGL.defaultContextAttributes in let attrs = WebGL.defaultContextAttributes in
attrs##.stencil := Js._true ; attrs##.stencil := Js._true;
match match
WebGL.getContextWithAttributes canvas attrs |> Js.Opt.to_option WebGL.getContextWithAttributes canvas attrs |> Js.Opt.to_option
with with
| None -> | None ->
print_endline "Sorry your browser does not support WebGL" ; print_endline "Sorry your browser does not support WebGL";
raise Exit raise Exit
| Some ctx -> ctx in | Some ctx -> ctx
in
let open NVG in let open NVG in
let vg = let vg =
create create
~flags:CreateFlags.(antialias lor stencil_strokes) ~flags:CreateFlags.(antialias lor stencil_strokes)
webgl_ctx in webgl_ctx
in
(* File in this case is actually the CSS font name *) (* File in this case is actually the CSS font name *)
Text.create vg ~name:"sans" ~file:"sans" |> ignore ; Text.create vg ~name:"sans" ~file:"sans" |> ignore;
webgl_ctx##clearColor 0.3 0.3 0.32 1. ; webgl_ctx##clearColor 0.3 0.3 0.32 1.;
let rec render (time : float) =
(*
let render ev =
webgl_ctx##clear webgl_ctx##clear
( webgl_ctx##._COLOR_BUFFER_BIT_ (webgl_ctx##._COLOR_BUFFER_BIT_
lor webgl_ctx##._DEPTH_BUFFER_BIT_ lor webgl_ctx##._DEPTH_BUFFER_BIT_
lor webgl_ctx##._STENCIL_BUFFER_BIT_ ) ; lor webgl_ctx##._STENCIL_BUFFER_BIT_);
let device_ratio = Dom_html.window##.devicePixelRatio in let device_ratio = Dom_html.window##.devicePixelRatio in
begin_frame vg ~width:canvas##.width ~height:canvas##.height begin_frame vg ~width:canvas##.width ~height:canvas##.height
~device_ratio ; ~device_ratio;
Transform.scale vg ~x:device_ratio ~y:device_ratio ; Transform.scale vg ~x:device_ratio ~y:device_ratio;
Human.Display.render vg canvas##.width canvas##.height ; ignore Human.Panel.Ui.(panel vg Gg.P2.o test ev);
(* (*
Path.begin_ vg ; Path.begin_ vg ;
Path.rect vg ~x:40. ~y:40. ~w:320. ~h:320. ; Path.rect vg ~x:40. ~y:40. ~w:320. ~h:320. ;
@ -62,8 +77,33 @@ let _ =
Text.set_align vg ~align:Align.(center lor middle) ; Text.set_align vg ~align:Align.(center lor middle) ;
set_fill_color vg ~color:Color.white ; set_fill_color vg ~color:Color.white ;
Text.text vg ~x:0. ~y:0. "Hello World!" ; *) Text.text vg ~x:0. ~y:0. "Hello World!" ; *)
NVG.end_frame vg ; NVG.end_frame vg
Dom_html.window##requestAnimationFrame (Js.wrap_callback render) in
|> ignore in Dom_html.window##requestAnimationFrame
Dom_html.window##requestAnimationFrame (Js.wrap_callback render) (Js.wrap_callback (fun _ -> render Human.Event.empty))
|> ignore |> ignore;*)
let open Js_of_ocaml_lwt.Lwt_js_events in
async (fun () ->
buffered_loop (make_event Dom_html.Event.keydown)
Dom_html.document (fun ev _ ->
webgl_ctx##clear
(webgl_ctx##._COLOR_BUFFER_BIT_
lor webgl_ctx##._DEPTH_BUFFER_BIT_
lor webgl_ctx##._STENCIL_BUFFER_BIT_);
let device_ratio = Dom_html.window##.devicePixelRatio in
begin_frame vg ~width:canvas##.width ~height:canvas##.height
~device_ratio;
Transform.scale vg ~x:device_ratio ~y:device_ratio;
Human.Panel.Ui.(
render_lwt vg Gg.P2.o
(Human.Event_js.evt_of_jskey `Press ev))
>>= fun p ->
Logs.debug (fun m ->
m "Drawing finished at point: %a" Gg.V2.pp p);
NVG.end_frame vg;
Lwt.return_unit))
(* Dom_html.document##.onkeydown
:= Dom.handler (fun (evt : Dom_html.keyboardEvent Js.t) ->
render (Human.Event_js.evt_of_jskey `Press evt) ;
Js._false ) *)

7
cors_proxy.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if [ ! -f /tmp/key.pem ]; then
echo Creating key
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /tmp/key.pem -out /tmp/cert.pem -batch
fi
npx http-server --cors -S -P https://github.com --log-ip -c-1 -C /tmp/cert.pem -K /tmp/key.pem

24
dune
View File

@ -1,19 +1,31 @@
(env (env
(dev (dev (flags (:standard -warn-error -A))
(flags (:standard -warn-error -A)))) (js_of_ocaml (flags --no-inline --pretty --source-map-inline --debug-info)
(build_runtime_flags --no-inline --pretty --source-map-inline --debug-info)
(link_flags --source-map-inline))))
(executable (executable
(name boot_js) (name boot_js)
(modes byte js) (modes byte js)
(preprocess (pps js_of_ocaml-ppx)) (preprocess (pps js_of_ocaml-ppx))
(modules boot_js backend backend_js human)
(modules boot_js human)
(libraries (libraries
fmt
logs
graphv_webgl graphv_webgl
js_of_ocaml js_of_ocaml-lwt
lwt digestif.ocaml
checkseum.ocaml
irmin.mem
git
irmin-git irmin-git
irmin-indexeddb cohttp-lwt-jsoo
mimic
uri
zed zed
gg gg
wall
)) ))

View File

@ -1,3 +1,2 @@
(lang dune 2.8) (lang dune 3.4)
(name komm) (name boot)
(wrapped_executables false)

2813
human.ml

File diff suppressed because it is too large Load Diff

View File

@ -17,8 +17,8 @@ div {
} }
canvas { canvas {
width: 400px; width: 100%;
height: 400px; height: 100%;
} }
</style> </style>
</head> </head>