|
- /* vview.c - drawing for the c64 vim clone: scroll, rows, status row. */
-
- extern char *bfr;
- extern unsigned blen;
- extern unsigned lptr[];
- extern int nlines, cy, cx, top, leftcol, mode, dirty;
- extern char *note;
- extern char fname[];
- extern char ybuf[];
- extern int ylen, yok;
- extern int redraw;
-
- /* decimal of v into t at p, returns the position after it */
- dnum(t, p, v)
- char *t;
- int p, v;
- {
- char d[6];
- int n;
-
- n = 0;
- if (v == 0) {
- t[p++] = 48;
- return p;
- }
- while (v > 0 && n < 5) {
- d[n++] = 48 + (v % 10);
- v = v / 10;
- }
- while (n > 0) t[p++] = d[--n];
- return p;
- }
-
- /* bring the cursor back into view */
- scroll()
- {
- if (cy < top) top = cy;
- if (cy > top + 23) top = cy - 23;
- if (top < 0) top = 0;
- if (cx < leftcol) leftcol = cx;
- if (cx > leftcol + 39) leftcol = cx - 39;
- if (leftcol < 0) leftcol = 0;
- return 0;
- }
-
- /* the status row: message, mode or name on the left; modified flag; line/total */
- dstat()
- {
- char t[40];
- char *s;
- int i, n, p;
-
- if (note != 0) s = note;
- else if (mode) s = "-- insert --";
- else if (fname[0] == 0) s = "[no name]";
- else s = fname;
-
- n = 0;
- for (i = 0; s[i] && i < 26; i++) t[n++] = s[i];
- while (n < 28) t[n++] = 32;
- if (dirty) t[n++] = 43; /* + */
- else t[n++] = 32;
- while (n < 31) t[n++] = 32;
- p = dnum(t, n, cy + 1);
- t[p++] = 47; /* / */
- p = dnum(t, p, nlines);
-
- mlrow((unsigned) t, p, 1984, 255, 128); /* row 24 = $0400 + 960, reverse */
- return 0;
- }
-
- /* what the screen showed last time, so a key that only moves the cursor
- repaints two rows instead of 24 */
- int ltop, lleft, lcy;
-
- /* repaint what changed, then the status row. redraw is raised by the editing
- code: 1 = the cursor line changed, 2 = lines moved, repaint everything.
- (no double bar: power c cannot type it, see NOTES.md) */
- dall()
- {
- int crow, ccol, orow, full;
-
- crow = cy - top;
- ccol = cx - leftcol;
- full = 0;
- if (redraw == 2) full = 1;
- if (top != ltop) full = 1;
- if (leftcol != lleft) full = 1;
- if (full) {
- mlscr(0, 23, crow, ccol); /* one call paints 24 rows */
- } else {
- orow = lcy - top; /* take the cursor off its old row */
- if (orow != crow && orow >= 0 && orow < 24) mlscr(orow, orow, crow, ccol);
- mlscr(crow, crow, crow, ccol);
- }
- ltop = top;
- lleft = leftcol;
- lcy = cy;
- redraw = 0;
- dstat();
- return 0;
- }
-
- /* end of vview.c */
|