mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
reference nc->margin when we want margins, not stdplane #1615
This commit is contained in:
parent
27b05e6f1b
commit
608943bb95
4
NEWS.md
4
NEWS.md
@ -26,6 +26,10 @@ rearrangements of Notcurses.
|
|||||||
`nccells_ascii_box()`. All are `static inline`.
|
`nccells_ascii_box()`. All are `static inline`.
|
||||||
* A bug was fixed in `ncplane_move_yx()`: root planes were being moved
|
* A bug was fixed in `ncplane_move_yx()`: root planes were being moved
|
||||||
relatively instead of absolutely. This was never the intended behavior.
|
relatively instead of absolutely. This was never the intended behavior.
|
||||||
|
* It used to be possible to pass `NULL` as the second parameter of
|
||||||
|
`ncplane_mergedown_simple()`, and have the standard plane be used as
|
||||||
|
the destination. This is no longer supported, since the source plane
|
||||||
|
could be in another pile. An error will instead be returned.
|
||||||
|
|
||||||
* 2.3.2 (2021-06-03)
|
* 2.3.2 (2021-06-03)
|
||||||
* Fixed a bug affecting certain scalings of `ncvisual` objects created from
|
* Fixed a bug affecting certain scalings of `ncvisual` objects created from
|
||||||
|
7
USAGE.md
7
USAGE.md
@ -825,9 +825,10 @@ struct ncplane* ncplane_dup(struct ncplane* n, void* opaque);
|
|||||||
// this operation. Do not supply the same plane for both 'src' and 'dst'.
|
// this operation. Do not supply the same plane for both 'src' and 'dst'.
|
||||||
int ncplane_mergedown(struct ncplane* restrict src, struct ncplane* restrict dst);
|
int ncplane_mergedown(struct ncplane* restrict src, struct ncplane* restrict dst);
|
||||||
|
|
||||||
// If 'src' does not intersect with 'dst', 'dst' will not be changed, but it is
|
// Merge the entirety of 'src' down onto the ncplane 'dst'. If 'src' does not
|
||||||
// not an error. If 'dst' is NULL, the operation will target the standard plane.
|
// intersect with 'dst', 'dst' will not be changed, but it is not an error.
|
||||||
int ncplane_mergedown_simple(const ncplane* restrict src, ncplane* restrict dst);
|
int ncplane_mergedown_simple(struct ncplane* restrict src,
|
||||||
|
struct ncplane* restrict dst);
|
||||||
|
|
||||||
// Erase every cell in the ncplane, resetting all attributes to normal, all
|
// Erase every cell in the ncplane, resetting all attributes to normal, all
|
||||||
// colors to the default color, and all cells to undrawn. All cells associated
|
// colors to the default color, and all cells to undrawn. All cells associated
|
||||||
|
@ -1966,8 +1966,8 @@ API int ncplane_format(struct ncplane* n, int ystop, int xstop, uint32_t stylema
|
|||||||
API int ncplane_stain(struct ncplane* n, int ystop, int xstop, uint64_t ul,
|
API int ncplane_stain(struct ncplane* n, int ystop, int xstop, uint64_t ul,
|
||||||
uint64_t ur, uint64_t ll, uint64_t lr);
|
uint64_t ur, uint64_t ll, uint64_t lr);
|
||||||
|
|
||||||
// If 'src' does not intersect with 'dst', 'dst' will not be changed, but it is
|
// Merge the entirety of 'src' down onto the ncplane 'dst'. If 'src' does not
|
||||||
// not an error. If 'dst' is NULL, the operation will target the standard plane.
|
// intersect with 'dst', 'dst' will not be changed, but it is not an error.
|
||||||
API int ncplane_mergedown_simple(struct ncplane* RESTRICT src,
|
API int ncplane_mergedown_simple(struct ncplane* RESTRICT src,
|
||||||
struct ncplane* RESTRICT dst);
|
struct ncplane* RESTRICT dst);
|
||||||
|
|
||||||
|
@ -486,8 +486,7 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n,
|
|||||||
static ncplane*
|
static ncplane*
|
||||||
create_initial_ncplane(notcurses* nc, int dimy, int dimx){
|
create_initial_ncplane(notcurses* nc, int dimy, int dimx){
|
||||||
ncplane_options nopts = {
|
ncplane_options nopts = {
|
||||||
.y = nc->margin_t,
|
.y = 0, .x = 0,
|
||||||
.x = nc->margin_l,
|
|
||||||
.rows = dimy - (nc->margin_t + nc->margin_b),
|
.rows = dimy - (nc->margin_t + nc->margin_b),
|
||||||
.cols = dimx - (nc->margin_l + nc->margin_r),
|
.cols = dimx - (nc->margin_l + nc->margin_r),
|
||||||
.userptr = NULL,
|
.userptr = NULL,
|
||||||
@ -566,10 +565,8 @@ inline int ncplane_cursor_move_yx(ncplane* n, int y, int x){
|
|||||||
ncplane* ncplane_dup(const ncplane* n, void* opaque){
|
ncplane* ncplane_dup(const ncplane* n, void* opaque){
|
||||||
int dimy = n->leny;
|
int dimy = n->leny;
|
||||||
int dimx = n->lenx;
|
int dimx = n->lenx;
|
||||||
// if we're duping the standard plane, we need adjust for marginalia
|
const int placey = n->absy;
|
||||||
const struct notcurses* nc = ncplane_notcurses_const(n);
|
const int placex = n->absx;
|
||||||
const int placey = n->absy - nc->margin_t;
|
|
||||||
const int placex = n->absx - nc->margin_l;
|
|
||||||
struct ncplane_options nopts = {
|
struct ncplane_options nopts = {
|
||||||
.y = placey,
|
.y = placey,
|
||||||
.x = placex,
|
.x = placex,
|
||||||
@ -2019,14 +2016,14 @@ int ncplane_move_yx(ncplane* n, int y, int x){
|
|||||||
|
|
||||||
int ncplane_y(const ncplane* n){
|
int ncplane_y(const ncplane* n){
|
||||||
if(n->boundto == n){
|
if(n->boundto == n){
|
||||||
return n->absy - ncplane_notcurses_const(n)->margin_t;
|
return n->absy;
|
||||||
}
|
}
|
||||||
return n->absy - n->boundto->absy;
|
return n->absy - n->boundto->absy;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ncplane_x(const ncplane* n){
|
int ncplane_x(const ncplane* n){
|
||||||
if(n->boundto == n){
|
if(n->boundto == n){
|
||||||
return n->absx - ncplane_notcurses_const(n)->margin_t;
|
return n->absx;
|
||||||
}
|
}
|
||||||
return n->absx - n->boundto->absx;
|
return n->absx - n->boundto->absx;
|
||||||
}
|
}
|
||||||
|
@ -514,9 +514,10 @@ int ncplane_mergedown(ncplane* restrict src, ncplane* restrict dst,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ncplane_mergedown_simple(ncplane* restrict src, ncplane* restrict dst){
|
int ncplane_mergedown_simple(ncplane* restrict src, ncplane* restrict dst){
|
||||||
const notcurses* nc = ncplane_notcurses_const(src);
|
// have to check dst, since we used to accept a NULL dst to mean the
|
||||||
|
// standard plane (this was unsafe, since src might be in another pile).
|
||||||
if(dst == NULL){
|
if(dst == NULL){
|
||||||
dst = nc->stdplane;
|
return -1;
|
||||||
}
|
}
|
||||||
int dimy, dimx;
|
int dimy, dimx;
|
||||||
ncplane_dim_yx(dst, &dimy, &dimx);
|
ncplane_dim_yx(dst, &dimy, &dimx);
|
||||||
@ -912,11 +913,11 @@ clean_sprixels(notcurses* nc, ncpile* p, FILE* out){
|
|||||||
ncplane_yx(s->n, &y, &x);
|
ncplane_yx(s->n, &y, &x);
|
||||||
// FIXME clean this up, don't use sprite_draw, etc.
|
// FIXME clean this up, don't use sprite_draw, etc.
|
||||||
// without this, kitty flickers
|
// without this, kitty flickers
|
||||||
//fprintf(stderr, "1 MOVING BITMAP %d STATE %d AT %d/%d for %p\n", s->id, s->invalidated, y + nc->stdplane->absy, x + nc->stdplane->absx, s->n);
|
//fprintf(stderr, "1 MOVING BITMAP %d STATE %d AT %d/%d for %p\n", s->id, s->invalidated, y + nc->margin_t, x + nc->margin_l, s->n);
|
||||||
if(s->invalidated == SPRIXEL_MOVED){
|
if(s->invalidated == SPRIXEL_MOVED){
|
||||||
sprite_destroy(nc, p, out, s);
|
sprite_destroy(nc, p, out, s);
|
||||||
}
|
}
|
||||||
if(goto_location(nc, out, y + nc->stdplane->absy, x + nc->stdplane->absx) == 0){
|
if(goto_location(nc, out, y + nc->margin_t, x + nc->margin_l) == 0){
|
||||||
if(sprite_draw(nc, p, s, out)){
|
if(sprite_draw(nc, p, s, out)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -941,8 +942,8 @@ rasterize_sprixels(notcurses* nc, ncpile* p, FILE* out){
|
|||||||
if(s->invalidated == SPRIXEL_INVALIDATED){
|
if(s->invalidated == SPRIXEL_INVALIDATED){
|
||||||
int y, x;
|
int y, x;
|
||||||
ncplane_yx(s->n, &y, &x);
|
ncplane_yx(s->n, &y, &x);
|
||||||
//fprintf(stderr, "3 DRAWING BITMAP %d STATE %d AT %d/%d for %p\n", s->id, s->invalidated, y + nc->stdplane->absy, x + nc->stdplane->absx, s->n);
|
//fprintf(stderr, "3 DRAWING BITMAP %d STATE %d AT %d/%d for %p\n", s->id, s->invalidated, y + nc->margin_t, x + nc->margin_l, s->n);
|
||||||
if(goto_location(nc, out, y + nc->stdplane->absy, x + nc->stdplane->absx) == 0){
|
if(goto_location(nc, out, y + nc->margin_t, x + nc->margin_l) == 0){
|
||||||
if(sprite_draw(nc, p, s, out)){
|
if(sprite_draw(nc, p, s, out)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -970,10 +971,10 @@ rasterize_sprixels(notcurses* nc, ncpile* p, FILE* out){
|
|||||||
static int
|
static int
|
||||||
rasterize_core(notcurses* nc, const ncpile* p, FILE* out, unsigned phase){
|
rasterize_core(notcurses* nc, const ncpile* p, FILE* out, unsigned phase){
|
||||||
struct crender* rvec = p->crender;
|
struct crender* rvec = p->crender;
|
||||||
for(int y = nc->stdplane->absy ; y < p->dimy + nc->stdplane->absy ; ++y){
|
for(int y = nc->margin_t; y < p->dimy + nc->margin_t ; ++y){
|
||||||
const int innery = y - nc->stdplane->absy;
|
const int innery = y - nc->margin_t;
|
||||||
for(int x = nc->stdplane->absx ; x < p->dimx + nc->stdplane->absx ; ++x){
|
for(int x = nc->margin_l ; x < p->dimx + nc->margin_l ; ++x){
|
||||||
const int innerx = x - nc->stdplane->absx;
|
const int innerx = x - nc->margin_l;
|
||||||
const size_t damageidx = innery * nc->lfdimx + innerx;
|
const size_t damageidx = innery * nc->lfdimx + innerx;
|
||||||
unsigned r, g, b, br, bg, bb;
|
unsigned r, g, b, br, bg, bb;
|
||||||
const nccell* srccell = &nc->lastframe[damageidx];
|
const nccell* srccell = &nc->lastframe[damageidx];
|
||||||
@ -1062,7 +1063,7 @@ rasterize_core(notcurses* nc, const ncpile* p, FILE* out, unsigned phase){
|
|||||||
// this is used to invalidate the sprixel in the first text round,
|
// this is used to invalidate the sprixel in the first text round,
|
||||||
// which is only necessary for sixel, not kitty.
|
// which is only necessary for sixel, not kitty.
|
||||||
if(rvec[damageidx].sprixel){
|
if(rvec[damageidx].sprixel){
|
||||||
sprixcell_e scstate = sprixel_state(rvec[damageidx].sprixel, y - nc->stdplane->absy, x - nc->stdplane->absx);
|
sprixcell_e scstate = sprixel_state(rvec[damageidx].sprixel, y - nc->margin_t, x - nc->margin_l);
|
||||||
if((scstate == SPRIXCELL_MIXED_SIXEL || scstate == SPRIXCELL_OPAQUE_SIXEL)
|
if((scstate == SPRIXCELL_MIXED_SIXEL || scstate == SPRIXCELL_OPAQUE_SIXEL)
|
||||||
&& !rvec[damageidx].s.p_beats_sprixel){
|
&& !rvec[damageidx].s.p_beats_sprixel){
|
||||||
//fprintf(stderr, "INVALIDATING at %d/%d (%u)\n", y, x, rvec[damageidx].s.p_beats_sprixel);
|
//fprintf(stderr, "INVALIDATING at %d/%d (%u)\n", y, x, rvec[damageidx].s.p_beats_sprixel);
|
||||||
@ -1094,7 +1095,7 @@ notcurses_rasterize_inner(notcurses* nc, ncpile* p, FILE* out){
|
|||||||
// don't write a clearscreen. we only update things that have been changed.
|
// don't write a clearscreen. we only update things that have been changed.
|
||||||
// we explicitly move the cursor at the beginning of each output line, so no
|
// we explicitly move the cursor at the beginning of each output line, so no
|
||||||
// need to home it expliticly.
|
// need to home it expliticly.
|
||||||
//fprintf(stderr, "pile %p ymax: %d xmax: %d\n", p, p->dimy + nc->stdplane->absy, p->dimx + nc->stdplane->absx);
|
//fprintf(stderr, "pile %p ymax: %d xmax: %d\n", p, p->dimy + nc->margin_t, p->dimx + nc->margin_l);
|
||||||
if(clean_sprixels(nc, p, out) < 0){
|
if(clean_sprixels(nc, p, out) < 0){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1194,8 +1195,8 @@ int notcurses_refresh(notcurses* nc, int* restrict dimy, int* restrict dimx){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ncpile p = {};
|
ncpile p = {};
|
||||||
p.dimy = nc->stdplane->leny;
|
p.dimy = nc->margin_t;
|
||||||
p.dimx = nc->stdplane->lenx;
|
p.dimx = nc->margin_l;
|
||||||
const int count = (nc->lfdimx > p.dimx ? nc->lfdimx : p.dimx) *
|
const int count = (nc->lfdimx > p.dimx ? nc->lfdimx : p.dimx) *
|
||||||
(nc->lfdimy > p.dimy ? nc->lfdimy : p.dimy);
|
(nc->lfdimy > p.dimy ? nc->lfdimy : p.dimy);
|
||||||
p.crender = malloc(count * sizeof(*p.crender));
|
p.crender = malloc(count * sizeof(*p.crender));
|
||||||
@ -1226,8 +1227,8 @@ int notcurses_render_to_file(notcurses* nc, FILE* fp){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ncpile p;
|
ncpile p;
|
||||||
p.dimy = nc->stdplane->leny;
|
p.dimy = nc->margin_t;
|
||||||
p.dimx = nc->stdplane->lenx;
|
p.dimx = nc->margin_l;
|
||||||
const int count = (nc->lfdimx > p.dimx ? nc->lfdimx : p.dimx) *
|
const int count = (nc->lfdimx > p.dimx ? nc->lfdimx : p.dimx) *
|
||||||
(nc->lfdimy > p.dimy ? nc->lfdimy : p.dimy);
|
(nc->lfdimy > p.dimy ? nc->lfdimy : p.dimy);
|
||||||
p.crender = malloc(count * sizeof(*p.crender));
|
p.crender = malloc(count * sizeof(*p.crender));
|
||||||
@ -1261,13 +1262,13 @@ int notcurses_render_to_file(notcurses* nc, FILE* fp){
|
|||||||
// down the z-buffer, looking at intersections with ncplanes. This implies
|
// down the z-buffer, looking at intersections with ncplanes. This implies
|
||||||
// locking down the EGC, the attributes, and the channels for each cell.
|
// locking down the EGC, the attributes, and the channels for each cell.
|
||||||
static void
|
static void
|
||||||
ncpile_render_internal(ncplane* n, struct crender* rvec, int leny, int lenx,
|
ncpile_render_internal(ncplane* n, struct crender* rvec, int leny, int lenx){
|
||||||
int absy, int absx){
|
//fprintf(stderr, "rendering %dx%d\n", leny, lenx);
|
||||||
ncpile* np = ncplane_pile(n);
|
ncpile* np = ncplane_pile(n);
|
||||||
ncplane* p = np->top;
|
ncplane* p = np->top;
|
||||||
sprixel* sprixel_list = NULL;
|
sprixel* sprixel_list = NULL;
|
||||||
while(p){
|
while(p){
|
||||||
paint(p, rvec, leny, lenx, absy, absx, &sprixel_list);
|
paint(p, rvec, leny, lenx, 0, 0, &sprixel_list);
|
||||||
p = p->below;
|
p = p->below;
|
||||||
}
|
}
|
||||||
if(sprixel_list){
|
if(sprixel_list){
|
||||||
@ -1338,10 +1339,7 @@ int ncpile_render(ncplane* n){
|
|||||||
if(engorge_crender_vector(pile)){
|
if(engorge_crender_vector(pile)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// FIXME notcurses_stdplane() doesn't belong here #1615
|
ncpile_render_internal(n, pile->crender, pile->dimy, pile->dimx);
|
||||||
ncpile_render_internal(n, pile->crender, pile->dimy, pile->dimx,
|
|
||||||
notcurses_stdplane(nc)->absy,
|
|
||||||
notcurses_stdplane(nc)->absx);
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &renderdone);
|
clock_gettime(CLOCK_MONOTONIC, &renderdone);
|
||||||
pthread_mutex_lock(&nc->statlock);
|
pthread_mutex_lock(&nc->statlock);
|
||||||
update_render_stats(&renderdone, &start, &nc->stats);
|
update_render_stats(&renderdone, &start, &nc->stats);
|
||||||
@ -1458,7 +1456,7 @@ int notcurses_cursor_enable(notcurses* nc, int y, int x){
|
|||||||
logerror(nc, "Illegal cursor placement: %d, %d\n", y, x);
|
logerror(nc, "Illegal cursor placement: %d, %d\n", y, x);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(y >= nc->stdplane->leny || x >= nc->stdplane->lenx){
|
if(y >= nc->margin_t || x >= nc->margin_l){
|
||||||
logerror(nc, "Illegal cursor placement: %d, %d\n", y, x);
|
logerror(nc, "Illegal cursor placement: %d, %d\n", y, x);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1472,7 +1470,7 @@ int notcurses_cursor_enable(notcurses* nc, int y, int x){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// updates nc->rstate.cursor{y,x}
|
// updates nc->rstate.cursor{y,x}
|
||||||
if(goto_location(nc, nc->ttyfp, y + nc->stdplane->absy, x + nc->stdplane->absx)){
|
if(goto_location(nc, nc->ttyfp, y + nc->margin_t, x + nc->margin_l)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// if we were already positive, we're already visible, no need to write cnorm
|
// if we were already positive, we're already visible, no need to write cnorm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user