From 7e697c36285d78b1eff70bfb4a6b7fb0df3abd6a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 4 Dec 2020 12:55:48 +0100 Subject: [PATCH] feat: add drawWidget Let the widget handle if its selected or not --- birb/modules/menusystem/menus/widgets/base.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/birb/modules/menusystem/menus/widgets/base.lua b/birb/modules/menusystem/menus/widgets/base.lua index 3390a60..867d425 100644 --- a/birb/modules/menusystem/menus/widgets/base.lua +++ b/birb/modules/menusystem/menus/widgets/base.lua @@ -85,9 +85,16 @@ end -- DRAW WIDGETS -- Draw the widget -function BaseWidget:draw(x, y) +function BaseWidget:drawWidget(x, y, w, h) + if (self:haveFocus()) then + self:drawSelected(x, y, w, h) + else + self:draw(x, y, w, h) + end +end + +function BaseWidget:draw(x, y, w, h) if self.canvas.texture ~= nil then - utils.graphics.resetColor() love.graphics.draw(self.canvas.texture, x, y) end end @@ -106,6 +113,13 @@ function BaseWidget:update(dt) -- N/A end +-- FOCUS FUNCTIONS +-- Detect if the widget have focus + +function BaseWidget:haveFocus() + return (self.menu:haveFocus() and self.menu.widget:getSelected() == self.id) +end + -- ACTION FUNCTION -- Functions to handle actions and selection.