]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
Added line tracking to buffer drawing code so that clicks can be mapped easier
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 19 Jan 2018 21:06:29 +0000 (16:06 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 19 Jan 2018 21:06:29 +0000 (16:06 -0500)
edit.ml
lib/draw.ml
lib/draw.mli
lib/view.ml

diff --git a/edit.ml b/edit.ml
index 3dcbcd0816a8359be7d24a54fc81809830779e60..ff6a713f2dbb65bee73bbc695b576ff6ec2d311e 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -17,7 +17,6 @@ let scroll_dn () =
  ******************************************************************************)
 let onselect mods x y nclicks =
   let sx,sy = !edit_view.pos and w,h = !edit_view.dim in
-  Printf.printf "lines: %d\n" ((h - sy) / Draw.font.height);
   Printf.printf "select (%d,%d) %d" x y nclicks;
   print_endline ""
 
index be62bdcc159719ce8a257e1405690b09cde35803..7bb2dbfacea82592c1e1d6585b18c720f4193001 100644 (file)
@@ -123,18 +123,21 @@ let vrule height csr =
 let buffer csr buf clr off =
   dark_bkg (csr.width - csr.x) (csr.height - csr.y) csr;
   csr.y <- csr.y + 2;
-  let num = ref 0 and csr = (restart csr 2 0) and boxes = ref [] in
+  let num = ref 0 and csr = (restart csr 2 0)
+  and boxes = ref [] and lines = ref [] in
   let draw_rune c =
     let pos = off + !num in
     if pos == (Buf.csrpos buf) then
       draw_cursor csr;
+    if csr.x == csr.startx then
+      lines := pos :: !lines;
     boxes := draw_glyph csr c (Colormap.find pos clr) (Buf.selected buf pos) !boxes;
     num := !num + 1;
     has_next_line csr
   in
   Buf.iter draw_rune buf off;
   List.iter X11.draw_rect !boxes; (* draw selection boxes *)
-  !num
+  (!num, !lines)
 
 let status csr str =
   dark_bkg csr.width (4 + font_height) csr;
@@ -160,4 +163,5 @@ let scroll csr params =
 
 let edit csr buf clr =
   dark_bkg (csr.width - csr.x) (csr.height - csr.y) csr;
-  buffer csr buf clr
+  let nchars = buffer csr buf clr in
+  nchars
index ab4166e9ba76382270e9cdf32b6da630d57565fe..4910c43a87da1492af8801d537825b05ac287472 100644 (file)
@@ -22,7 +22,7 @@ val dark_bkg : int -> int -> Cursor.t -> unit
 val light_bkg : int -> int -> Cursor.t -> unit
 val rule_bkg : int -> int -> Cursor.t -> unit
 
-val buffer : Cursor.t -> Buf.t -> Colormap.t -> int -> int
+val buffer : Cursor.t -> Buf.t -> Colormap.t -> int -> (int * int list)
 
 val string : string -> Cursor.t -> unit
 val hrule : int -> Cursor.t -> unit
@@ -31,4 +31,4 @@ val vrule : int -> Cursor.t -> unit
 val status : Cursor.t -> string -> unit
 val tags : Cursor.t -> Buf.t -> unit
 val scroll : Cursor.t -> (float * float) -> unit
-val edit : Cursor.t -> Buf.t -> Colormap.t -> int -> int
+val edit : Cursor.t -> Buf.t -> Colormap.t -> int -> (int * int list)
index 25e85216dbe5393c5b6b9c21bcaaf3936810b182..08c1070053857e6eded7b0897bcffcfc6e746e9d 100644 (file)
@@ -1,5 +1,6 @@
 type t = {
   num : int;
+  lines: int list;
   buf : Buf.t;
   map : Scrollmap.t;
   clr : Colormap.t;
@@ -8,7 +9,7 @@ type t = {
 }
 
 let from_buffer buf width height =
-  { num = 0; buf = buf;
+  { num = 0; buf = buf; lines = [];
     map = Scrollmap.make buf width 0;
     clr = Colormap.make (Buf.make_lexer buf);
     pos = (0,0);
@@ -29,9 +30,10 @@ let resize view width =
 let draw view csr =
   let view = (resize view (Draw.Cursor.max_width csr)) in
   let newcsr = (Draw.Cursor.clone csr) in
-  let num = Draw.buffer newcsr view.buf view.clr (Scrollmap.first view.map) in
+  let num, lines = Draw.buffer newcsr view.buf view.clr (Scrollmap.first view.map) in
   { view with
     num = num;
+    lines = lines;
     pos = Draw.Cursor.pos csr;
     dim = Draw.Cursor.dim csr }