Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
fade.c File Reference
#include <time.h>
#include <sys/time.h>
#include "internal.h"
Include dependency graph for fade.c:

Go to the source code of this file.

Data Structures

struct  ncfadectx
 

Typedefs

typedef struct ncfadectx ncfadectx
 

Functions

int ncfadectx_iterations (const ncfadectx *nctx)
 
int ncplane_fadein_iteration (ncplane *n, ncfadectx *nctx, int iter, fadecb fader, void *curry)
 
int ncplane_fadeout_iteration (ncplane *n, ncfadectx *nctx, int iter, fadecb fader, void *curry)
 
ncfadectxncfadectx_setup (ncplane *n)
 
void ncfadectx_free (ncfadectx *nctx)
 
int ncplane_fadeout (ncplane *n, const struct timespec *ts, fadecb fader, void *curry)
 
int ncplane_fadein (ncplane *n, const struct timespec *ts, fadecb fader, void *curry)
 
int ncplane_pulse (ncplane *n, const struct timespec *ts, fadecb fader, void *curry)
 

Typedef Documentation

◆ ncfadectx

typedef struct ncfadectx ncfadectx

Function Documentation

◆ ncfadectx_free()

void ncfadectx_free ( ncfadectx nctx)

Definition at line 253 of file fade.c.

253 {
254 if(nctx){
255 free(nctx->channels);
256 free(nctx);
257 }
258}
free(duplicated)
uint64_t * channels
Definition fade.c:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncfadectx_iterations()

int ncfadectx_iterations ( const ncfadectx nctx)

Definition at line 16 of file fade.c.

16 {
17 return nctx->maxsteps;
18}
int maxsteps
Definition fade.c:8

◆ ncfadectx_setup()

ncfadectx * ncfadectx_setup ( ncplane n)

Definition at line 249 of file fade.c.

249 {
250 return ncfadectx_setup_internal(n, NULL);
251}
vopts n
Definition notcurses.h:3502
return NULL
Definition termdesc.h:229

◆ ncplane_fadein()

int ncplane_fadein ( ncplane n,
const struct timespec *  ts,
fadecb  fader,
void *  curry 
)

Definition at line 284 of file fade.c.

284 {
285 ncfadectx* nctx = ncfadectx_setup_internal(n, ts);
286 if(nctx == NULL){
287 struct timespec now;
288 clock_gettime(CLOCK_MONOTONIC, &now);
289 if(fader){
290 fader(ncplane_notcurses(n), n, &now, curry);
291 }else{
292 notcurses_render(ncplane_notcurses(n));
293 }
294 return -1;
295 }
296 int ret = ncplane_fadein_internal(n, fader, nctx, curry);
297 ncfadectx_free(nctx);
298 return ret;
299}
void ncfadectx_free(ncfadectx *nctx)
Definition fade.c:253
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2626
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_fadein_iteration()

int ncplane_fadein_iteration ( ncplane n,
ncfadectx nctx,
int  iter,
fadecb  fader,
void *  curry 
)

Definition at line 109 of file fade.c.

110 {
111 // each time through, we need look each cell back up, due to the
112 // possibility of a resize event :/
113 unsigned dimy, dimx;
114 ncplane_dim_yx(n, &dimy, &dimx);
115 unsigned y;
116 for(y = 0 ; y < nctx->rows && y < dimy ; ++y){
117 for(unsigned x = 0 ; x < nctx->cols && x < dimx; ++x){
118 unsigned r, g, b;
119 ncchannels_fg_rgb8(nctx->channels[nctx->cols * y + x], &r, &g, &b);
120 unsigned br, bg, bb;
121 ncchannels_bg_rgb8(nctx->channels[nctx->cols * y + x], &br, &bg, &bb);
122 nccell* c = &n->fb[dimx * y + x];
123 if(!nccell_fg_default_p(c)){
124 r = r * iter / nctx->maxsteps;
125 g = g * iter / nctx->maxsteps;
126 b = b * iter / nctx->maxsteps;
127 nccell_set_fg_rgb8(c, r, g, b);
128 }
129 if(!nccell_bg_default_p(c)){
130 br = br * iter / nctx->maxsteps;
131 bg = bg * iter / nctx->maxsteps;
132 bb = bb * iter / nctx->maxsteps;
133 nccell_set_bg_rgb8(c, br, bg, bb);
134 }
135 }
136 }
137 uint64_t nextwake = (iter + 1) * nctx->nanosecs_step + nctx->startns;
138 struct timespec sleepspec;
139 sleepspec.tv_sec = nextwake / NANOSECS_IN_SEC;
140 sleepspec.tv_nsec = nextwake % NANOSECS_IN_SEC;
141 int ret = 0;
142 if(fader){
143 ret |= fader(ncplane_notcurses(n), n, &sleepspec, curry);
144 }else{
145 ret |= notcurses_render(ncplane_notcurses(n));
146 // clock_nanosleep() has no love for CLOCK_MONOTONIC_RAW, at least as
147 // of Glibc 2.29 + Linux 5.3 (or FreeBSD 12) :/.
148 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &sleepspec, NULL);
149 }
150 return ret;
151}
const nccell * c
Definition egcpool.h:296
int r
Definition fbuf.h:226
void ncplane_dim_yx(const ncplane *n, unsigned *rows, unsigned *cols)
Definition notcurses.c:301
int y
Definition notcurses.h:1905
int int x
Definition notcurses.h:1905
uint64_t nanosecs_step
Definition fade.c:11
unsigned rows
Definition fade.c:6
uint64_t startns
Definition fade.c:12
unsigned cols
Definition fade.c:7
Here is the call graph for this function:

◆ ncplane_fadeout()

int ncplane_fadeout ( ncplane n,
const struct timespec *  ts,
fadecb  fader,
void *  curry 
)

Definition at line 260 of file fade.c.

260 {
261 ncfadectx* pp = ncfadectx_setup_internal(n, ts);
262 if(!pp){
263 return -1;
264 }
265 struct timespec times;
266 ns_to_timespec(pp->startns, &times);
267 do{
268 uint64_t curns = times.tv_sec * NANOSECS_IN_SEC + times.tv_nsec;
269 int iter = (curns - pp->startns) / pp->nanosecs_step + 1;
270 if(iter > pp->maxsteps){
271 break;
272 }
273 int r = ncplane_fadeout_iteration(n, pp, iter, fader, curry);
274 if(r){
275 ncfadectx_free(pp);
276 return r;
277 }
278 clock_gettime(CLOCK_MONOTONIC, &times);
279 }while(true);
280 ncfadectx_free(pp);
281 return 0;
282}
int ncplane_fadeout_iteration(ncplane *n, ncfadectx *nctx, int iter, fadecb fader, void *curry)
Definition fade.c:174
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_fadeout_iteration()

int ncplane_fadeout_iteration ( ncplane n,
ncfadectx nctx,
int  iter,
fadecb  fader,
void *  curry 
)

Definition at line 174 of file fade.c.

175 {
176 unsigned br, bg, bb;
177 unsigned r, g, b;
178 // each time through, we need look each cell back up, due to the
179 // possibility of a resize event :/
180 unsigned dimy, dimx;
181 ncplane_dim_yx(n, &dimy, &dimx);
182 unsigned y;
183 for(y = 0 ; y < nctx->rows && y < dimy ; ++y){
184 for(unsigned x = 0 ; x < nctx->cols && x < dimx; ++x){
185 nccell* c = &n->fb[dimx * y + x];
186 if(!nccell_fg_default_p(c)){
187 ncchannels_fg_rgb8(nctx->channels[nctx->cols * y + x], &r, &g, &b);
188 r = r * (nctx->maxsteps - iter) / nctx->maxsteps;
189 g = g * (nctx->maxsteps - iter) / nctx->maxsteps;
190 b = b * (nctx->maxsteps - iter) / nctx->maxsteps;
191 nccell_set_fg_rgb8(c, r, g, b);
192 }
193 if(!nccell_bg_default_p(c)){
194 ncchannels_bg_rgb8(nctx->channels[nctx->cols * y + x], &br, &bg, &bb);
195 br = br * (nctx->maxsteps - iter) / nctx->maxsteps;
196 bg = bg * (nctx->maxsteps - iter) / nctx->maxsteps;
197 bb = bb * (nctx->maxsteps - iter) / nctx->maxsteps;
198 nccell_set_bg_rgb8(c, br, bg, bb);
199 }
200 }
201 }
202 nccell* c = &n->basecell;
203 if(!nccell_fg_default_p(c)){
204 ncchannels_fg_rgb8(nctx->channels[nctx->cols * y], &r, &g, &b);
205 r = r * (nctx->maxsteps - iter) / nctx->maxsteps;
206 g = g * (nctx->maxsteps - iter) / nctx->maxsteps;
207 b = b * (nctx->maxsteps - iter) / nctx->maxsteps;
208 nccell_set_fg_rgb8(&n->basecell, r, g, b);
209 }
210 if(!nccell_bg_default_p(c)){
211 ncchannels_bg_rgb8(nctx->channels[nctx->cols * y], &br, &bg, &bb);
212 br = br * (nctx->maxsteps - iter) / nctx->maxsteps;
213 bg = bg * (nctx->maxsteps - iter) / nctx->maxsteps;
214 bb = bb * (nctx->maxsteps - iter) / nctx->maxsteps;
215 nccell_set_bg_rgb8(&n->basecell, br, bg, bb);
216 }
217 uint64_t nextwake = (iter + 1) * nctx->nanosecs_step + nctx->startns;
218 struct timespec sleepspec;
219 sleepspec.tv_sec = nextwake / NANOSECS_IN_SEC;
220 sleepspec.tv_nsec = nextwake % NANOSECS_IN_SEC;
221 int ret;
222 if(fader){
223 ret = fader(ncplane_notcurses(n), n, &sleepspec, curry);
224 }else{
225 ret = notcurses_render(ncplane_notcurses(n));
226 // clock_nanosleep() has no love for CLOCK_MONOTONIC_RAW, at least as
227 // of Glibc 2.29 + Linux 5.3 (or FreeBSD 12) :/.
228 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &sleepspec, NULL);
229 }
230 return ret;
231}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncplane_pulse()

int ncplane_pulse ( ncplane n,
const struct timespec *  ts,
fadecb  fader,
void *  curry 
)

Definition at line 301 of file fade.c.

301 {
302 ncfadectx pp;
303 int ret;
304 if(!notcurses_canfade(ncplane_notcurses(n))){
305 return -1;
306 }
307 if(alloc_ncplane_palette(n, &pp, ts)){
308 return -1;
309 }
310 for(;;){
311 ret = ncplane_fadein_internal(n, fader, &pp, curry);
312 if(ret){
313 break;
314 }
315 ret = ncplane_fadeout(n, ts, fader, curry);
316 if(ret){
317 break;
318 }
319 }
320 free(pp.channels);
321 return ret;
322}
int ncplane_fadeout(ncplane *n, const struct timespec *ts, fadecb fader, void *curry)
Definition fade.c:260
Here is the call graph for this function:
Here is the caller graph for this function: