From 5c5b551d8d4067ea3d5b1bef9b5cd16cdcbd8701 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 2 Jan 2022 22:28:38 +0100 Subject: [PATCH] feat: make the cursor part of texture --- .../birb/modules/gui/elements/canvas.lua | 24 ++++++++++++++++++- .../birb/modules/gui/menus/flowbox.lua | 2 +- .../birb/modules/gui/menus/grid.lua | 2 +- .../birb/modules/gui/menus/hlistbox.lua | 2 +- .../birb/modules/gui/menus/listbox.lua | 2 +- .../birb/modules/gui/menus/parent.lua | 6 ++++- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua index 54d782f..7fb1e23 100644 --- a/sonic-radiance.love/birb/modules/gui/elements/canvas.lua +++ b/sonic-radiance.love/birb/modules/gui/elements/canvas.lua @@ -16,6 +16,8 @@ function CanvasElement:initCanvas() self.canvas.texture = nil self.canvas.isAnimated = false self.canvas.padding = 8 + self.canvas.final = nil + self.canvas.dual = false end function CanvasElement:updateElement(dt) @@ -30,6 +32,18 @@ function CanvasElement:redraw() if (self.canvas.needRedraw or self.canvas.isAnimated) then self:generateTexture() end + + if (self.canvas.dual) then + local w, h = self:getDimensions() + local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2)) + love.graphics.setCanvas(canvas) + + love.graphics.draw(self.canvas.texture, 0, 0) + self:drawFinalTexture() + + self.canvas.final = canvas + love.graphics.setCanvas() + end end function CanvasElement:generateTexture() @@ -55,6 +69,10 @@ function CanvasElement:drawTexture() end +function CanvasElement:drawFinalTexture() + +end + function CanvasElement:parseOrigin(origin, size) if (origin == "center") then return size/2 @@ -67,7 +85,11 @@ end function CanvasElement:draw() love.graphics.setColor(1, 1, 1, self.opacity) - love.graphics.draw(self.canvas.texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy) + local texture = self.canvas.texture + if (self.canvas.dual) then + texture = self.canvas.final + end + love.graphics.draw(texture, self.x - self.canvas.padding,self.y - self.canvas.padding,self.r,self.sx,self.sy,self.ox,self.oy) love.graphics.setColor(1, 1, 1, 1) end diff --git a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua index 328bb7a..a963122 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/flowbox.lua @@ -142,7 +142,7 @@ function FlowBox:getGraphicalCursorPosition() local col, line = self.view:getCoord(self.widget:getSelected()) local x = (col) * h local y = (line - beginline) * h - return self.x + x, self.y + y, w, h + return x, y, w, h end return FlowBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/grid.lua b/sonic-radiance.love/birb/modules/gui/menus/grid.lua index 3c98a1c..afbd4c2 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/grid.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/grid.lua @@ -273,7 +273,7 @@ function GridBox:drawCursor() local w, h = self:getWidgetSize(slot) local x = self.slots[slot].x * self.widgetSize.w local y = self.slots[slot].y * self.widgetSize.h - self:drawGraphicalCursor(self.x + x, self.y + y, w, h) + self:drawGraphicalCursor(x, y, w, h) end end diff --git a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua index e94809b..fe4a594 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/hlistbox.lua @@ -99,7 +99,7 @@ function HListBox:getGraphicalCursorPosition() local w, h = self:getWidgetSize() local x = (self.widget:getSelected() - self.view.firstSlot) * w - return self.x + x,self.y, w, h + return x, 0, w, h end return HListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua index ad6d9e5..b11c39b 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/listbox.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/listbox.lua @@ -108,7 +108,7 @@ end function ListBox:getGraphicalCursorPosition() local x, y, w, h = self:getListPart(self.widget:getSelected() - self.view.firstSlot) - return self.x - self.ox + x,self.y + y - self.oy, w, h + return self:getListPart(self.widget:getSelected() - self.view.firstSlot) end return ListBox diff --git a/sonic-radiance.love/birb/modules/gui/menus/parent.lua b/sonic-radiance.love/birb/modules/gui/menus/parent.lua index 03ef62b..65ca974 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/parent.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/parent.lua @@ -43,6 +43,7 @@ function Menu:new(name, x, y, w, h) self:initCanvas() self.cancelFunc = nil + self.canvas.dual = true end -- FUNCTIONS FUNCTIONS @@ -180,9 +181,12 @@ end function Menu:drawElement() self:draw() +end + +function Menu:drawFinalTexture() if (self:haveFocus()) then local x, y, w, h = self:getGraphicalCursorPosition() - self:drawGraphicalCursor(x, y, w, h) + self:drawGraphicalCursor(self.canvas.padding + x, self.canvas.padding + y, w, h) end end