From 4c4eacedde19f7de6ed2574a91877bf3c9997a13 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 20 Dec 2017 13:47:34 -0500 Subject: [PATCH] implemented cursor and selection logic --- lib/buf.ml | 2 +- lib/draw.ml | 41 +++++++++++++++++++++++++++++------------ lib/draw.mli | 2 ++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/buf.ml b/lib/buf.ml index 08eda4c..4d80e14 100644 --- a/lib/buf.ml +++ b/lib/buf.ml @@ -73,7 +73,7 @@ module Cursor = struct let selected csr pos = let csr = swap csr in - (pos >= csr.start && pos <= csr.stop) + (pos >= csr.start && pos < csr.stop) end let move_to dest buf i = diff --git a/lib/draw.ml b/lib/draw.ml index 107e591..2c4996c 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -45,23 +45,39 @@ module Cursor = struct let has_next_line csr = ((csr.y + font_height) < csr.height) - let draw_tab csr = + let draw_sel_bkg csr width insel boxes = + if insel then + (X11.make_rect csr.x csr.y width font_height Cfg.Color.palette.(2)) :: boxes + else + boxes + + let draw_newline csr insel boxes = + let boxes = draw_sel_bkg csr (csr.width - csr.x) insel boxes in + next_line csr; + boxes + + let draw_tab csr insel boxes = let xoff = (glyph_width (X11.get_glyph font tabglyph)) in let tabsz = (xoff * tabwidth) in - csr.x <- (csr.startx + ((csr.x - csr.startx + tabsz) / tabsz * tabsz)) + let newx = (csr.startx + ((csr.x - csr.startx + tabsz) / tabsz * tabsz)) in + let boxes = draw_sel_bkg csr (newx - csr.x) insel boxes in + csr.x <- newx; + boxes - let place_glyph csr glyph clr = + let place_glyph csr glyph clr insel boxes = let xoff = (glyph_width glyph) in if (csr.x + xoff) > csr.width then (next_line csr); + let boxes = draw_sel_bkg csr xoff insel boxes in let _ = X11.draw_glyph Cfg.Color.palette.(clr) glyph (csr.x, csr.y) in - csr.x <- csr.x + xoff + csr.x <- csr.x + xoff; + boxes - let draw_glyph csr c clr = + let draw_glyph csr c clr insel boxes = match c with - | 0x0A -> next_line csr - | 0x0D -> () - | 0x09 -> draw_tab csr - | _ -> place_glyph csr (X11.get_glyph font c) clr + | 0x0A -> draw_newline csr insel boxes + | 0x0D -> boxes + | 0x09 -> draw_tab csr insel boxes + | _ -> place_glyph csr (X11.get_glyph font c) clr insel boxes let next_glyph csr c = let glyph = (X11.get_glyph font c) in @@ -69,7 +85,7 @@ module Cursor = struct match c with | 0x0A -> next_line csr; true | 0x0D -> false - | 0x09 -> draw_tab csr; false + | 0x09 -> let _ = draw_tab csr false [] in false | _ -> let nl = (if (csr.x + xoff) > csr.width then (next_line csr; true) else false) in csr.x <- csr.x + xoff; nl @@ -101,16 +117,17 @@ 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) in + let num = ref 0 and csr = (restart csr 2 0) and boxes = ref [] in let draw_rune c = let pos = off + !num in if pos == (Buf.csrpos buf) then draw_cursor csr; - draw_glyph csr c (Colormap.find pos clr); + 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 let status csr str = diff --git a/lib/draw.mli b/lib/draw.mli index 517ee34..f97126a 100644 --- a/lib/draw.mli +++ b/lib/draw.mli @@ -4,10 +4,12 @@ module Cursor : sig val clone : t -> t val move_x : t -> int -> unit val max_width : t -> int +(* val restart : t -> int -> int -> t val next_line : t -> unit val has_next_line : t -> bool val draw_glyph : t -> int -> int -> unit +*) val next_glyph : t -> int -> bool end -- 2.52.0