From bb200521cc918055c9d94932dd4037bbbeb442ab Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 28 Sep 2017 14:55:58 -0400 Subject: [PATCH] sketched out basic window drawing code --- Makefile | 2 +- edit.ml | 50 +++++++++++++++++++++++++++++++++++++++++++------- lib/rope.ml | 2 +- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 40ab0ee..eeb53a8 100644 --- 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 97862d0..a5bb3b8 100644 --- 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; diff --git a/lib/rope.ml b/lib/rope.ml index acb9eda..128adc5 100644 --- a/lib/rope.ml +++ b/lib/rope.ml @@ -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 -- 2.52.0