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 Lwt.Infix
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,
it prevents blurriness when rendering to the canvas *)
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 width = rect##.right -. rect##.left in
let height = rect##.bottom -. rect##.top in
canvas##.width := width *. dpr |> int_of_float ;
canvas##.height := height *. dpr |> int_of_float ;
canvas##.width := width *. dpr |> int_of_float;
canvas##.height := height *. dpr |> int_of_float;
let width =
Printf.sprintf "%dpx" (int_of_float width) |> Js.string in
Printf.sprintf "%dpx" (int_of_float width) |> Js.string
in
let height =
Printf.sprintf "%dpx" (int_of_float height) |> Js.string in
canvas##.style##.width := width ;
Printf.sprintf "%dpx" (int_of_float height) |> Js.string
in
canvas##.style##.width := width;
canvas##.style##.height := height
let _ =
let canvas =
Js.Unsafe.coerce (Dom_html.getElementById_exn "canvas") in
scale_canvas canvas ;
Js.Unsafe.coerce (Dom_html.getElementById_exn "canvas")
in
scale_canvas canvas;
let webgl_ctx =
(* Graphv requires a stencil buffer to work properly *)
let attrs = WebGL.defaultContextAttributes in
attrs##.stencil := Js._true ;
attrs##.stencil := Js._true;
match
WebGL.getContextWithAttributes canvas attrs |> Js.Opt.to_option
with
| None ->
print_endline "Sorry your browser does not support WebGL" ;
print_endline "Sorry your browser does not support WebGL";
raise Exit
| Some ctx -> ctx in
| Some ctx -> ctx
in
let open NVG in
let vg =
create
~flags:CreateFlags.(antialias lor stencil_strokes)
webgl_ctx in
webgl_ctx
in
(* File in this case is actually the CSS font name *)
Text.create vg ~name:"sans" ~file:"sans" |> ignore ;
webgl_ctx##clearColor 0.3 0.3 0.32 1. ;
let rec render (time : float) =
Text.create vg ~name:"sans" ~file:"sans" |> ignore;
webgl_ctx##clearColor 0.3 0.3 0.32 1.;
(*
let render ev =
webgl_ctx##clear
( webgl_ctx##._COLOR_BUFFER_BIT_
(webgl_ctx##._COLOR_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
begin_frame vg ~width:canvas##.width ~height:canvas##.height
~device_ratio ;
Transform.scale vg ~x:device_ratio ~y:device_ratio ;
Human.Display.render vg canvas##.width canvas##.height ;
~device_ratio;
Transform.scale vg ~x:device_ratio ~y:device_ratio;
ignore Human.Panel.Ui.(panel vg Gg.P2.o test ev);
(*
Path.begin_ vg ;
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) ;
set_fill_color vg ~color:Color.white ;
Text.text vg ~x:0. ~y:0. "Hello World!" ; *)
NVG.end_frame vg ;
Dom_html.window##requestAnimationFrame (Js.wrap_callback render)
|> ignore in
Dom_html.window##requestAnimationFrame (Js.wrap_callback render)
|> ignore
NVG.end_frame vg
in
Dom_html.window##requestAnimationFrame
(Js.wrap_callback (fun _ -> render Human.Event.empty))
|> 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
(dev
(flags (:standard -warn-error -A))))
(dev (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
(name boot_js)
(modes byte js)
(preprocess (pps js_of_ocaml-ppx))
(modules boot_js backend backend_js human)
(modules boot_js human)
(libraries
fmt
logs
graphv_webgl
js_of_ocaml
lwt
js_of_ocaml-lwt
digestif.ocaml
checkseum.ocaml
irmin.mem
git
irmin-git
irmin-indexeddb
cohttp-lwt-jsoo
mimic
uri
zed
gg
wall
))

View File

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

2829
human.ml

File diff suppressed because it is too large Load Diff

View File

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