drawing is faster but the bold attr is not supported anymore.

This commit is contained in:
Aurélien Aptel 2009-10-28 14:34:22 +01:00
parent 4e6915a16b
commit f2dff29a16
2 changed files with 39 additions and 27 deletions

View File

@ -3,7 +3,7 @@
#define FONT "fixed" #define FONT "fixed"
#define BORDER 3 #define BORDER 3
#define LINESPACE 1 /* additional pixel between each line */ #define LINESPACE 0 /* additional pixel between each line */
/* Terminal colors */ /* Terminal colors */
static const char *colorname[] = { static const char *colorname[] = {

64
st.c
View File

@ -3,6 +3,7 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h>
#include <locale.h> #include <locale.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@ -24,6 +25,7 @@
/* Arbitrary sizes */ /* Arbitrary sizes */
#define ESCSIZ 256 #define ESCSIZ 256
#define ESCARG 16 #define ESCARG 16
#define MAXDRAWBUF 1024
#define SERRNO strerror(errno) #define SERRNO strerror(errno)
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
@ -32,6 +34,7 @@
#define DEFAULT(a, b) (a) = (a) ? (a) : (b) #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
/* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */ /* Attribute, Cursor, Character state, Terminal mode, Screen draw mode */
enum { ATnone=0 , ATreverse=1 , ATunderline=2, ATbold=4 }; enum { ATnone=0 , ATreverse=1 , ATunderline=2, ATbold=4 };
@ -933,6 +936,23 @@ xinit(void) {
XSync(xw.dis, 0); XSync(xw.dis, 0);
} }
void
xdraws (char *s, Glyph base, int x, int y, int len) {
unsigned long xfg, xbg;
int winx = x*xw.cw, winy = y*xw.ch + dc.font->ascent, width = len*xw.cw;
if(base.mode & ATreverse)
xfg = dc.col[base.bg], xbg = dc.col[base.fg];
else
xfg = dc.col[base.fg], xbg = dc.col[base.bg];
XSetBackground(xw.dis, dc.gc, xbg);
XSetForeground(xw.dis, dc.gc, xfg);
XDrawImageString(xw.dis, xw.win, dc.gc, winx, winy, s, len);
if(base.mode & ATunderline)
XDrawLine(xw.dis, xw.win, dc.gc, winx, winy+1, winx+width-1, winy+1);
}
void void
xdrawc(int x, int y, Glyph g) { xdrawc(int x, int y, Glyph g) {
XRectangle r = { x * xw.cw, y * xw.ch, xw.cw, xw.ch }; XRectangle r = { x * xw.cw, y * xw.ch, xw.cw, xw.ch };
@ -944,18 +964,9 @@ xdrawc(int x, int y, Glyph g) {
else else
xfg = dc.col[g.fg], xbg = dc.col[g.bg]; xfg = dc.col[g.fg], xbg = dc.col[g.bg];
/* background */ /* background */
XSetForeground(xw.dis, dc.gc, xbg); XSetBackground(xw.dis, dc.gc, xbg);
XFillRectangles(xw.dis, xw.win, dc.gc, &r, 1);
/* string */
XSetForeground(xw.dis, dc.gc, xfg); XSetForeground(xw.dis, dc.gc, xfg);
XDrawString(xw.dis, xw.win, dc.gc, r.x, r.y+dc.font->ascent, &(g.c), 1); XDrawImageString(xw.dis, xw.win, dc.gc, r.x, r.y+dc.font->ascent, &g.c, 1);
if(g.mode & ATbold) /* XXX: bold hack (draw again at x+1) */
XDrawString(xw.dis, xw.win, dc.gc, r.x+1, r.y+dc.font->ascent, &(g.c), 1);
/* underline */
if(g.mode & ATunderline) {
r.y += dc.font->ascent + 1;
XDrawLine(xw.dis, xw.win, dc.gc, r.x, r.y, r.x+r.width-1, r.y);
}
} }
void void
@ -983,25 +994,26 @@ xcursor(int mode) {
void void
draw(int redraw_all) { draw(int redraw_all) {
int x, y; int i, x, y, ox;
int changed, set; Glyph base, new;
char buf[MAXDRAWBUF];
if(redraw_all)
XClearWindow(xw.dis, xw.win);
/* XXX: drawing could be optimised */
for(y = 0; y < term.row; y++) { for(y = 0; y < term.row; y++) {
base = term.line[y][0];
i = ox = 0;
for(x = 0; x < term.col; x++) { for(x = 0; x < term.col; x++) {
changed = term.line[y][x].state & CRupdate; new = term.line[y][x];
set = term.line[y][x].state & CRset; if(!ATTRCMP(base, new) && i < MAXDRAWBUF)
if(redraw_all || changed) { buf[i++] = new.c;
term.line[y][x].state &= ~CRupdate; else {
if(set) xdraws(buf, base, ox, y, i);
xdrawc(x, y, term.line[y][x]); buf[0] = new.c;
else i = 1;
xclear(x, y, x, y); ox = x;
base = new;
} }
} }
xdraws(buf, base, ox, y, i);
} }
xcursor(CSdraw); xcursor(CSdraw);
} }