fade: propagate fader return value

pull/278/head
nick black 5 years ago
parent 23b5078ed1
commit 13c2dc9841
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -108,6 +108,7 @@ int ncplane_fadein(ncplane* n, const struct timespec* ts, fadecb fader){
uint64_t startns = times.tv_sec * NANOSECS_IN_SEC + times.tv_nsec; uint64_t startns = times.tv_sec * NANOSECS_IN_SEC + times.tv_nsec;
// Current time, sampled each iteration // Current time, sampled each iteration
uint64_t curns; uint64_t curns;
int ret = 0;
do{ do{
clock_gettime(CLOCK_MONOTONIC, &times); clock_gettime(CLOCK_MONOTONIC, &times);
curns = times.tv_sec * NANOSECS_IN_SEC + times.tv_nsec; curns = times.tv_sec * NANOSECS_IN_SEC + times.tv_nsec;
@ -142,9 +143,12 @@ int ncplane_fadein(ncplane* n, const struct timespec* ts, fadecb fader){
} }
} }
if(fader){ if(fader){
fader(n->nc, n); ret |= fader(n->nc, n);
}else{ }else{
notcurses_render(n->nc); ret |= notcurses_render(n->nc);
}
if(ret){
break;
} }
uint64_t nextwake = (iter + 1) * nanosecs_step + startns; uint64_t nextwake = (iter + 1) * nanosecs_step + startns;
struct timespec sleepspec; struct timespec sleepspec;
@ -159,10 +163,10 @@ int ncplane_fadein(ncplane* n, const struct timespec* ts, fadecb fader){
} }
}while(true); }while(true);
free(pp.channels); free(pp.channels);
return 0; return ret;
} }
int ncplane_fadeout(struct ncplane* n, const struct timespec* ts, fadecb fader){ int ncplane_fadeout(ncplane* n, const struct timespec* ts, fadecb fader){
planepalette pp; planepalette pp;
if(!n->nc->RGBflag && !n->nc->CCCflag){ // terminal can't fade if(!n->nc->RGBflag && !n->nc->CCCflag){ // terminal can't fade
return -1; return -1;
@ -184,6 +188,7 @@ int ncplane_fadeout(struct ncplane* n, const struct timespec* ts, fadecb fader){
clock_gettime(CLOCK_MONOTONIC, &times); clock_gettime(CLOCK_MONOTONIC, &times);
// Start time in absolute nanoseconds // Start time in absolute nanoseconds
uint64_t startns = times.tv_sec * NANOSECS_IN_SEC + times.tv_nsec; uint64_t startns = times.tv_sec * NANOSECS_IN_SEC + times.tv_nsec;
int ret = 0;
do{ do{
unsigned br, bg, bb; unsigned br, bg, bb;
unsigned r, g, b; unsigned r, g, b;
@ -233,9 +238,12 @@ int ncplane_fadeout(struct ncplane* n, const struct timespec* ts, fadecb fader){
cell_set_bg_rgb(&n->basecell, br, bg, bb); cell_set_bg_rgb(&n->basecell, br, bg, bb);
} }
if(fader){ if(fader){
fader(n->nc, n); ret = fader(n->nc, n);
}else{ }else{
notcurses_render(n->nc); ret = notcurses_render(n->nc);
}
if(ret){
break;
} }
uint64_t nextwake = (iter + 1) * nanosecs_step + startns; uint64_t nextwake = (iter + 1) * nanosecs_step + startns;
struct timespec sleepspec; struct timespec sleepspec;
@ -250,6 +258,20 @@ int ncplane_fadeout(struct ncplane* n, const struct timespec* ts, fadecb fader){
} }
}while(true); }while(true);
free(pp.channels); free(pp.channels);
return 0; return ret;
} }
int ncplane_pulse(ncplane* n, const struct timespec* ts, fadecb fader){
int ret;
for(;;){
ret = ncplane_fadein(n, ts, fader);
if(ret){
break;
}
ret = ncplane_fadeout(n, ts, fader);
if(ret){
break;
}
}
return ret;
}

Loading…
Cancel
Save