commit 9cbcbd6f9384e42a6268f0ebb3686db3d4cf5d2c
parent 93a31baa7cf1b6377160a0d2ef9b4a7c50899ad4
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Thu, 31 Mar 2022 21:53:51 +0000
cache DrawState for every new line
Diffstat:
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/richterm.c b/richterm.c
@@ -748,10 +748,13 @@ drawelems(void)
Elem *e;
e = nil;
ds.pos = Pt(rich.r.min.x, rich.r.min.y - rich.scroll);
- ds.nlpos = Pt(rich.r.min.x, ds.pos.y + font->height);
+ ds.nlpos = ds.pos; // Pt(rich.r.min.x, ds.pos.y + font->height);
ds.font = font;
ds.link = nil;
+ drawcache->count = 0;
+ arraygrow(drawcache, 1, &ds);
+
for (ds.n = 0; ds.n < elems->count; ds.n++) {
if (arrayget(elems, ds.n, &e) == nil)
sysfatal("drawelems: failed to get elem");
@@ -794,6 +797,7 @@ drawrune(DrawState *ds, Elem *e)
draw(screen, r, bg, nil, ZP);
ds->pos = ds->nlpos;
r = elemrect(ds, e);
+ arraygrow(drawcache, 1, ds);
}
if (rectXrect(r, rich.r) != 0) {
@@ -877,13 +881,16 @@ clearelems(void)
int
getelem(Point xy)
{
- int i;
+ long i;
DrawState ds;
- ds.pos = Pt(rich.r.min.x, rich.r.min.y - rich.scroll);
- ds.nlpos = Pt(rich.r.min.x, ds.pos.y + font->height);
- ds.font = font;
- ds.link = nil;
+
+ for (i = drawcache->count - 1; i >= 0; i--) {
+ if (arrayget(drawcache, 0, &ds) == nil) {
+ sysfatal("getelem: drawcache failure");
+ }
+ if (ds.pos.y < xy.y) break;
+ }
for (i = 0; i < elems->count; i++) {
@@ -944,7 +951,6 @@ getlink(long n)
return nil;
}
-
Rectangle
elemrect(DrawState *ds, Elem *e)
{