From d4e493727e8f74a09d4514cd89239d597ab73899 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 6 Oct 2017 21:22:52 +0530 Subject: [PATCH] Clip all rendered images to screen boundaries --- kitty/graphics.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kitty/graphics.c b/kitty/graphics.c index 665835a50..7729c686f 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -580,7 +580,7 @@ grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float scree Image *img; ImageRef *ref; ImageRect r; float screen_width = dx * num_cols, screen_height = dy * num_rows; - float screen_bottom = screen_top - screen_height; + float screen_bottom = screen_top - screen_height, screen_right = screen_left + screen_width; float screen_width_px = num_cols * global_state.cell_width; float screen_height_px = num_rows * global_state.cell_height; float y0 = screen_top - dy * scrolled_by; @@ -597,6 +597,12 @@ grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float scree if (ref->num_cols) r.right = screen_left + (ref->start_column + ref->num_cols) * dx; else r.right = r.left + screen_width * (float)ref->src_width / screen_width_px; + // Clip image to screen boundaries + if (r.top > screen_top) r.top = screen_top; + if (r.bottom < screen_bottom) r.bottom = screen_bottom; + if (r.left < screen_left) r.left = screen_left; + if (r.right > screen_right) r.right = screen_right; + if (ref->z_index < 0) self->num_of_negative_refs++; else self->num_of_positive_refs++; ensure_space_for(self, render_data, ImageRenderData, self->count + 1, capacity, 100); ImageRenderData *rd = self->render_data + self->count;