diff --git a/src/animations/DurFile.zig b/src/animations/DurFile.zig index 57d38c0..c0048ee 100644 --- a/src/animations/DurFile.zig +++ b/src/animations/DurFile.zig @@ -358,11 +358,8 @@ fn calc_start_position(terminal_buffer: *TerminalBuffer, dur_movie: *DurFormat, const buf_width: u32 = @intCast(terminal_buffer.width); const buf_height: u32 = @intCast(terminal_buffer.height); - var movie_width: u32 = dur_movie.columns; - var movie_height: u32 = dur_movie.lines; - - if (movie_width > buf_width) movie_width = buf_width; - if (movie_height > buf_height) movie_height = buf_height; + const movie_width: u32 = dur_movie.columns; + const movie_height: u32 = dur_movie.lines; const start_pos: IVec2 = switch (offset_alignment) { DurOffsetAlignment.center => .{ center(buf_width) - center(movie_width), center(buf_height) - center(movie_height) }, @@ -545,14 +542,14 @@ fn draw(self: *DurFile) void { const buf_height: u32 = @intCast(self.terminal_buffer.height); // y is used as an iterator in the durformat, while cell_y gives us the correct placement for the cell (same for x) - for (0..self.frame_size[VEC_Y]) |y| { + for (@max(0, -self.start_pos[VEC_Y])..@intCast(self.frame_size[VEC_Y])) |y| { const y_offset_i = @as(i32, @intCast(y)) + self.start_pos[VEC_Y]; // we skip the pass if it falls outside of the draw window (ensure no int underflow) const cell_y: u32 = if (y_offset_i >= 0 and y_offset_i < buf_height) @intCast(y_offset_i) else continue; var iter = std.unicode.Utf8View.initUnchecked(current_frame.contents[y]).iterator(); - for (0..self.frame_size[VEC_X]) |x| { + for (@max(0, -self.start_pos[VEC_X])..@intCast(self.frame_size[VEC_X])) |x| { const x_offset_i = @as(i32, @intCast(x)) + self.start_pos[VEC_X]; // skip pass, same as y but also increment the codepoint iter to fetch correct values in later passes const cell_x: u32 = if (x_offset_i >= 0 and x_offset_i < buf_width) @intCast(x_offset_i) else {