Skip to content

Commit

Permalink
pixelplots: paint only through egcidx #1382
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Aug 22, 2021
1 parent 242ec7a commit 1571bfe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ rearrangements of Notcurses.
* 2.3.17 (not yet released)
* Added `notcurses_enter_alternate_screen()` and
`notcurses_leave_alternate_screen()`.
* Added `ncplane_boundlist()`.
* Plots now support `NCBLIT_PIXEL`!

* 2.3.16 (2021-08-19)
* Fix `ncdirect_set_*_rgb()` for the case where an emulator has fewer than
Expand Down
3 changes: 3 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,9 @@ int ncplane_resize_realign(struct ncplane* n);
struct ncplane* ncplane_parent(struct ncplane* n);
const struct ncplane* ncplane_parent_const(const struct ncplane* n);

// Get the head of the list of planes bound to 'n'.
struct ncplane* ncplane_boundlist(struct ncplane* n);

// Duplicate an existing ncplane. The new plane will have the same geometry,
// will duplicate all content, and will start with the same rendering state.
struct ncplane* ncplane_dup(struct ncplane* n, void* opaque);
Expand Down
10 changes: 8 additions & 2 deletions include/notcurses/notcurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,14 @@ API int ncplane_abs_y(const struct ncplane* n) __attribute__ ((pure));
API int ncplane_abs_x(const struct ncplane* n) __attribute__ ((pure));

// Get the plane to which the plane 'n' is bound, if any.
API struct ncplane* ncplane_parent(struct ncplane* n);
API const struct ncplane* ncplane_parent_const(const struct ncplane* n);
API struct ncplane* ncplane_parent(struct ncplane* n)
__attribute__ ((nonnull (1)));
API const struct ncplane* ncplane_parent_const(const struct ncplane* n)
__attribute__ ((nonnull (1)));

// Get the head of the list of planes bound to 'n'.
API struct ncplane* ncplane_boundlist(struct ncplane* n)
__attribute__ ((nonnull (1)));

// Return non-zero iff 'n' is a proper descendent of 'ancestor'.
static inline int
Expand Down
6 changes: 5 additions & 1 deletion src/demo/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,10 @@ int demo_render(struct notcurses* nc){
clock_gettime(CLOCK_MONOTONIC, &ts);
if(plot){
if(!plot_hidden){
struct ncplane* pixelp = ncplane_boundlist(ncuplot_plane(plot));
if(pixelp){
ncplane_move_top(pixelp);
}
ncplane_move_top(ncuplot_plane(plot));
}
uint64_t ns = (timespec_to_ns(&ts) - plottimestart) / (NANOSECS_IN_SEC / FPSHZ);
Expand Down Expand Up @@ -660,7 +664,7 @@ int fpsgraph_init(struct notcurses* nc){
opts.flags = NCPLOT_OPTION_LABELTICKSD |
NCPLOT_OPTION_EXPONENTIALD |
NCPLOT_OPTION_PRINTSAMPLE;
opts.gridtype = NCBLIT_BRAILLE;
opts.gridtype = NCBLIT_PIXEL;
opts.legendstyle = NCSTYLE_ITALIC | NCSTYLE_BOLD;
opts.title = "frames per semisecond";
ncchannels_set_fg_rgb8(&opts.minchannels, 0x80, 0x80, 0xff);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/notcurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,10 @@ const ncplane* ncplane_parent_const(const ncplane* n){
return n->boundto;
}

ncplane* ncplane_boundlist(ncplane* n){
return n->blist;
}

void ncplane_set_resizecb(ncplane* n, int(*resizecb)(ncplane*)){
if(n == notcurses_stdplane(ncplane_notcurses(n))){
return;
Expand Down
21 changes: 9 additions & 12 deletions src/lib/plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ int redraw_pixelplot_##T(nc##X##plot* ncp){ \
bool done = !ncp->plot.bset->fill; \
for(int y = 0 ; y < dimy ; ++y){ \
uint64_t channels = 0; \
ncplane_set_channels(ncp->plot.ncp, channels); \
/* if we've got at least one interval's worth on the number of positions \
times the number of intervals per position plus the starting offset, \
we're going to print *something* */ \
Expand All @@ -154,24 +153,22 @@ int redraw_pixelplot_##T(nc##X##plot* ncp){ \
egcidx = (gvals[i] - intervalbase) / interval; \
} \
if(egcidx >= states){ \
egcidx = states - 1; \
egcidx = states; \
done = false; \
} \
}else{ \
egcidx = 0; \
} \
/* FIXME take egcidx into account for height..scale is wide, states is high */ \
/*fprintf(stderr, "WRITING TO y/x %d/%d (%zu)\n", y, x, dimx * dimy * scale * states); */\
if(egcidx){ \
for(size_t yy = 0 ; yy < states ; ++yy){ \
int poff = x * scale + i + ((y * states + yy) * dimx * scale); \
calc_gradient_channels(&channels, ncp->plot.minchannels, ncp->plot.minchannels, \
ncp->plot.maxchannels, ncp->plot.maxchannels, \
y * states + yy, x, dimy * states, dimx); \
uint32_t color = ncchannels_fg_rgb(channels); \
ncpixel_set_a(&color, 0xff); \
pixels[poff] = color; \
} \
for(size_t yy = 0 ; yy < egcidx ; ++yy){ \
int poff = x * scale + i + ((y * states + yy) * dimx * scale); \
calc_gradient_channels(&channels, ncp->plot.minchannels, ncp->plot.minchannels, \
ncp->plot.maxchannels, ncp->plot.maxchannels, \
y * states + yy, x, dimy * states, dimx); \
uint32_t color = ncchannels_fg_rgb(channels); \
ncpixel_set_a(&color, 0xff); \
pixels[poff] = color; \
} \
} \
if(done){ \
Expand Down

0 comments on commit 1571bfe

Please sign in to comment.