Skip to content

Commit

Permalink
overlapping images: fix background and clipping borders (~mintty#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintty committed Jun 9, 2020
1 parent baa45da commit 2b941d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/winimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ strage_read(temp_strage_t *strage, unsigned char *p, size_t size)


#define dont_debug_img_list
#define dont_debug_img_disp

static uint
winimg_len(imglist *img)
Expand All @@ -253,7 +254,9 @@ winimg_new(imglist **ppimg, char * id, unsigned char * pixels, uint len,
#endif

static int _imgi = 0;
//printf("winimg_new %d @%d\n", _imgi, top);
#ifdef debug_img_disp
printf("winimg_new %d @%d:%d\n", _imgi, left, top);
#endif
img->imgi = _imgi++;

img->pixels = pixels;
Expand Down Expand Up @@ -645,11 +648,14 @@ winimgs_paint(void)

HDC dc = GetDC(wnd);

#ifdef pre_clip
// this does not appear to be necessary
RECT rc;
GetClientRect(wnd, &rc);
IntersectClipRect(dc, rc.left + PADDING, rc.top + PADDING,
rc.left + PADDING + term.cols * cell_width,
rc.top + PADDING + term.rows * cell_height);
#endif

imglist * prev = 0;
for (img = term.imgs.first; img;) {
Expand All @@ -675,7 +681,7 @@ winimgs_paint(void)
#ifdef debug_img_list
printf("paint: check img %p v@%d s@%d\n", img, img->top, top);
#endif
// create DC handle if it is not initialized, or resume from hibernate
// create img DC handle if not initialized, or resume from hibernate
winimg_lazyinit(img);

// check all cells of image area;
Expand All @@ -693,9 +699,13 @@ winimgs_paint(void)
bool clip_flag = false;
if (dchar->chr != SIXELCH)
clip_flag = true;
else if (img->imgi - dchar->attr.imgi >= 0)
else if (img->imgi - dchar->attr.imgi >= 0) {
// need to keep newer image, as sync may take a while
#ifdef debug_img_disp
printf("paint: dirty (%d) %d:%d %d >= %d\n", disp_flag, y, x, img->imgi, dchar->attr.imgi);
#endif
disp_flag = true;
}
// if cell is overlaid by selection or cursor, exclude
if (dchar->attr.attr & (TATTR_RESULT | TATTR_CURRESULT | TATTR_MARKED | TATTR_CURMARKED))
clip_flag = true;
Expand Down Expand Up @@ -724,7 +734,10 @@ winimgs_paint(void)
// better background handling implemented below; this version
// would expose artefacts if a transparent image is scrolled
}
else {
else if (disp_flag) {
#ifdef debug_img_disp
printf("paint: clear background\n");
#endif
// determine image size for padding
int iwidth;
int iheight;
Expand Down Expand Up @@ -786,12 +799,16 @@ winimgs_paint(void)
DeleteObject(hbm);
DeleteDC(hdc);
}
else
else {
StretchBlt(dc,
left * cell_width + PADDING, top * cell_height + PADDING,
img->width * cell_width, img->height * cell_height,
img->hdc,
0, 0, img->pixelwidth, img->pixelheight, SRCCOPY);
}
// restore clipping region
ReleaseDC(wnd, dc);
dc = GetDC(wnd);
}
else if (top < 0 || top + img->height > term.rows) {
// we did not check the scrolled-out image part,
Expand Down
3 changes: 3 additions & 0 deletions wiki/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Window handling
* For overlapping images, fixed background and clipping borders (~#1010).

### 3.1.8 (7 June 2020) ###

Terminal features
Expand Down

0 comments on commit 2b941d6

Please sign in to comment.