mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-10-31 15:20:13 +00:00
recenter post-rotation in normal demo #617
This commit is contained in:
parent
bcdf513e31
commit
99bd3fd597
@ -1232,6 +1232,9 @@ API char* ncplane_contents(const struct ncplane* nc, int begy, int begx,
|
||||
API void* ncplane_set_userptr(struct ncplane* n, void* opaque);
|
||||
API void* ncplane_userptr(struct ncplane* n);
|
||||
|
||||
API void ncplane_center_abs(const struct ncplane* n, int* RESTRICT y,
|
||||
int* RESTRICT x);
|
||||
|
||||
// Return the column at which 'c' cols ought start in order to be aligned
|
||||
// according to 'align' within ncplane 'n'. Returns INT_MAX on invalid 'align'.
|
||||
// Undefined behavior on negative 'c'.
|
||||
|
@ -96,16 +96,30 @@ int normal_demo(struct notcurses* nc){
|
||||
cell_release(nstd, &c);
|
||||
for(int i = 0 ; i < 16 ; ++i){
|
||||
demo_nanosleep(nc, &scaled);
|
||||
int centy, centx;
|
||||
ncplane_center_abs(n, ¢y, ¢x);
|
||||
if(ncplane_rotate_cw(n)){
|
||||
goto err;
|
||||
}
|
||||
int cent2y, cent2x;
|
||||
int absy, absx;
|
||||
ncplane_center_abs(n, ¢2y, ¢2x);
|
||||
ncplane_yx(n, &absy, &absx);
|
||||
ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x);
|
||||
DEMO_RENDER(nc);
|
||||
}
|
||||
for(int i = 0 ; i < 16 ; ++i){
|
||||
demo_nanosleep(nc, &scaled);
|
||||
int centy, centx;
|
||||
ncplane_center_abs(n, ¢y, ¢x);
|
||||
if(ncplane_rotate_ccw(n)){
|
||||
goto err;
|
||||
}
|
||||
int cent2y, cent2x;
|
||||
int absy, absx;
|
||||
ncplane_center_abs(n, ¢2y, ¢2x);
|
||||
ncplane_yx(n, &absy, &absx);
|
||||
ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x);
|
||||
DEMO_RENDER(nc);
|
||||
}
|
||||
ncplane_destroy(n);
|
||||
|
@ -563,11 +563,6 @@ int ncplane_rotate_cw(ncplane* n){
|
||||
}
|
||||
int ret = rotate_merge(n, newp);
|
||||
ret |= ncplane_destroy(newp);
|
||||
int cent2y, cent2x;
|
||||
int absy, absx;
|
||||
ncplane_center_abs(n, ¢2y, ¢2x);
|
||||
ncplane_yx(n, &absy, &absx);
|
||||
ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -578,8 +573,6 @@ int ncplane_rotate_ccw(ncplane* n){
|
||||
}
|
||||
int dimy, dimx, targdimy, targdimx;
|
||||
ncplane_dim_yx(n, &dimy, &dimx);
|
||||
int centy, centx;
|
||||
ncplane_center_abs(n, ¢y, ¢x);
|
||||
ncplane_dim_yx(newp, &targdimy, &targdimx);
|
||||
int x = dimx - 2, y;
|
||||
// Each row of the target plane is taken from a column of the source plane.
|
||||
@ -597,11 +590,6 @@ int ncplane_rotate_ccw(ncplane* n){
|
||||
}
|
||||
int ret = rotate_merge(n, newp);
|
||||
ret |= ncplane_destroy(newp);
|
||||
int cent2y, cent2x;
|
||||
int absy, absx;
|
||||
ncplane_center_abs(n, ¢2y, ¢2x);
|
||||
ncplane_yx(n, &absy, &absx);
|
||||
ncplane_move_yx(n, absy + centy - cent2y, absx + centx - cent2x);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -648,21 +648,6 @@ ncplane_center(const ncplane* n, int* RESTRICT y, int* RESTRICT x){
|
||||
center_box(y, x);
|
||||
}
|
||||
|
||||
// find the center coordinate of a plane, preferring the top/left in the
|
||||
// case of an even number of rows/columns (in such a case, there will be one
|
||||
// more cell to the bottom/right of the center than the top/left). the
|
||||
// center is then modified relative to the plane's origin.
|
||||
static inline void
|
||||
ncplane_center_abs(const ncplane* n, int* RESTRICT y, int* RESTRICT x){
|
||||
ncplane_center(n, y, x);
|
||||
if(y){
|
||||
*y += n->absy;
|
||||
}
|
||||
if(x){
|
||||
*x += n->absx;
|
||||
}
|
||||
}
|
||||
|
||||
int ncvisual_bounding_box(const struct ncvisual* ncv, int* leny, int* lenx,
|
||||
int* offy, int* offx);
|
||||
|
||||
|
@ -2003,3 +2003,17 @@ int cells_rounded_box(struct ncplane* n, uint32_t attr, uint64_t channels,
|
||||
}
|
||||
return cells_ascii_box(n, attr, channels, ul, ur, ll, lr, hl, vl);
|
||||
}
|
||||
|
||||
// find the center coordinate of a plane, preferring the top/left in the
|
||||
// case of an even number of rows/columns (in such a case, there will be one
|
||||
// more cell to the bottom/right of the center than the top/left). the
|
||||
// center is then modified relative to the plane's origin.
|
||||
void ncplane_center_abs(const ncplane* n, int* RESTRICT y, int* RESTRICT x){
|
||||
ncplane_center(n, y, x);
|
||||
if(y){
|
||||
*y += n->absy;
|
||||
}
|
||||
if(x){
|
||||
*x += n->absx;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user