core/menusystem: rework default Widget
This commit is contained in:
parent
5c2792c9f4
commit
205de52345
1 changed files with 32 additions and 43 deletions
|
@ -1,68 +1,59 @@
|
||||||
local Widget = {}
|
local Widget = {}
|
||||||
|
|
||||||
BaseWidget = Object:extend()
|
BaseWidget = Object:extend()
|
||||||
DummyWidget = BaseWidget:extend()
|
|
||||||
|
|
||||||
function BaseWidget:new(controller)
|
function BaseWidget:new(menu)
|
||||||
self.controller = controller
|
self.menu = menu
|
||||||
|
|
||||||
self.destroyed = false
|
self.destroyed = false
|
||||||
self.selectable = false
|
self.selectable = false
|
||||||
self.selection_margin = 0
|
self.selection_margin = 0
|
||||||
self.margin = 2
|
self.margin = 2
|
||||||
self.label = ""
|
|
||||||
|
|
||||||
self.beginlabel = ""
|
self:register()
|
||||||
self.endlabel = ""
|
|
||||||
|
self.height, self.width = self.menu:getWidgetSize()
|
||||||
|
|
||||||
self.canvas = {}
|
self.canvas = {}
|
||||||
self.canvas.texture = nil
|
self.canvas.texture = nil
|
||||||
self.canvas.needRedraw = true
|
self.canvas.needRedraw = true
|
||||||
|
|
||||||
self:register()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWidget:register()
|
function BaseWidget:register()
|
||||||
self.controller:addWidget(self)
|
self.menu:addWidget(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWidget:setCanvas(w, h)
|
function BaseWidget:redrawCanvas()
|
||||||
self.canvas = {}
|
self.canvas.texture = love.graphics.newCanvas(self.width, self.height)
|
||||||
self.canvas.width = w
|
love.graphics.setCanvas( self.canvas.texture )
|
||||||
self.canvas.height = h
|
|
||||||
|
|
||||||
self.canvas.selected = {}
|
self:drawCanvas()
|
||||||
self.canvas.selected.texture = nil
|
self.canvas.needRedraw = false
|
||||||
self.canvas.selected.active = false
|
|
||||||
|
|
||||||
self.canvas.base = {}
|
love.graphics.setCanvas( )
|
||||||
self.canvas.base.texture = nil
|
end
|
||||||
self.canvas.base.active = false
|
|
||||||
|
function BaseWidget:drawCanvas()
|
||||||
|
self.r = love.math.random(128)/256
|
||||||
|
self.g = love.math.random(128)/256
|
||||||
|
self.b = love.math.random(128)/256
|
||||||
|
|
||||||
|
love.graphics.setColor(self.r, self.g, self.b, 70)
|
||||||
|
love.graphics.rectangle("fill", 0, 0, self.width, self.height)
|
||||||
|
love.graphics.setColor(self.r, self.g, self.b)
|
||||||
|
love.graphics.rectangle("line", 0, 0, self.width, self.height)
|
||||||
|
utils.graphics.resetColor()
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWidget:selectAction()
|
function BaseWidget:selectAction()
|
||||||
-- Do nothing
|
-- Do nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
function DummyWidget:new()
|
function BaseWidget:draw(x, y)
|
||||||
DummyWidget.super.new(self)
|
if self.canvas.texture ~= nil then
|
||||||
self.r = love.math.random(128)
|
utils.graphics.resetColor()
|
||||||
self.g = love.math.random(128)
|
love.graphics.draw(self.canvas.texture, x, y)
|
||||||
self.b = love.math.random(128)
|
end
|
||||||
self.selectable = true
|
|
||||||
self.label = "DUMMY WIDGET (see modules.menus.widget)"
|
|
||||||
end
|
|
||||||
|
|
||||||
function DummyWidget:draw(x, y, w, h)
|
|
||||||
x = x + self.margin
|
|
||||||
y = y + self.margin
|
|
||||||
w = w - self.margin * 2
|
|
||||||
h = h - self.margin * 2
|
|
||||||
|
|
||||||
love.graphics.setColor(self.r,self.g,self.b,70)
|
|
||||||
love.graphics.rectangle("fill", x, y, w, h)
|
|
||||||
love.graphics.setColor(self.r,self.g,self.b)
|
|
||||||
love.graphics.rectangle("line", x, y, w, h)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWidget:drawSelected(x,y,w,h)
|
function BaseWidget:drawSelected(x,y,w,h)
|
||||||
|
@ -100,10 +91,10 @@ function BaseWidget:drawSelected(x,y,w,h)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWidget:draw(x, y, w, h)
|
|
||||||
end
|
|
||||||
|
|
||||||
function BaseWidget:update(dt)
|
function BaseWidget:update(dt)
|
||||||
|
if (self.canvas.needRedraw) then
|
||||||
|
self:redrawCanvas()
|
||||||
|
end
|
||||||
-- N/A
|
-- N/A
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,8 +135,6 @@ function drawWidget_selected(x, y, w, h)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
Widget.Base = BaseWidget
|
Widget.Base = BaseWidget
|
||||||
Widget.Dummy = DummyWidget
|
|
||||||
|
|
||||||
return Widget
|
return Widget
|
||||||
|
|
Loading…
Reference in a new issue