visual: implement NC_SCALE on both paths #683

pull/690/head
nick black 4 years ago
parent f1da9406f9
commit 10cbaedc77
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -426,22 +426,16 @@ auto ncvisual_render(notcurses* nc, ncvisual* ncv,
if(!vopts || vopts->scaling == NCSCALE_NONE){ if(!vopts || vopts->scaling == NCSCALE_NONE){
dispcols = ncv->cols / encoding_x_scale(bset) + ncv->cols % encoding_x_scale(bset); dispcols = ncv->cols / encoding_x_scale(bset) + ncv->cols % encoding_x_scale(bset);
disprows = ncv->rows / encoding_y_scale(bset) + ncv->rows % encoding_y_scale(bset); disprows = ncv->rows / encoding_y_scale(bset) + ncv->rows % encoding_y_scale(bset);
}else if(vopts->scaling == NCSCALE_SCALE){ }else{
notcurses_term_dim_yx(nc, &disprows, &dispcols); notcurses_term_dim_yx(nc, &disprows, &dispcols);
// FIXME kill FP? if(vopts->scaling == NCSCALE_SCALE){
double tmpratio = dispcols * encoding_x_scale(bset) / (double)ncv->cols; double xratio = (double)(dispcols * encoding_x_scale(bset)) / ncv->cols;
if(tmpratio * ncv->rows > disprows * encoding_y_scale(bset)){ if(xratio * ncv->rows > disprows * encoding_y_scale(bset)){
tmpratio = disprows * encoding_y_scale(bset) / (double)ncv->rows; xratio = (double)(disprows * encoding_y_scale(bset)) / ncv->rows;
assert(tmpratio <= 1); }
dispcols *= tmpratio; disprows = xratio * (ncv->rows / encoding_y_scale(bset));
}else{ dispcols = xratio * (ncv->cols / encoding_x_scale(bset));
assert(tmpratio <= 1);
disprows *= tmpratio;
} }
}else if(vopts->scaling == NCSCALE_STRETCH){
notcurses_term_dim_yx(nc, &disprows, &dispcols);
}else{
return nullptr;
} }
//fprintf(stderr, "PLACING NEW PLANE: %d/%d @ %d/%d\n", disprows, dispcols, placey, placex); //fprintf(stderr, "PLACING NEW PLANE: %d/%d @ %d/%d\n", disprows, dispcols, placey, placex);
n = ncplane_new(nc, disprows, dispcols, placey, placex, nullptr); n = ncplane_new(nc, disprows, dispcols, placey, placex, nullptr);
@ -454,10 +448,18 @@ auto ncvisual_render(notcurses* nc, ncvisual* ncv,
if(!vopts || vopts->scaling == NCSCALE_NONE){ if(!vopts || vopts->scaling == NCSCALE_NONE){
dispcols = ncv->cols / encoding_x_scale(bset) + ncv->cols % encoding_x_scale(bset); dispcols = ncv->cols / encoding_x_scale(bset) + ncv->cols % encoding_x_scale(bset);
disprows = ncv->rows / encoding_y_scale(bset) + ncv->rows % encoding_y_scale(bset); disprows = ncv->rows / encoding_y_scale(bset) + ncv->rows % encoding_y_scale(bset);
}else{ // FIXME handle SCALE }else{
ncplane_dim_yx(n, &disprows, &dispcols); ncplane_dim_yx(n, &disprows, &dispcols);
disprows -= placey; disprows -= placey;
dispcols -= placex; dispcols -= placex;
if(vopts->scaling == NCSCALE_SCALE){
double xratio = (double)(dispcols * encoding_x_scale(bset)) / ncv->cols;
if(xratio * ncv->rows > (double)(disprows * encoding_y_scale(bset))){
xratio = (double)(disprows * encoding_y_scale(bset)) / ncv->rows;
}
disprows = xratio * (ncv->rows / encoding_y_scale(bset));
dispcols = xratio * (ncv->cols / encoding_x_scale(bset));
}
} }
} }
leny = (leny / (double)ncv->rows) * ((double)disprows * encoding_y_scale(bset)); leny = (leny / (double)ncv->rows) * ((double)disprows * encoding_y_scale(bset));

Loading…
Cancel
Save