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) {
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);
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;
}
}
}
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;
}