core/menusystem: let the menu handle cursor drawing

This commit is contained in:
Kazhnuz 2019-02-12 18:52:38 +01:00
parent a1f7995b13
commit b18c95455c
5 changed files with 27 additions and 31 deletions

View file

@ -3,6 +3,8 @@ local Menu = require(cwd .. "parent")
FlowBox = Menu:extend() FlowBox = Menu:extend()
local menuutils = require(cwd .. "widgets.utils")
function FlowBox:new(menusystem, name, x, y, w, h, slots_hor, slots_vert) function FlowBox:new(menusystem, name, x, y, w, h, slots_hor, slots_vert)
self.slots = slots_hor * slots_vert self.slots = slots_hor * slots_vert
self.slots_hor = slots_hor self.slots_hor = slots_hor
@ -161,4 +163,12 @@ function FlowBox:draw()
end end
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 return FlowBox

View file

@ -82,6 +82,11 @@ function MenuSystem:draw(dt) -- On dessine les entitées
v:draw(dt) v:draw(dt)
end end
end end
if self.menus[self.focusedMenu] ~= nil then
self.menus[self.focusedMenu]:drawCursor()
end
end end
return MenuSystem return MenuSystem

View file

@ -1,6 +1,8 @@
local cwd = (...):gsub('%.listbox$', '') .. "." local cwd = (...):gsub('%.listbox$', '') .. "."
local Menu = require(cwd .. "parent") local Menu = require(cwd .. "parent")
local menuutils = require(cwd .. "widgets.utils")
ListBox = Menu:extend() ListBox = Menu:extend()
function ListBox:new(menusystem, name, x, y, w, h, slots) function ListBox:new(menusystem, name, x, y, w, h, slots)
@ -82,4 +84,10 @@ function ListBox:draw()
end end
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 return ListBox

View file

@ -84,6 +84,10 @@ function Menu:draw()
-- nothing here -- nothing here
end end
function Menu:drawCursor()
-- nothing here
end
function Menu:drawCanvas() function Menu:drawCanvas()
end end

View file

@ -58,37 +58,6 @@ end
function BaseWidget:drawSelected(x,y,w,h) function BaseWidget:drawSelected(x,y,w,h)
self:draw(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 end
function BaseWidget:update(dt) function BaseWidget:update(dt)