From: Mike Lowis Date: Tue, 4 Oct 2016 20:26:27 +0000 (-0400) Subject: Added offset tracking per line in the screen buffer. Also moved the rune to display... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=b52d61f2161adf8a0da3d570a772499032e9ce81;p=projs%2Ftide.git Added offset tracking per line in the screen buffer. Also moved the rune to display glyph logic to the screen module --- diff --git a/edit.h b/edit.h index 3173a73..9126b52 100644 --- a/edit.h +++ b/edit.h @@ -56,6 +56,8 @@ unsigned buf_byline(Buf* buf, unsigned pos, int count); /* Screen management functions *****************************************************************************/ typedef struct { + unsigned off; + unsigned rlen; unsigned len; Rune cols[]; } Row; @@ -65,7 +67,8 @@ void screen_getsize(unsigned* nrows, unsigned* ncols); void screen_clear(void); Row* screen_getrow(unsigned row); void screen_clearrow(unsigned row); -void screen_setcell(unsigned row, unsigned col, Rune r); +void screen_setrowoff(unsigned row, unsigned off); +unsigned screen_setcell(unsigned row, unsigned col, Rune r); Rune screen_getcell(unsigned row, unsigned col); /* Miscellaneous Functions diff --git a/screen.c b/screen.c index 33818ad..27f1fb9 100644 --- a/screen.c +++ b/screen.c @@ -36,16 +36,32 @@ void screen_clearrow(unsigned row) if (!scrrow) return; for (unsigned i = 0; i < NumCols; i++) scrrow->cols[i] = (Rune)' '; - scrrow->len = 0; + scrrow->rlen = 0; + scrrow->len = 0; } -void screen_setcell(unsigned row, unsigned col, Rune r) +void screen_setrowoff(unsigned row, unsigned off) { - if (row >= NumRows || col >= NumCols) return; + screen_getrow(row)->off = off; +} + +unsigned screen_setcell(unsigned row, unsigned col, Rune r) +{ + if (row >= NumRows || col >= NumCols) return 0; Row* scrrow = screen_getrow(row); - scrrow->cols[col] = r; - if (col+1 >= scrrow->len) - scrrow->len = col+1; + /* write the rune to the screen buf */ + unsigned ncols = 1; + if (r == '\t') { + scrrow->cols[col] = ' '; + ncols = (TabWidth - (col % TabWidth)); + } else if (r != '\n') { + scrrow->cols[col] = r; + } + /* Update lengths */ + scrrow->rlen += 1; + if ((col + ncols) > scrrow->len) + scrrow->len = col + ncols; + return ncols; } Rune screen_getcell(unsigned row, unsigned col) diff --git a/xedit.c b/xedit.c index 8071095..c7a4ffa 100644 --- a/xedit.c +++ b/xedit.c @@ -247,19 +247,14 @@ static void redraw(void) { screen_clearrow(0); for (unsigned y = 1; y < nrows; y++) { screen_clearrow(y); - for (unsigned x = 0; x < ncols; x++) { + screen_setrowoff(y, pos); + for (unsigned x = 0; x < ncols;) { if (CursorPos == pos) csrx = x, csry = y; Rune r = buf_get(&Buffer, pos++); - if (r == '\n') { - screen_setcell(y,x,' '); - break; - } else if (r == '\t') { - screen_setcell(y,x,' '); - x += TabWidth - (x % TabWidth) - 1; - } else { - screen_setcell(y,x,r); - } + unsigned cols = screen_setcell(y,x,r); + x += cols; + if (r == '\n') break; } } EndPos = pos-1; @@ -272,8 +267,7 @@ static void redraw(void) { /* flush the screen buffer */ for (unsigned y = 0; y < nrows; y++) { Row* row = screen_getrow(y); - if (row->len > 0) - XftDrawString32(X.xft, &txtclr, X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len)); + XftDrawString32(X.xft, &txtclr, X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len)); } /* Place cursor on screen */ @@ -281,9 +275,7 @@ static void redraw(void) { if (InsertMode) { XftDrawRect(X.xft, &csrclr, csrx * fwidth, csry * fheight + X.font->descent, 2, fheight); } else { - unsigned width = 1; - if ('\t' == buf_get(&Buffer, CursorPos)) - width = TabWidth - (csrx % TabWidth); + unsigned width = ('\t' == buf_get(&Buffer, CursorPos) ? (TabWidth - (csrx % TabWidth)) : 1); XftDrawRect(X.xft, &csrclr, csrx * fwidth, csry * fheight + X.font->descent, width * fwidth, fheight); XftDrawString32(X.xft, &bkgclr, X.font, csrx * fwidth, (csry+1) * fheight, (FcChar32*)&csrrune, 1); }