From 3a705590c565cb8c69c86ea8a92c063c9ece4aa3 Mon Sep 17 00:00:00 2001 From: "Marcus E. W. Germano" Date: Wed, 20 Jan 2021 23:29:38 -0500 Subject: [PATCH 1/2] Implemented a surface resize method. --- src/core.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/core.lua b/src/core.lua index f1de7df..6c3929a 100644 --- a/src/core.lua +++ b/src/core.lua @@ -344,6 +344,34 @@ function surf:copy() return surface end +function surf:resize(width, height, b, t, c) + local newbuffer = { } + for y = 0, height - 1 do + for x = 0, width - 1 do + if (x >= 0 and x < self.width) and (y >= 0 and y < self.height) then + newbuffer[3 * (y * width + x) + 1] = self.buffer[3 * (y * self.width + x) + 1] + newbuffer[3 * (y * width + x) + 2] = self.buffer[3 * (y * self.width + x) + 2] + newbuffer[3 * (y * width + x) + 3] = self.buffer[3 * (y * self.width + x) + 3] + else + if b or self.overwrite then + newbuffer[3 * (y * width + x) + 1] = b + end + if t or self.overwrite then + newbuffer[3 * (y * width + x) + 2] = t + end + if c or self.overwrite then + newbuffer[3 * (y * width + x) + 3] = c + end + end + end + end + newbuffer[3 * width * height + 1] = false + + self.buffer = newbuffer + self.width = width + self.height = height +end + function surf:clear(b, t, c) local xoffset, yoffset From f86a449fe980d70d698145ec9654a137d3791e02 Mon Sep 17 00:00:00 2001 From: "Marcus E. W. Germano" Date: Thu, 21 Jan 2021 00:56:33 -0500 Subject: [PATCH 2/2] Fixed bug where drawing to new width and height will not take effect. --- src/core.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.lua b/src/core.lua index 6c3929a..0cf97a9 100644 --- a/src/core.lua +++ b/src/core.lua @@ -368,8 +368,8 @@ function surf:resize(width, height, b, t, c) newbuffer[3 * width * height + 1] = false self.buffer = newbuffer - self.width = width - self.height = height + self.width, self.cwidth = width, width + self.height, self.cheight = height, height end function surf:clear(b, t, c)