ncdirect_render_image: save/restore colors #1230

pull/1239/head
nick black 4 years ago
parent bf3e3eb0b5
commit d7fd7fa39e
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -371,6 +371,9 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np, int xoff){
int dimy, dimx;
ncplane_dim_yx(np, &dimy, &dimx);
//fprintf(stderr, "rasterizing %dx%d+%d\n", dimy, dimx, xoff);
// save the existing style and colors
bool fgdefault = n->fgdefault, bgdefault = n->bgdefault;
uint32_t fgrgb = n->fgrgb, bgrgb = n->bgrgb;
for(int y = 0 ; y < dimy ; ++y){
if(xoff){
if(ncdirect_cursor_move_yx(n, -1, xoff)){
@ -408,6 +411,17 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np, int xoff){
}
}
}
// restore the previous colors
if(fgdefault){
ncdirect_fg_default(n);
}else{
ncdirect_fg_rgb(n, fgrgb);
}
if(bgdefault){
ncdirect_bg_default(n);
}else{
ncdirect_bg_rgb(n, bgrgb);
}
return 0;
}
@ -449,7 +463,7 @@ int ncdirect_render_image(ncdirect* n, const char* file, ncalign_e align,
.rows = disprows / encoding_y_scale(bset),
.cols = dispcols / encoding_x_scale(bset),
.userptr = nullptr,
.name = "direct",
.name = "fake",
.resizecb = nullptr,
.flags = 0,
};

@ -16,6 +16,9 @@ int main(void){
fprintf(stderr, "This notcurses was not build with multimedia support.\n");
return EXIT_FAILURE;
}
ncdirect_fg_rgb8(n, 0xff, 0, 0xff);
ncdirect_bg_rgb8(n, 0, 0xff, 0);
ncdirect_printf_aligned(n, -1, NCALIGN_CENTER, "let's play!");
if(ncdirect_render_image(n, "../data/normal.png", NCALIGN_LEFT,
NCBLIT_DEFAULT, NCSCALE_STRETCH)){
return EXIT_FAILURE;

Loading…
Cancel
Save