]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
sketched out basic window drawing code
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 28 Sep 2017 18:55:58 +0000 (14:55 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 28 Sep 2017 18:55:58 +0000 (14:55 -0400)
Makefile
edit.ml
lib/rope.ml

index 40ab0eea9bd6f8c292f14c527dbb3b173b720b4f..eeb53a8f616d39c5093e56b02bc17ef6bf4e812b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 # Toolchain Configuration
 #-------------------------------------------------------------------------------
 INCS = -I . -I lib -I /usr/X11R6/include -I /usr/include/freetype2 -I /usr/X11R6/include/freetype2
-LIBS = -L/usr/X11R6/lib -lX11 -lXft
+LIBS = -L/usr/X11R6/lib -lX11 -lXft -lfontconfig
 
 ifeq ($(NATIVE), 1)
     OC         = ocamlopt
diff --git a/edit.ml b/edit.ml
index 97862d0e1effc480199117a20785a42540e17aac..a5bb3b87d22a500535c2c2f2e9496dcf5fce82f0 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -1,8 +1,42 @@
 open X11
 
 (*let font = font_load "Times New Roman:pixelsize=14"*)
-let font = font_load "Helvetica:pixelsize=48"
+let font = font_load "Liberation Mono:size=10"
 
+(* Drawing functions
+ ******************************************************************************)
+type drawpos = { x: int; y: int }
+
+let draw_background width height =
+  draw_rect { x = 0; y = 0; w = width; h = height; c = Cfg.Color.palette.(0) }
+
+let draw_hrule pos width =
+  draw_rect { x = 0; y = pos.y; w = width; h = 1; c = Cfg.Color.palette.(3) };
+  { pos with y = pos.y + 1 }
+
+let draw_vrule pos height =
+  draw_rect { x = pos.x; y = pos.y; w = 1; h = height - pos.y; c = Cfg.Color.palette.(3) };
+  { pos with x = pos.x + 1 }
+
+let draw_status pos width text =
+  draw_string font Cfg.Color.palette.(5) text (pos.x + 2, pos.y + 2);
+  let pos = { pos with y = (4 + font.height) } in
+  draw_hrule pos width
+
+let draw_tags pos width text =
+  draw_string font Cfg.Color.palette.(5) text (pos.x + 2, pos.y + 2);
+  let pos = { pos with y = (pos.y + 2 + font.height) } in
+  draw_hrule pos width
+
+let draw_scroll pos height =
+  let pos = { pos with x = 14 } in
+  draw_vrule pos height
+
+let draw_edit pos width height =
+  ()
+
+(* Event functions
+ ******************************************************************************)
 let onfocus focused =
   print_endline "onfocus"
 
@@ -16,12 +50,12 @@ let onmousemove mods x y =
   print_endline "onmousemove"
 
 let onupdate width height =
-  let text = "FooBarBazYay" in
-  Printf.printf "onupdate: %d %d\n" width height;
-  draw_rect { x = 2; y = 2; w = width; h = height; c = Cfg.Color.palette.(0) };
-  draw_string font Cfg.Color.palette.(5) text (2,2);
-  draw_string font Cfg.Color.palette.(5) text (2,2+font.height);
-  draw_rect { x = 2; y = 2; w = 1; h = font.height; c = Cfg.Color.palette.(3) };
+  draw_background width height;
+  let (pos : drawpos) = { x = 0; y = 0 } in
+  let pos = draw_status pos width "UNSI> *scratch*" in
+  let pos = draw_tags pos width "Sample tags data" in
+  let pos = draw_scroll pos height in
+  draw_edit pos width height;
   flip ()
 
 let onshutdown () =
@@ -41,6 +75,8 @@ let onevent = function
   | Update e         -> onupdate e.width e.height
   | Shutdown         -> onshutdown ()
 
+(* Main Routine
+ ******************************************************************************)
 let () =
   let win = make_window 640 480 in
   show_window win true;
index acb9edaa55784a69beca37cc7c6bf4c85dc0a053..128adc5fc30950908133ebad3ffe0a2359043334 100644 (file)
@@ -44,7 +44,7 @@ let rec split rope i =
 let rec getc rope i =
   check_index rope i;
   match rope with
-  | Leaf (s,off,len) -> s.[off + i]
+  | Leaf (s,off,_) -> s.[off + i]
   | Node (l,r,len)   ->
       let left_len = (length l) in
       if i < left_len then