]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
implemented scanning portion of scrollmap generation
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 26 Oct 2017 01:53:49 +0000 (21:53 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 26 Oct 2017 01:53:49 +0000 (21:53 -0400)
lib/draw.ml
lib/draw.mli
lib/scrollmap.ml

index 2e9d5563bbd13a8e5df3a3e1b98b7b57e9c4bab8..6cae7e613da3aaa6238ead9149073e2eede833be 100644 (file)
@@ -25,9 +25,6 @@ module Cursor = struct
     csr.y <- csr.starty;
     csr
 
-  let place_glyph csr glyph =
-    let _ = X11.draw_glyph Cfg.Color.palette.(5) glyph (csr.x, csr.y) in ()
-
   let next_line csr =
     csr.x <- csr.startx;
     csr.y <- csr.y + font_height
@@ -35,19 +32,32 @@ module Cursor = struct
   let has_next_line csr =
     ((csr.y + font_height) < csr.height)
 
-  let next_glyph csr c draw =
-    let glyph = (X11.get_glyph font c) in
+  let draw_tab csr =
+    let tabsz = ((X11.get_glyph font tabglyph).xoff * tabwidth) in
+    csr.x <- (csr.startx + ((csr.x - csr.startx + tabsz) / tabsz * tabsz))
+
+  let place_glyph csr glyph =
+    let xoff = (let open X11 in glyph.xoff) in
+    if (csr.x + xoff) > csr.width then (next_line csr);
+    let _ = X11.draw_glyph Cfg.Color.palette.(5) glyph (csr.x, csr.y) in
+    csr.x <- csr.x + xoff
+
+  let draw_glyph csr c =
     match c with
     | 0x0A -> next_line csr
     | 0x0D -> ()
-    | 0x09 ->
-        let tabsz = ((X11.get_glyph font tabglyph).xoff * tabwidth) in
-        csr.x <- (csr.startx + ((csr.x - csr.startx + tabsz) / tabsz * tabsz))
-    | _    -> begin
-        if (csr.x + glyph.xoff) > csr.width then (next_line csr);
-        if draw then place_glyph csr glyph;
-        csr.x <- csr.x + glyph.xoff
-    end
+    | 0x09 -> draw_tab csr
+    | _    -> place_glyph csr (X11.get_glyph font c)
+
+  let next_glyph csr c =
+    let glyph = (X11.get_glyph font c) in
+    match c with
+    | 0x0A -> next_line csr; true
+    | 0x0D -> false
+    | 0x09 -> draw_tab csr; false
+    | _    -> let nl = (if (csr.x + glyph.xoff) > csr.width then
+                        (next_line csr; true) else false) in
+              csr.x <- csr.x + glyph.xoff; nl
 end
 
 open Cursor
@@ -75,7 +85,7 @@ let vrule height csr =
 let buffer csr buf =
   let csr = (restart csr 2 0) in
   let draw_rune c =
-    next_glyph csr c true;
+    draw_glyph csr c;
     has_next_line csr
   in
   Buf.iter_from draw_rune buf (Buf.start buf)
index 55501d89eb6a5156ab1305c7c6b02d3940de8b5a..11b70b7d839c2d86d3fa6490bb02a400536ed6d7 100644 (file)
@@ -2,10 +2,10 @@ module Cursor : sig
   type t
   val make : (int * int) -> int -> int -> t
   val restart : t -> int -> int -> t
-  val place_glyph : t -> X11.glyph -> unit
   val next_line : t -> unit
   val has_next_line : t -> bool
-  val next_glyph : t -> int -> bool -> unit
+  val draw_glyph : t -> int -> unit
+  val next_glyph : t -> int -> bool
 end
 
 val font : X11.font
index d1a0e2be50f2e277bb656b38cab553548e354c43..d81b6a63252867945f125e8f4caaf2d0060df67d 100644 (file)
@@ -4,14 +4,13 @@ type t = {
 }
 
 let make buf width height off =
+  print_endline "\nfoo:";
   let bol = (Rope.to_bol (Buf.rope buf) off) in
   let lines = ref [bol] in
   let csr = Draw.Cursor.make (width, 0) 0 0 in
   let process_glyph i c =
-    let open Draw.Cursor in
-    next_glyph csr c false;
-    (*if csr.startx == csr.x then
-      lines := i :: !lines;*)
+    if (Draw.Cursor.next_glyph csr c) then
+      lines := i :: !lines;
     ((Rope.is_eol (Buf.rope buf) i) == false)
   in
   Buf.iteri_from process_glyph buf off;