]> git.mdlowis.com Git - projs/tide.git/commitdiff
reworked the screen buffer code so that it is only *fully* updated on screen resize...
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 5 Oct 2016 02:52:35 +0000 (22:52 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 5 Oct 2016 02:52:35 +0000 (22:52 -0400)
edit.h
screen.c
xedit.c

diff --git a/edit.h b/edit.h
index e4ceccb2b3404906ea0c4c8fe7bd471de196bce5..e56eee0a6c18ef65968166cec4327c4b0d6429e9 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -61,7 +61,7 @@ typedef struct {
     Rune cols[];
 } Row;
 
-void screen_setsize(unsigned nrows, unsigned ncols);
+void screen_setsize(Buf* buf, unsigned nrows, unsigned ncols);
 void screen_getsize(unsigned* nrows, unsigned* ncols);
 void screen_clear(void);
 Row* screen_getrow(unsigned row);
index 2135b9cbe2e13fb513e83adfa0aae65f6f31bc2f..e69b42ea505662f7cb002909b7d0a94d7a8845db 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -4,13 +4,36 @@ static unsigned NumRows = 0;
 static unsigned NumCols = 0;
 static Row** Rows;
 
-void screen_setsize(unsigned nrows, unsigned ncols) {
-    if (Rows) free(Rows);
+void screen_setsize(Buf* buf, unsigned nrows, unsigned ncols) {
+    unsigned pos = 0;
+    /* free the old row data */
+    if (Rows) {
+        pos = Rows[1]->off;
+        for (unsigned i = 0; i < NumRows; i++)
+            free(Rows[i]);
+        free(Rows);
+    }
+    /* create the new row data */
     Rows = calloc(nrows, sizeof(Row*));
     for (unsigned i = 0; i < nrows; i++)
         Rows[i] = calloc(1, sizeof(Row) + (ncols * sizeof(Rune)));
+    /* update dimensions */
     NumRows = nrows;
     NumCols = ncols;
+    /* populate the screen buffer */
+    screen_clearrow(0);
+    for (unsigned y = 1; y < NumRows; y++) {
+        screen_clearrow(y);
+        screen_setrowoff(y, pos);
+        for (unsigned x = 0; x < NumCols;) {
+            //if (csr == pos)
+            //    *csrx = x, *csry = y;
+            Rune r = buf_get(buf, pos++);
+            x += screen_setcell(y,x,r);
+            if (r == '\n') break;
+        }
+    }
+
 }
 
 void screen_getsize(unsigned* nrows, unsigned* ncols) {
@@ -63,13 +86,8 @@ Rune screen_getcell(unsigned row, unsigned col) {
     return scrrow->cols[col];
 }
 
-static unsigned linelen(Buf* buf, unsigned csr) {
-    unsigned eol = buf_eol(buf, csr);
-    unsigned bol = buf_bol(buf, csr);
-    return (eol - bol);
-}
-
 static void fill_row(Buf* buf, unsigned row, unsigned pos) {
+    screen_clearrow(row);
     for (unsigned x = 0; x < NumCols;) {
         Rune r = buf_get(buf, pos++);
         x += screen_setcell(row, x, r);
@@ -116,16 +134,13 @@ static void sync_view(Buf* buf, unsigned csr) {
 void screen_update(Buf* buf, unsigned csr, unsigned* csrx, unsigned* csry) {
     sync_view(buf, csr);
     screen_clearrow(0);
-    unsigned pos = Rows[1]->off;
     for (unsigned y = 1; y < NumRows; y++) {
-        screen_clearrow(y);
-        screen_setrowoff(y, pos);
-        for (unsigned x = 0; x < NumCols;) {
-            if (csr == pos)
-                *csrx = x, *csry = y;
-            Rune r = buf_get(buf, pos++);
-            x += screen_setcell(y,x,r);
-            if (r == '\n') break;
+        unsigned start = Rows[y]->off;
+        unsigned end   = Rows[y]->off + Rows[y]->rlen - 1;
+        if (start <= csr && csr <= end) {
+            *csry = y;
+            *csrx = csr - start;
+            break;
         }
     }
 }
diff --git a/xedit.c b/xedit.c
index d243691a5e35db90095b87139eb2f58208e3931f..651f19f53113410059d2ab40a7671d521aade3c7 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -196,7 +196,10 @@ static void handle_event(XEvent* e) {
                 X.height = e->xconfigure.height;
                 X.pixmap = XCreatePixmap(X.display, X.window, X.width, X.height, X.depth);
                 X.xft    = XftDrawCreate(X.display, X.pixmap, X.visual, X.colormap);
-                screen_setsize(X.height / X.font->height, X.width / X.font->max_advance_width);
+                screen_setsize(
+                    &Buffer,
+                    X.height / X.font->height,
+                    X.width / X.font->max_advance_width);
             }
             break;
     }