ref: a62cbf2bafdc78059301ce61f62b152fdb022b80
parent: 1146757bfd9088ff4955a1d896ec7b5d4c894f2d
author: Sigrid Haflínudóttir <[email protected]>
date: Wed May 27 08:09:16 EDT 2020
redraw less, fix menu disappearing
--- a/zuke.c
+++ b/zuke.c
@@ -16,6 +16,11 @@
Cforwardfast,
Cbackwardfast,
+ Rcover = 1<<0,
+ Rprogress = 1<<1,
+ Rlist = 1<<2,
+ Rall = Rcover|Rprogress|Rlist,
+
Everror = 1,
Evready,
@@ -112,7 +117,7 @@
}
static void
-redraw(void)
+redraw(int flags)
{
Image *col;
Point p, sp;
@@ -124,94 +129,96 @@
return;
lockdisplay(display);
- draw(screen, screen->r, colors[Dback].im, nil, ZP);
+ if(flags & Rlist){
+ draw(screen, screen->r, colors[Dback].im, nil, ZP);
- scrollsz = Dy(screen->r) / f->height - 1;
- adjustcolumns();
- left = screen->r.min.x;
- if(scrollsz < plnum){ /* add a scrollbar */
- p.x = sp.x = screen->r.min.x + Scrollwidth;
- p.y = screen->r.min.y;
- sp.y = screen->r.max.y;
- line(screen, p, sp, Endsquare, Endsquare, 0, colors[Dfmed].im, ZP);
+ scrollsz = Dy(screen->r) / f->height - 1;
+ adjustcolumns();
+ left = screen->r.min.x;
+ if(scrollsz < plnum){ /* add a scrollbar */
+ p.x = sp.x = screen->r.min.x + Scrollwidth;
+ p.y = screen->r.min.y;
+ sp.y = screen->r.max.y;
+ line(screen, p, sp, Endsquare, Endsquare, 0, colors[Dfmed].im, ZP);
- r = screen->r;
- r.max.x = r.min.x + Scrollwidth - 1;
- r.min.x += 1;
- if(scroll < 1)
- scrollcenter = 0;
- else
- scrollcenter = (Dy(screen->r)-Scrollheight*5/4)*scroll / (plnum - scrollsz);
- r.min.y += scrollcenter + Scrollheight/4;
- r.max.y = r.min.y + Scrollheight;
- draw(screen, r, colors[Dfmed].im, nil, ZP);
+ r = screen->r;
+ r.max.x = r.min.x + Scrollwidth - 1;
+ r.min.x += 1;
+ if(scroll < 1)
+ scrollcenter = 0;
+ else
+ scrollcenter = (Dy(screen->r)-Scrollheight*5/4)*scroll / (plnum - scrollsz);
+ r.min.y += scrollcenter + Scrollheight/4;
+ r.max.y = r.min.y + Scrollheight;
+ draw(screen, r, colors[Dfmed].im, nil, ZP);
- left += Scrollwidth + 4;
- }
+ left += Scrollwidth + 4;
+ }
- p.x = sp.x = left + colwidth[0] + 4;
- p.y = 0;
- sp.y = screen->r.max.y;
- line(screen, p, sp, Endsquare, Endsquare, 0, colors[Dfmed].im, ZP);
+ p.x = sp.x = left + colwidth[0] + 4;
+ p.y = 0;
+ sp.y = screen->r.max.y;
+ line(screen, p, sp, Endsquare, Endsquare, 0, colors[Dfmed].im, ZP);
- p.x = sp.x = left + colwidth[0] + 8 + colwidth[1] + 4;
- p.y = 0;
- sp.y = screen->r.max.y;
- line(screen, p, sp, Endsquare, Endsquare, 0, colors[Dfmed].im, ZP);
+ p.x = sp.x = left + colwidth[0] + 8 + colwidth[1] + 4;
+ p.y = 0;
+ sp.y = screen->r.max.y;
+ line(screen, p, sp, Endsquare, Endsquare, 0, colors[Dfmed].im, ZP);
- sp.x = sp.y = 0;
- p.x = left + 2;
- p.y = screen->r.min.y + 2;
+ sp.x = sp.y = 0;
+ p.x = left + 2;
+ p.y = screen->r.min.y + 2;
- for(i = scroll; i < plnum; i++, p.y += f->height){
- if(i < 0)
- continue;
- if(p.y > screen->r.max.y)
- break;
+ for(i = scroll; i < plnum; i++, p.y += f->height){
+ if(i < 0)
+ continue;
+ if(p.y > screen->r.max.y)
+ break;
- if(pcur == i){
- sel.min.x = left;
- sel.min.y = p.y;
- sel.max.x = screen->r.max.x;
- sel.max.y = p.y + f->height;
- draw(screen, sel, colors[Dbinv].im, nil, ZP);
- col = colors[Dfinv].im;
- }else{
- col = colors[pcurplaying == i ? Dfhigh : Dfmed].im;
- }
+ if(pcur == i){
+ sel.min.x = left;
+ sel.min.y = p.y;
+ sel.max.x = screen->r.max.x;
+ sel.max.y = p.y + f->height;
+ draw(screen, sel, colors[Dbinv].im, nil, ZP);
+ col = colors[Dfinv].im;
+ }else{
+ col = colors[pcurplaying == i ? Dfhigh : Dfmed].im;
+ }
- sel = screen->r;
- r = screen->r;
+ sel = screen->r;
+ r = screen->r;
- p.x = left + 2;
- sel.max.x = p.x + colwidth[0];
- replclipr(screen, 0, sel);
- string(screen, p, col, sp, f, pl[i].artist[0]);
- p.x += colwidth[0] + 8;
- sel.min.x = p.x;
- sel.max.x = p.x + colwidth[1];
- replclipr(screen, 0, sel);
- string(screen, p, col, sp, f, pl[i].album);
- p.x += colwidth[1] + 8;
- sel.min.x = p.x;
- sel.max.x = p.x + colwidth[2];
- replclipr(screen, 0, sel);
- string(screen, p, col, sp, f, pl[i].title);
+ p.x = left + 2;
+ sel.max.x = p.x + colwidth[0];
+ replclipr(screen, 0, sel);
+ string(screen, p, col, sp, f, pl[i].artist[0]);
+ p.x += colwidth[0] + 8;
+ sel.min.x = p.x;
+ sel.max.x = p.x + colwidth[1];
+ replclipr(screen, 0, sel);
+ string(screen, p, col, sp, f, pl[i].album);
+ p.x += colwidth[1] + 8;
+ sel.min.x = p.x;
+ sel.max.x = p.x + colwidth[2];
+ replclipr(screen, 0, sel);
+ string(screen, p, col, sp, f, pl[i].title);
- replclipr(screen, 0, r);
+ replclipr(screen, 0, r);
- if(pcurplaying == i){
- Point rightp, leftp;
- leftp.y = rightp.y = p.y - 1;
- leftp.x = left;
- rightp.x = screen->r.max.x;
- line(screen, leftp, rightp, 0, 0, 0, colors[Dfmed].im, sp);
- leftp.y = rightp.y = p.y + f->height;
- line(screen, leftp, rightp, 0, 0, 0, colors[Dfmed].im, sp);
+ if(pcurplaying == i){
+ Point rightp, leftp;
+ leftp.y = rightp.y = p.y - 1;
+ leftp.x = left;
+ rightp.x = screen->r.max.x;
+ line(screen, leftp, rightp, 0, 0, 0, colors[Dfmed].im, sp);
+ leftp.y = rightp.y = p.y + f->height;
+ line(screen, leftp, rightp, 0, 0, 0, colors[Dfmed].im, sp);
+ }
}
}
- if(cover != nil){
+ if(cover != nil && (flags & Rcover) != 0){
r = screen->r;
r.min.x = r.max.x - cover->r.max.x - 8;
r.min.y = r.max.y - cover->r.max.y - 8 - f->height - 4;
@@ -223,17 +230,19 @@
draw(screen, r, cover, nil, ZP);
}
- if(pcurplaying >= 0)
- snprint(tmp, sizeof(tmp), "%P/%P %d%%", (int)(byteswritten/Bps), pl[pcurplaying].duration/1000, volume);
- else
- snprint(tmp, sizeof(tmp), "%d%%", volume);
- r = screen->r;
- r.min.x = r.max.x - stringwidth(f, tmp) - 4;
- r.min.y = r.max.y - f->height - 4;
- draw(screen, r, colors[Dblow].im, nil, ZP);
- r.min.x += 2;
- r.min.y += 2;
- string(screen, r.min, colors[Dfhigh].im, sp, f, tmp);
+ if(flags & Rprogress){
+ if(pcurplaying >= 0)
+ snprint(tmp, sizeof(tmp), "%P/%P %d%%", (int)(byteswritten/Bps), pl[pcurplaying].duration/1000, volume);
+ else
+ snprint(tmp, sizeof(tmp), "%d%%", volume);
+ r = screen->r;
+ r.min.x = r.max.x - stringwidth(f, tmp) - 4;
+ r.min.y = r.max.y - f->height - 4;
+ draw(screen, r, colors[Dblow].im, nil, ZP);
+ r.min.x += 2;
+ r.min.y += 2;
+ string(screen, r.min, colors[Dfhigh].im, sp, f, tmp);
+ }
flushimage(display, 1);
unlockdisplay(display);
@@ -242,7 +251,7 @@
void
themechanged(void)
{
- redraw();
+ redraw(Rall);
}
static void
@@ -451,7 +460,7 @@
pcurplaying = player->pcur;
if(c != Cbackward && c != Cbackwardfast)
- redraw();
+ redraw(Rall);
while(1){
n = Relbufsz;
@@ -465,7 +474,7 @@
if(player->img != nil && nbrecv(player->img, &thiscover) != 0){
freeimage(cover);
cover = thiscover;
- redraw();
+ redraw(Rcover);
player->img = nil;
}
c = nbrecvul(player->ctl);
@@ -506,7 +515,7 @@
}
byteswritten += n;
if(bytesfrom == byteswritten || (byteswritten/Bps > (byteswritten-n)/Bps))
- redraw();
+ redraw(Rprogress);
}
if(n == 0){ /* seeking backwards or end of the song */
@@ -698,7 +707,7 @@
for(s--; s != plraw; s--){
if(memcmp(s, "\0# ", 3) == 0 && isdigit(s[3])){
pcur = atoi(s+3);
- redraw();
+ redraw(Rall);
return;
}
}
@@ -806,19 +815,28 @@
}
themeinit();
- redraw();
+ redraw(Rall);
oldbuttons = 0;
scrolling = 0;
for(;;){
+ev:
oldpcur = pcur;
switch(alt(a)){
case 0:
- if(oldbuttons == 0 && m.buttons == 2 && m.xy.x <= screen->r.min.x+Scrollwidth)
- scrolling = 1;
- else if(m.buttons != 2)
+ if(m.buttons == 4){
+ n = menuhit(3, mctl, &menu3, nil);
+ if(n == 0)
+ proccreate(themeproc, nil, 4096);
+ else if(n == 1)
+ goto end;
+ goto ev;
+ }
+ if(m.buttons != 2)
scrolling = 0;
+ else if(oldbuttons == 0 && m.xy.x <= screen->r.min.x+Scrollwidth)
+ scrolling = 1;
oldbuttons = m.buttons;
if(m.buttons == 0)
break;
@@ -831,8 +849,8 @@
scroll = plnum-scrollsz-1;
if(scroll < 0)
scroll = 0;
- redraw();
- }else if(m.buttons != 4){
+ redraw(Rall);
+ }else if(m.buttons == 1 || m.buttons == 2){
pcur = scroll + (m.xy.y - screen->r.min.y)/f->height;
if(m.buttons == 2){
stop(playercurr);
@@ -839,17 +857,12 @@
playercurr = newplayer(pcur, 1);
start(playercurr);
}
- }else if((n = menuhit(3, mctl, &menu3, nil)) >= 0){
- if(n == 0)
- proccreate(themeproc, redraw, 4096);
- else if(n == 1)
- goto end;
}
break;
case 1: /* resize */
if(getwindow(display, Refnone) < 0)
sysfatal("getwindow: %r");
- redraw();
+ redraw(Rall);
break;
case 2:
switch(key){
@@ -918,11 +931,11 @@
break;
case '-':
chvolume(-1);
- redraw();
+ redraw(Rprogress);
break;
case '+':
chvolume(+1);
- redraw();
+ redraw(Rprogress);
break;
case 's':
stop(playercurr);
@@ -930,7 +943,7 @@
pcurplaying = -1;
freeimage(cover);
cover = nil;
- redraw();
+ redraw(Rall);
break;
case 'p':
toggle(playercurr);
@@ -958,7 +971,7 @@
scroll = 0;
if(pcur != oldpcur)
- redraw();
+ redraw(Rall);
}
}