ref: 0729f86ea9233ed4e2e7881fe5ac8aee735c78ee
parent: 141bdb3dee04048a493e5bfca93979ce1f1c9462
author: sirjofri <[email protected]>
date: Sat Sep 7 07:52:23 EDT 2024
properly centers text, fixes text bug
--- a/mkfile
+++ b/mkfile
@@ -1,5 +1,6 @@
</$objtype/mkfile
+BIN=/$objtype/bin
TARG=winview
OFILES=winview.$O
--- a/winview.c
+++ b/winview.c
@@ -185,7 +185,8 @@
}
close(fd);
buf[n] = 0;
- return buf;
+ s = strdup(buf);
+ return s;
}
int
@@ -252,15 +253,16 @@
char *s;
char *winname;
Memimage *m, *mn;
- Point coords;
+ Point coords, txt, ts;
Rectangle textbox;
winname = getwinname(dir->name);
if (!winname)
return 0;
- winname = strdup(winname);
- if (issamewin(winname))
+ if (issamewin(winname)) {
+ free(winname);
return 0;
+ }
s = smprint("%s/%s/window", windir, dir->name);
if (!s)
@@ -295,13 +297,18 @@
memimagedraw(target, rectaddpt(m->r, coords),
m, m->r.min, nil, ZP, S);
- textbox.min = addpt(coords, halfcell);
- textbox.max = addpt(textbox.min, stringsize(font, winname));
+ ts = stringsize(font, winname);
+ txt = addpt(coords, halfcell);
+ txt = subpt(txt, divpt(ts, 2));
+ textbox.min = txt;
+ textbox.max = addpt(textbox.min, ts);
textbox = insetrect(textbox, -5);
memimagedraw(target, textbox, tback, ZP, nil, ZP, SoverD);
- memimagestring(target, addpt(coords, halfcell),
+ memimagestring(target, txt,
contrast, ZP, memdefont, winname);
+
+ free(winname);
if (!windows[num].name) {
windows[num].name = strdup(dir->name);