rio: colors, flicker reduction, refresh after mouse close

allocate all the colors in iconinit(), remove unused ones
like grey. rename darkgrey to paletextcol because thats
what it is used for. new approach to window image allocation.
we allocate the window with DNofill and let the window fill
itself. this reduces flickering especially with (-b) option
and makes rio resize feel a lot faster.

wrefresh() didnt work. now fixed.
This commit is contained in:
cinap_lenrek 2012-10-20 15:51:32 +02:00
parent c33732a530
commit 8057e48ae1
7 changed files with 63 additions and 75 deletions

View file

@ -317,9 +317,19 @@ Cursor sightcursor;
Cursor whitearrow; Cursor whitearrow;
Cursor query; Cursor query;
Cursor *corners[9]; Cursor *corners[9];
Image *background; Image *background;
Image *lightgrey; Image *cols[NCOL];
Image *red; Image *titlecol;
Image *lighttitlecol;
Image *dholdcol;
Image *holdcol;
Image *lightholdcol;
Image *paleholdcol;
Image *paletextcol;
Image *sizecol;
int reverse; /* there are no pastel paints in the dungeons and dragons world -- rob pike */
Window **window; Window **window;
Window *wkeyboard; /* window of simulated keyboard */ Window *wkeyboard; /* window of simulated keyboard */
int nwindow; int nwindow;

View file

@ -176,5 +176,28 @@ void
iconinit(void) iconinit(void)
{ {
background = allocimage(display, Rect(0,0,1,1), RGB24, 1, 0x777777FF); background = allocimage(display, Rect(0,0,1,1), RGB24, 1, 0x777777FF);
red = allocimage(display, Rect(0,0,1,1), RGB24, 1, 0xDD0000FF);
/* greys are multiples of 0x11111100+0xFF, 14* being palest */
cols[BACK] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xFFFFFFFF^reverse);
cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF^reverse);
cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF^reverse);
cols[TEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
cols[HTEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
if(!reverse) {
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen);
lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreygreen);
} else {
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPurpleblue);
lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF);;
}
dholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue);
lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreyblue);
paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreyblue);
paletextcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
sizecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DRed);
if(reverse == 0)
holdcol = dholdcol;
else
holdcol = paleholdcol;
} }

View file

@ -46,7 +46,6 @@ Channel* initkbd(void);
char *fontname; char *fontname;
int mainpid; int mainpid;
int reverse;
enum enum
{ {
@ -228,7 +227,7 @@ threadmain(int argc, char *argv[])
r = screen->r; r = screen->r;
r.max.x = r.min.x+300; r.max.x = r.min.x+300;
r.max.y = r.min.y+80; r.max.y = r.min.y+80;
i = allocwindow(wscreen, r, Refbackup, DWhite); i = allocwindow(wscreen, r, Refbackup, DNofill);
wkeyboard = new(i, FALSE, scrolling, 0, nil, "/bin/rc", kbdargv); wkeyboard = new(i, FALSE, scrolling, 0, nil, "/bin/rc", kbdargv);
if(wkeyboard == nil) if(wkeyboard == nil)
error("can't create keyboard window"); error("can't create keyboard window");
@ -653,10 +652,10 @@ resized(void)
break; break;
incref(w); incref(w);
if(j < nhidden){ if(j < nhidden){
im = allocimage(display, r, screen->chan, 0, DWhite); im = allocimage(display, r, screen->chan, 0, DNofill);
r = ZR; r = ZR;
} else } else
im = allocwindow(wscreen, r, Refbackup, DWhite); im = allocwindow(wscreen, r, Refbackup, DNofill);
if(im) if(im)
wsendctlmesg(w, Reshaped, r, im); wsendctlmesg(w, Reshaped, r, im);
wclose(w); wclose(w);
@ -846,12 +845,13 @@ sweep(void)
p = onscreen(mouse->xy); p = onscreen(mouse->xy);
r = canonrect(Rpt(p0, p)); r = canonrect(Rpt(p0, p));
if(Dx(r)>5 && Dy(r)>5){ if(Dx(r)>5 && Dy(r)>5){
i = allocwindow(wscreen, r, Refnone, 0xEEEEEEFF); /* grey */ i = allocwindow(wscreen, r, Refnone, DNofill);
freeimage(oi); freeimage(oi);
if(i == nil) if(i == nil)
goto Rescue; goto Rescue;
oi = i; oi = i;
border(i, r, Selborder, red, ZP); border(i, r, Selborder, sizecol, ZP);
draw(i, insetrect(r, Selborder), cols[BACK], nil, ZP);
flushimage(display, 1); flushimage(display, 1);
} }
} }
@ -861,11 +861,10 @@ sweep(void)
if(i==nil || Dx(i->r)<100 || Dy(i->r)<3*font->height) if(i==nil || Dx(i->r)<100 || Dy(i->r)<3*font->height)
goto Rescue; goto Rescue;
oi = i; oi = i;
i = allocwindow(wscreen, oi->r, Refbackup, DWhite); i = allocwindow(wscreen, oi->r, Refbackup, DNofill);
freeimage(oi); freeimage(oi);
if(i == nil) if(i == nil)
goto Rescue; goto Rescue;
border(i, r, Selborder, red, ZP);
cornercursor(input, mouse->xy, 1); cornercursor(input, mouse->xy, 1);
goto Return; goto Return;
@ -890,7 +889,9 @@ drawedge(Image **bp, Rectangle r)
originwindow(b, r.min, r.min); originwindow(b, r.min, r.min);
else{ else{
freeimage(b); freeimage(b);
*bp = allocwindow(wscreen, r, Refbackup, DRed); b = allocwindow(wscreen, r, Refbackup, DNofill);
if(b != nil) draw(b, r, sizecol, nil, ZP);
*bp = b;
} }
} }
@ -944,7 +945,7 @@ drag(Window *w, Rectangle *rp)
moveto(mousectl, mouse->xy); /* force cursor update; ugly */ moveto(mousectl, mouse->xy); /* force cursor update; ugly */
menuing = FALSE; menuing = FALSE;
flushimage(display, 1); flushimage(display, 1);
if(mouse->buttons!=0 || (ni=allocwindow(wscreen, r, Refbackup, DWhite))==nil){ if(mouse->buttons!=0 || (ni=allocwindow(wscreen, r, Refbackup, DNofill))==nil){
moveto(mousectl, om); moveto(mousectl, om);
while(mouse->buttons) while(mouse->buttons)
readmouse(mousectl); readmouse(mousectl);
@ -1023,7 +1024,6 @@ whichrect(Rectangle r, Point p, int which)
Image* Image*
bandsize(Window *w) bandsize(Window *w)
{ {
Image *i;
Rectangle r, or; Rectangle r, or;
Point p, startp; Point p, startp;
int which, but; int which, but;
@ -1060,11 +1060,7 @@ bandsize(Window *w)
} }
if(abs(p.x-startp.x)+abs(p.y-startp.y) <= 1) if(abs(p.x-startp.x)+abs(p.y-startp.y) <= 1)
return nil; return nil;
i = allocwindow(wscreen, or, Refbackup, DWhite); return allocwindow(wscreen, or, Refbackup, DNofill);
if(i == nil)
return nil;
border(i, r, Selborder, red, ZP);
return i;
} }
Window* Window*
@ -1157,7 +1153,7 @@ whide(Window *w)
if(nhidden >= nelem(hidden)) if(nhidden >= nelem(hidden))
return 0; return 0;
incref(w); incref(w);
i = allocimage(display, w->screenr, w->i->chan, 0, DWhite); i = allocimage(display, w->screenr, w->i->chan, 0, DNofill);
if(i){ if(i){
if(w == input) if(w == input)
input = nil; input = nil;
@ -1180,7 +1176,7 @@ wunhide(Window *w)
if(j == nhidden) if(j == nhidden)
return -1; /* not hidden */ return -1; /* not hidden */
incref(w); incref(w);
i = allocwindow(wscreen, w->i->r, Refbackup, DWhite); i = allocwindow(wscreen, w->i->r, Refbackup, DNofill);
if(i){ if(i){
--nhidden; --nhidden;
memmove(hidden+j, hidden+j+1, (nhidden-j)*sizeof(Window*)); memmove(hidden+j, hidden+j+1, (nhidden-j)*sizeof(Window*));

View file

@ -21,7 +21,7 @@ scrtemps(void)
if(scrtmp) if(scrtmp)
return; return;
h = BIG*Dy(screen->r); h = BIG*Dy(screen->r);
scrtmp = allocimage(display, Rect(0, 0, 32, h), screen->chan, 0, DWhite); scrtmp = allocimage(display, Rect(0, 0, 32, h), screen->chan, 0, DNofill);
if(scrtmp == nil) if(scrtmp == nil)
error("scrtemps"); error("scrtemps");
} }
@ -70,7 +70,7 @@ wscrdraw(Window *w)
scrtemps(); scrtemps();
if(w->i == nil) if(w->i == nil)
error("scrdraw"); return;
r = w->scrollr; r = w->scrollr;
b = scrtmp; b = scrtmp;
r1 = r; r1 = r;

View file

@ -330,14 +330,13 @@ wctlnew(Rectangle rect, char *arg, int pid, int hideit, int scrollit, char *dir,
argv[3] = nil; argv[3] = nil;
} }
if(hideit) if(hideit)
i = allocimage(display, rect, screen->chan, 0, DWhite); i = allocimage(display, rect, screen->chan, 0, DNofill);
else else
i = allocwindow(wscreen, rect, Refbackup, DWhite); i = allocwindow(wscreen, rect, Refbackup, DNofill);
if(i == nil){ if(i == nil){
strcpy(err, Ewalloc); strcpy(err, Ewalloc);
return -1; return -1;
} }
border(i, rect, Selborder, red, ZP);
new(i, hideit, scrollit, pid, dir, "/bin/rc", argv); new(i, hideit, scrollit, pid, dir, "/bin/rc", argv);
@ -366,12 +365,11 @@ wctlcmd(Window *w, Rectangle r, int cmd, char *err)
} }
if(eqrect(r, w->screenr)) if(eqrect(r, w->screenr))
return 1; return 1;
i = allocwindow(wscreen, r, Refbackup, DWhite); i = allocwindow(wscreen, r, Refbackup, DNofill);
if(i == nil){ if(i == nil){
strcpy(err, Ewalloc); strcpy(err, Ewalloc);
return -1; return -1;
} }
border(i, r, Selborder, red, ZP);
wsendctlmesg(w, Reshaped, i->r, i); wsendctlmesg(w, Reshaped, i->r, i);
return 1; return 1;
case Scroll: case Scroll:

View file

@ -21,21 +21,9 @@ enum
MinWater = 20000, /* room to leave available when reallocating */ MinWater = 20000, /* room to leave available when reallocating */
}; };
extern int reverse; /* there are no pastel paints in the dungeons and dragons world -- rob pike */
static int topped; static int topped;
static int id; static int id;
static Image *cols[NCOL];
static Image *grey;
static Image *darkgrey;
static Cursor *lastcursor; static Cursor *lastcursor;
static Image *titlecol;
static Image *lighttitlecol;
static Image *dholdcol;
static Image *holdcol;
static Image *lightholdcol;
static Image *paleholdcol;
Window* Window*
wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling) wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
@ -43,31 +31,6 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
Window *w; Window *w;
Rectangle r; Rectangle r;
if(cols[0] == nil){
/* greys are multiples of 0x11111100+0xFF, 14* being palest */
grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF^reverse);
darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
cols[BACK] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xFFFFFFFF^reverse);
cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF^reverse);
cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF);
cols[TEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
cols[HTEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
if(reverse == 0) {
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen);
lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreygreen);
} else {
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPurpleblue);
lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
}
dholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue);
lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreyblue);
paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreyblue);
if(reverse == 0)
holdcol = dholdcol;
else
holdcol = paleholdcol;
}
w = emalloc(sizeof(Window)); w = emalloc(sizeof(Window));
w->screenr = i->r; w->screenr = i->r;
r = insetrect(i->r, Selborder+1); r = insetrect(i->r, Selborder+1);
@ -162,16 +125,15 @@ wresize(Window *w, Image *i, int move)
} }
void void
wrefresh(Window *w, Rectangle) wrefresh(Window *w, Rectangle r)
{ {
/* BUG: rectangle is ignored */ /* BUG: rectangle is ignored */
if(w == input) if(w == input)
wborder(w, Selborder); wborder(w, Selborder);
else else
wborder(w, Unselborder); wborder(w, Unselborder);
if(w->mouseopen) r = insetrect(w->i->r, Selborder);
return; draw(w->i, r, w->cols[BACK], nil, w->entire.min);
draw(w->i, insetrect(w->i->r, Borderwidth), w->cols[BACK], nil, w->i->r.min);
w->ticked = 0; w->ticked = 0;
if(w->p0 > 0) if(w->p0 > 0)
frdrawsel(w, frptofchar(w, 0), 0, w->p0, 0); frdrawsel(w, frptofchar(w, 0), 0, w->p0, 0);
@ -760,7 +722,7 @@ wsetcols(Window *w)
if(w == input) if(w == input)
w->cols[TEXT] = w->cols[HTEXT] = cols[TEXT]; w->cols[TEXT] = w->cols[HTEXT] = cols[TEXT];
else else
w->cols[TEXT] = w->cols[HTEXT] = darkgrey; w->cols[TEXT] = w->cols[HTEXT] = paletextcol;
} }
void void

View file

@ -183,11 +183,10 @@ xfidattach(Xfid *x)
err = Ebadrect; err = Ebadrect;
else{ else{
if(hideit) if(hideit)
i = allocimage(display, r, screen->chan, 0, DWhite); i = allocimage(display, r, screen->chan, 0, DNofill);
else else
i = allocwindow(wscreen, r, Refbackup, DWhite); i = allocwindow(wscreen, r, Refbackup, DNofill);
if(i){ if(i){
border(i, r, Selborder, display->black, ZP);
if(pid == 0) if(pid == 0)
pid = -1; /* make sure we don't pop a shell! - UGH */ pid = -1; /* make sure we don't pop a shell! - UGH */
w = new(i, hideit, scrollit, pid, nil, nil, nil); w = new(i, hideit, scrollit, pid, nil, nil, nil);