diff --git a/sonic-boost.love/core/modules/menusystem/widgets/init.lua b/sonic-boost.love/core/modules/menusystem/widgets/init.lua index 059a016..7aa78d9 100644 --- a/sonic-boost.love/core/modules/menusystem/widgets/init.lua +++ b/sonic-boost.love/core/modules/menusystem/widgets/init.lua @@ -1,68 +1,59 @@ local Widget = {} BaseWidget = Object:extend() -DummyWidget = BaseWidget:extend() -function BaseWidget:new(controller) - self.controller = controller +function BaseWidget:new(menu) + self.menu = menu self.destroyed = false self.selectable = false self.selection_margin = 0 self.margin = 2 - self.label = "" - self.beginlabel = "" - self.endlabel = "" + self:register() + + self.height, self.width = self.menu:getWidgetSize() self.canvas = {} self.canvas.texture = nil self.canvas.needRedraw = true - - self:register() end function BaseWidget:register() - self.controller:addWidget(self) + self.menu:addWidget(self) end -function BaseWidget:setCanvas(w, h) - self.canvas = {} - self.canvas.width = w - self.canvas.height = h +function BaseWidget:redrawCanvas() + self.canvas.texture = love.graphics.newCanvas(self.width, self.height) + love.graphics.setCanvas( self.canvas.texture ) - self.canvas.selected = {} - self.canvas.selected.texture = nil - self.canvas.selected.active = false + self:drawCanvas() + self.canvas.needRedraw = false - self.canvas.base = {} - self.canvas.base.texture = nil - self.canvas.base.active = false + love.graphics.setCanvas( ) +end + +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 function BaseWidget:selectAction() -- Do nothing end -function DummyWidget:new() - DummyWidget.super.new(self) - self.r = love.math.random(128) - self.g = love.math.random(128) - self.b = love.math.random(128) - 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) +function BaseWidget:draw(x, y) + if self.canvas.texture ~= nil then + utils.graphics.resetColor() + love.graphics.draw(self.canvas.texture, x, y) + end end function BaseWidget:drawSelected(x,y,w,h) @@ -100,10 +91,10 @@ function BaseWidget:drawSelected(x,y,w,h) end -function BaseWidget:draw(x, y, w, h) -end - function BaseWidget:update(dt) + if (self.canvas.needRedraw) then + self:redrawCanvas() + end -- N/A end @@ -144,8 +135,6 @@ function drawWidget_selected(x, y, w, h) end - Widget.Base = BaseWidget -Widget.Dummy = DummyWidget return Widget