restructure progbar logic to prep for highres #1209

This commit is contained in:
nick black 2020-12-13 11:34:19 -05:00
parent 4984903d61
commit d5574cab9a
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 21 additions and 10 deletions

View File

@ -10,7 +10,7 @@ fader(struct notcurses* nc, struct ncplane* ncp, void* curry){
int startx = (cols - (centercols - 2)) / 2;
for(int x = startx ; x < startx + centercols - 2 ; ++x){
ncplane_set_fg_rgb8(ncp, 0xd0, 0xf0, 0xd0);
if(ncplane_putwc_yx(ncp, rows - 11, x, x % 2 == *flipmode % 2 ? L'' : L'') <= 0){
if(ncplane_putwc_yx(ncp, rows - 10, x, x % 2 == *flipmode % 2 ? L'' : L'') <= 0){
return -1;
}
}

View File

@ -27,32 +27,43 @@ progbar_redraw(ncprogbar* n){
int dimy, dimx;
ncplane_dim_yx(ncprogbar_plane(n), &dimy, &dimx);
const bool horizontal = dimx > dimy;
int range, delt;
int range, delt, pos;
if(horizontal){
range = dimx;
delt = -1;
delt = 1;
pos = 0;
}else{
range = dimy;
delt = -1;
pos = range - 1;
}
ncplane_set_channels(ncprogbar_plane(n), n->channels);
double progress = n->progress * range;
if(n->retrograde){
progress = range - progress;
delt *= -1;
}
//fprintf(stderr, "progress: %g range: %d delt: %d\n", progress, range, delt);
while(progress > 0 && progress < range){
if(pos){
pos = 0;
}else{
pos = range - 1;
}
if(horizontal){
if(ncplane_putegc_yx(ncprogbar_plane(n), 0, progress, "", NULL) <= 0){
progress = range - progress;
}
}else if(!horizontal){
progress = range - progress;
}
while((delt < 0 && pos > progress) || (delt > 0 && pos < progress)){
//fprintf(stderr, "progress: %g pos: %d range: %d delt: %d\n", progress, pos, range, delt);
if(horizontal){
if(ncplane_putegc_yx(ncprogbar_plane(n), 0, pos, "", NULL) <= 0){
return -1;
}
}else{
if(ncplane_putegc_yx(ncprogbar_plane(n), range - progress, 0, "", NULL) <= 0){
if(ncplane_putegc_yx(ncprogbar_plane(n), pos, 0, "", NULL) <= 0){
return -1;
}
}
progress += delt;
pos += delt;
}
return 0;
}