popup: one text drawing call; drop what the draw thread never reaches
font.c exported three wrappers for one function, and the fit == -1 mode existed only for the tests; textdraw() takes fit and colour. win.c tested the empty picture in the thread and again in winshow, interned two atoms by hand next to getatom(), kept a consumer-side drain that the producer's already guarantees never finds anything, zeroed ten globals before returning from the only thread that read them, and re-checked sizes that resizebacking had just established. The page marker is laid out once and drawn from the layout instead of being recomputed.
This commit is contained in:
@@ -117,9 +117,7 @@ void
|
||||
popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
||||
{
|
||||
char buf[32];
|
||||
Str mark;
|
||||
vlong width;
|
||||
int first, i, markrow, nall, nmark, npre, pad, total, y;
|
||||
int first, i, markrow, nall, nmark, npre, pad, total, width, y;
|
||||
|
||||
memset(p, 0, sizeof *p);
|
||||
p->prey = -1;
|
||||
@@ -128,7 +126,6 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
||||
p->markx = -1;
|
||||
p->marky = -1;
|
||||
p->sely = -1;
|
||||
p->row0 = 0;
|
||||
pad = PopupPad;
|
||||
nall = min(max(dc->nkouho, 0), Maxdisp);
|
||||
npre = dc->pre.n != 0;
|
||||
@@ -163,13 +160,14 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
||||
|
||||
width = PopupBasew;
|
||||
if(npre)
|
||||
width = max(width, (vlong)textwidth(&dc->pre) + 2*PopupPad);
|
||||
width = max(width, textwidth(&dc->pre) + 2*PopupPad);
|
||||
for(i = 0; i < p->n; i++)
|
||||
width = max(width, (vlong)textwidth(&dc->kouho[p->row0+i]) +
|
||||
width = max(width, textwidth(&dc->kouho[p->row0+i]) +
|
||||
PopupNumw + 2*PopupPad);
|
||||
if(nmark != 0){
|
||||
sinit(&mark, buf, nmark);
|
||||
width = max(width, (vlong)textwidth(&mark) + 2*PopupPad);
|
||||
if(markrow){
|
||||
sinit(&p->mark, buf, nmark);
|
||||
p->markw = textwidth(&p->mark);
|
||||
width = max(width, p->markw + 2*PopupPad);
|
||||
}
|
||||
p->w = min(width, areaw);
|
||||
|
||||
@@ -195,7 +193,7 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
||||
p->textx = PopupPad + PopupNumw;
|
||||
p->textw = max(p->w - PopupPad - p->textx, 0);
|
||||
if(markrow){
|
||||
p->markw = min(textwidth(&mark), max(p->w - 2*PopupPad, 0));
|
||||
p->markw = min(p->markw, max(p->w - 2*PopupPad, 0));
|
||||
p->markx = p->w - PopupPad - p->markw;
|
||||
}
|
||||
p->selx = PopupPad;
|
||||
@@ -207,10 +205,9 @@ popuplayout(Drawcmd *dc, int areaw, int areah, Popup *p)
|
||||
void
|
||||
popupdraw(u32int *img, Drawcmd *dc, Popup *p)
|
||||
{
|
||||
char buf[32];
|
||||
Str mark, num;
|
||||
Str num;
|
||||
u32int color;
|
||||
int first, i, j, nmark, total, y;
|
||||
int i, j, y;
|
||||
|
||||
if(img == nil || p->n < 0 || p->n > Maxdisp ||
|
||||
p->row0 < 0 || p->row0 + p->n > dc->nkouho ||
|
||||
@@ -218,8 +215,8 @@ popupdraw(u32int *img, Drawcmd *dc, Popup *p)
|
||||
return;
|
||||
fill(img, p->w*p->h, Colbg);
|
||||
if(p->prey >= 0)
|
||||
textdrawfit(img, p->w, p->h, PopupPad, p->prey,
|
||||
max(p->w - 2*PopupPad, 0), &dc->pre);
|
||||
textdraw(img, p->w, p->h, PopupPad, p->prey,
|
||||
max(p->w - 2*PopupPad, 0), Colfg, &dc->pre);
|
||||
if(p->sepy >= 0)
|
||||
fillrect(img, p->w, p->h, PopupPad, p->sepy,
|
||||
p->w - 2*PopupPad, PopupSep, Colsep);
|
||||
@@ -231,20 +228,15 @@ popupdraw(u32int *img, Drawcmd *dc, Popup *p)
|
||||
color = j == dc->sel ? Colselfg : Colfg;
|
||||
sclear(&num);
|
||||
sputr(&num, '1' + j + Asciitofull);
|
||||
textdrawfitcolor(img, p->w, p->h, p->numx, y,
|
||||
min(PopupNumw,
|
||||
max(p->w - PopupPad - p->numx, 0)), color, &num);
|
||||
textdrawfitcolor(img, p->w, p->h, p->textx, y,
|
||||
p->textw, color, &dc->kouho[j]);
|
||||
}
|
||||
first = dc->first + p->row0;
|
||||
total = max(dc->total, dc->first + dc->nkouho);
|
||||
nmark = pagemarker(buf, sizeof buf, first, p->n, total);
|
||||
if(nmark != 0 && p->marky >= 0){
|
||||
sinit(&mark, buf, nmark);
|
||||
textdrawfit(img, p->w, p->h, p->markx, p->marky,
|
||||
p->markw, &mark);
|
||||
textdraw(img, p->w, p->h, p->numx, y,
|
||||
min(PopupNumw, max(p->w - PopupPad - p->numx, 0)),
|
||||
color, &num);
|
||||
textdraw(img, p->w, p->h, p->textx, y, p->textw, color,
|
||||
&dc->kouho[j]);
|
||||
}
|
||||
if(p->marky >= 0)
|
||||
textdraw(img, p->w, p->h, p->markx, p->marky, p->markw,
|
||||
Colfg, &p->mark);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user