From: Michael D. Lowis Date: Fri, 19 Jan 2018 21:06:29 +0000 (-0500) Subject: Added line tracking to buffer drawing code so that clicks can be mapped easier X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d7e07da74bc50037567da73a2a08c1d52202c580;p=archive%2Ftide-ocaml.git Added line tracking to buffer drawing code so that clicks can be mapped easier --- diff --git a/edit.ml b/edit.ml index 3dcbcd0..ff6a713 100644 --- 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 "" diff --git a/lib/draw.ml b/lib/draw.ml index be62bdc..7bb2dbf 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -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 diff --git a/lib/draw.mli b/lib/draw.mli index ab4166e..4910c43 100644 --- a/lib/draw.mli +++ b/lib/draw.mli @@ -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) diff --git a/lib/view.ml b/lib/view.ml index 25e8521..08c1070 100644 --- a/lib/view.ml +++ b/lib/view.ml @@ -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 }