core/menusystem: let the menu handle cursor drawing
This commit is contained in:
parent
a1f7995b13
commit
b18c95455c
5 changed files with 27 additions and 31 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -84,6 +84,10 @@ function Menu:draw()
|
|||
-- nothing here
|
||||
end
|
||||
|
||||
function Menu:drawCursor()
|
||||
-- nothing here
|
||||
end
|
||||
|
||||
function Menu:drawCanvas()
|
||||
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue