ncneofetch: adapt to screen width for neofetch-style logos

This commit is contained in:
nick black 2021-03-07 21:16:09 -05:00
parent ef5a3200de
commit 228b9edf09
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
5 changed files with 43 additions and 38 deletions

View File

@ -3,6 +3,8 @@
// show it with each blitter, with a legend
static int
visualize(struct notcurses* nc, struct ncvisual* ncv){
struct timespec kdelay;
timespec_div(&demodelay, 2, &kdelay);
ncblitter_e bs[] = {
NCBLIT_1x1,
NCBLIT_2x1,
@ -12,37 +14,34 @@ visualize(struct notcurses* nc, struct ncvisual* ncv){
NCBLIT_PIXEL,
};
for(size_t i = 0 ; i < sizeof(bs) / sizeof(*bs) ; ++i){
if(bs[i] == NCBLIT_PIXEL && !notcurses_canpixel(nc)){
// FIXME throw up an indicator?
continue;
}
struct ncvisual_options vopts = {
.scaling = NCSCALE_STRETCH,
.scaling = bs[i] == NCBLIT_PIXEL ? NCSCALE_SCALE : NCSCALE_STRETCH,
.blitter = bs[i],
.n = notcurses_stdplane(nc),
.y = 1,
.flags = NCVISUAL_OPTION_NODEGRADE,
};
if(vopts.blitter == NCBLIT_PIXEL){
vopts.scaling = NCSCALE_SCALE;
}
if(ncvisual_render(nc, ncv, &vopts) == NULL){
return -1;
}
ncplane_set_fg_rgb(vopts.n, 0xffffff);
ncplane_set_bg_rgb(vopts.n, 0);
const char* name = notcurses_str_blitter(bs[i]);
int scalex, scaley, truey, truex;
ncvisual_geom(nc, ncv, &vopts, &truey, &truex, &scaley, &scalex);
vopts.x = (ncplane_dim_x(notcurses_stdplane(nc)) - truex / scalex) / 2;
ncplane_set_fg_rgb(vopts.n, 0xffffff);
ncplane_set_bg_rgb(vopts.n, 0);
if(ncvisual_render(nc, ncv, &vopts) == NULL){
ncplane_erase(vopts.n);
ncplane_printf_aligned(vopts.n, ncplane_dim_y(vopts.n) / 2 - 1, NCALIGN_CENTER, "not available");
}else{
ncplane_printf_aligned(vopts.n, ncplane_dim_y(vopts.n) / 2 - 1, NCALIGN_CENTER,
"%03dx%03d", truex, truey);
ncplane_printf_aligned(vopts.n, ncplane_dim_y(vopts.n) / 2 + 1, NCALIGN_CENTER,
"%d:%d pixels -> cell", scalex, scaley);
}
const char* name = notcurses_str_blitter(bs[i]);
ncplane_putstr_aligned(vopts.n, ncplane_dim_y(vopts.n) / 2 - 3, NCALIGN_CENTER, name);
ncplane_printf_aligned(vopts.n, ncplane_dim_y(vopts.n) / 2 - 1, NCALIGN_CENTER,
"%03dx%03d", truex, truey);
ncplane_printf_aligned(vopts.n, ncplane_dim_y(vopts.n) / 2 + 1, NCALIGN_CENTER,
"%d:%d pixels -> cell", scalex, scaley);
int ret = demo_render(nc);
if(ret){
return ret;
}
ret = demo_nanosleep(nc, &demodelay);
ret = demo_nanosleep(nc, &kdelay);
if(ret){
return ret;
}

View File

@ -552,7 +552,7 @@ neologo_present(struct ncdirect* nc, const char* nlogo){
maxlinelen = collen;
}
}
const int leftpad = (80 - maxlinelen) / 2;
const int leftpad = (ncdirect_dim_x(nc) - maxlinelen) / 2;
for(int i = 0 ; i < linecount ; ++i){
printf("%*.*s%s", leftpad, leftpad, "", lines[i]);
free(lines[i]);

View File

@ -5,13 +5,19 @@
// number of pixels that map to a single cell, height-wise
static inline int
encoding_y_scale(const struct blitset* bset) {
encoding_y_scale(const tinfo* tcache, const struct blitset* bset) {
if(bset->geom == NCBLIT_PIXEL){
return tcache->cellpixy;
}
return bset->height;
}
// number of pixels that map to a single cell, width-wise
static inline int
encoding_x_scale(const struct blitset* bset) {
encoding_x_scale(const tinfo* tcache, const struct blitset* bset) {
if(bset->geom == NCBLIT_PIXEL){
return tcache->cellpixx;
}
return bset->width;
}

View File

@ -478,8 +478,8 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
int disprows, dispcols;
if(scale != NCSCALE_NONE && scale != NCSCALE_NONE_HIRES){
if(bset->geom != NCBLIT_PIXEL){
dispcols = ncdirect_dim_x(n) * encoding_x_scale(bset);
disprows = ncdirect_dim_y(n) * encoding_y_scale(bset);
dispcols = ncdirect_dim_x(n) * encoding_x_scale(&n->tcache, bset);
disprows = ncdirect_dim_y(n) * encoding_y_scale(&n->tcache, bset);
}else{
dispcols = ncdirect_dim_x(n) * n->tcache.cellpixx;
disprows = ncdirect_dim_y(n) * n->tcache.cellpixy;
@ -489,7 +489,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
}
}else{
disprows = ncv->rows;
dispcols = ncv->cols / encoding_x_scale(bset);
dispcols = ncv->cols / encoding_x_scale(&n->tcache, bset);
}
leny = (leny / (double)ncv->rows) * ((double)disprows);
lenx = (lenx / (double)ncv->cols) * ((double)dispcols);
@ -497,8 +497,8 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
ncplane_options nopts = {
.y = 0,
.x = 0,
.rows = disprows / encoding_y_scale(bset),
.cols = dispcols / encoding_x_scale(bset),
.rows = disprows / encoding_y_scale(&n->tcache, bset),
.cols = dispcols / encoding_x_scale(&n->tcache, bset),
.userptr = nullptr,
.name = "fake",
.resizecb = nullptr,

View File

@ -93,22 +93,22 @@ auto ncvisual_geom(const notcurses* nc, const ncvisual* n,
if(n){
if(scale == NCSCALE_NONE || scale == NCSCALE_NONE_HIRES){
*y = n->rows;
*x = n->cols;// * encoding_x_scale(bset);
*x = n->cols;
}else{
int rows = vopts->n ? ncplane_dim_y(vopts->n) : ncplane_dim_y(nc->stdplane);
int cols = vopts->n ? ncplane_dim_x(vopts->n) : ncplane_dim_x(nc->stdplane);
*y = rows * encoding_y_scale(bset);
*x = cols * encoding_x_scale(bset);
*y = rows * encoding_y_scale(&nc->tcache, bset);
*x = cols * encoding_x_scale(&nc->tcache, bset);
}
if(scale == NCSCALE_SCALE || scale == NCSCALE_SCALE_HIRES){
scale_visual(n, y, x);
}
}
if(toy){
*toy = encoding_y_scale(bset);
*toy = encoding_y_scale(&nc->tcache, bset);
}
if(tox){
*tox = encoding_x_scale(bset);
*tox = encoding_x_scale(&nc->tcache, bset);
}
return 0;
}
@ -431,8 +431,8 @@ auto ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const blitset* bset,
disprows = ncv->rows;
}else{
notcurses_term_dim_yx(nc, &disprows, &dispcols);
dispcols *= encoding_x_scale(bset);
disprows *= encoding_y_scale(bset);
dispcols *= encoding_x_scale(&nc->tcache, bset);
disprows *= encoding_y_scale(&nc->tcache, bset);
if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){
scale_visual(ncv, &disprows, &dispcols);
} // else stretch
@ -441,8 +441,8 @@ auto ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const blitset* bset,
struct ncplane_options nopts = {
.y = placey,
.x = placex,
.rows = disprows / encoding_y_scale(bset),
.cols = dispcols / encoding_x_scale(bset),
.rows = disprows / encoding_y_scale(&nc->tcache, bset),
.cols = dispcols / encoding_x_scale(&nc->tcache, bset),
.userptr = nullptr,
.name = "rgba",
.resizecb = nullptr,
@ -459,8 +459,8 @@ auto ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const blitset* bset,
disprows = ncv->rows;
}else{
ncplane_dim_yx(n, &disprows, &dispcols);
dispcols *= encoding_x_scale(bset);
disprows *= encoding_y_scale(bset);
dispcols *= encoding_x_scale(&nc->tcache, bset);
disprows *= encoding_y_scale(&nc->tcache, bset);
disprows -= placey;
dispcols -= placex;
if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){