From b18c95455ccc12e2b3878a9cce4b87414a232c4f Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 12 Feb 2019 18:52:38 +0100 Subject: [PATCH] core/menusystem: let the menu handle cursor drawing --- .../core/modules/menusystem/flowbox.lua | 10 ++++++ .../core/modules/menusystem/init.lua | 5 +++ .../core/modules/menusystem/listbox.lua | 8 +++++ .../core/modules/menusystem/parent.lua | 4 +++ .../core/modules/menusystem/widgets/init.lua | 31 ------------------- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/sonic-boost.love/core/modules/menusystem/flowbox.lua b/sonic-boost.love/core/modules/menusystem/flowbox.lua index 5a378bb..f1d2f23 100644 --- a/sonic-boost.love/core/modules/menusystem/flowbox.lua +++ b/sonic-boost.love/core/modules/menusystem/flowbox.lua @@ -3,6 +3,8 @@ local Menu = require(cwd .. "parent") FlowBox = Menu:extend() +local menuutils = require(cwd .. "widgets.utils") + function FlowBox:new(menusystem, name, x, y, w, h, slots_hor, slots_vert) self.slots = slots_hor * slots_vert self.slots_hor = slots_hor @@ -161,4 +163,12 @@ function FlowBox:draw() end end +function FlowBox:drawCursor() + local w, h = self:getWidgetSize() + local col, line = self:getCoord(self.widget.selected) + local x = (col) * h + local y = (line) * h + menuutils.drawCursor(self.x + x, self.y + y, w, h) +end + return FlowBox diff --git a/sonic-boost.love/core/modules/menusystem/init.lua b/sonic-boost.love/core/modules/menusystem/init.lua index b677a58..2ca98f5 100644 --- a/sonic-boost.love/core/modules/menusystem/init.lua +++ b/sonic-boost.love/core/modules/menusystem/init.lua @@ -82,6 +82,11 @@ function MenuSystem:draw(dt) -- On dessine les entitées v:draw(dt) end end + + if self.menus[self.focusedMenu] ~= nil then + self.menus[self.focusedMenu]:drawCursor() + end + end return MenuSystem diff --git a/sonic-boost.love/core/modules/menusystem/listbox.lua b/sonic-boost.love/core/modules/menusystem/listbox.lua index dd3b9ee..e2643d9 100644 --- a/sonic-boost.love/core/modules/menusystem/listbox.lua +++ b/sonic-boost.love/core/modules/menusystem/listbox.lua @@ -1,6 +1,8 @@ local cwd = (...):gsub('%.listbox$', '') .. "." local Menu = require(cwd .. "parent") +local menuutils = require(cwd .. "widgets.utils") + ListBox = Menu:extend() function ListBox:new(menusystem, name, x, y, w, h, slots) @@ -82,4 +84,10 @@ function ListBox:draw() end end +function ListBox:drawCursor() + local w, h = self:getWidgetSize() + local y = (self.widget.selected - 1) * h + menuutils.drawCursor(self.x,self.y + y, w, h) +end + return ListBox diff --git a/sonic-boost.love/core/modules/menusystem/parent.lua b/sonic-boost.love/core/modules/menusystem/parent.lua index 9573215..4db61fb 100644 --- a/sonic-boost.love/core/modules/menusystem/parent.lua +++ b/sonic-boost.love/core/modules/menusystem/parent.lua @@ -84,6 +84,10 @@ function Menu:draw() -- nothing here end +function Menu:drawCursor() + -- nothing here +end + function Menu:drawCanvas() end diff --git a/sonic-boost.love/core/modules/menusystem/widgets/init.lua b/sonic-boost.love/core/modules/menusystem/widgets/init.lua index 4363696..6272a1a 100644 --- a/sonic-boost.love/core/modules/menusystem/widgets/init.lua +++ b/sonic-boost.love/core/modules/menusystem/widgets/init.lua @@ -58,37 +58,6 @@ end function BaseWidget:drawSelected(x,y,w,h) self:draw(x, y, w, h) - x = x + self.selection_margin - y = y + self.selection_margin - w = w - self.selection_margin * 2 - h = h - self.selection_margin * 2 - - love.graphics.setColor(0,0,0) - love.graphics.rectangle("fill", x, y, 4, 8) - love.graphics.rectangle("fill", x, y, 8, 4) - - love.graphics.rectangle("fill", x + w, y, -4, 8) - love.graphics.rectangle("fill", x + w, y, -8, 4) - - love.graphics.rectangle("fill", x, y + h, 4, -8) - love.graphics.rectangle("fill", x, y + h, 8, -4) - - love.graphics.rectangle("fill", x + w, y + h, -4, -8) - love.graphics.rectangle("fill", x + w, y + h, -8, -4) - - love.graphics.setColor(255,255,255) - love.graphics.rectangle("fill", x + 1, y + 1, 2, 6) - love.graphics.rectangle("fill", x + 1, y + 1, 6, 2) - - love.graphics.rectangle("fill", x + w - 1, y + 1, -2, 6) - love.graphics.rectangle("fill", x + w - 1, y + 1, -6, 2) - - love.graphics.rectangle("fill", x + 1, y + h - 1, 2, -6) - love.graphics.rectangle("fill", x + 1, y + h - 1, 6, -2) - - love.graphics.rectangle("fill", x + w - 1, y + h - 1, -2, -6) - love.graphics.rectangle("fill", x + w - 1, y + h - 1, -6, -2) - end function BaseWidget:update(dt)