diff options
author | David McMackins II <contact@mcmackins.org> | 2018-05-20 08:14:51 -0500 |
---|---|---|
committer | David McMackins II <contact@mcmackins.org> | 2018-05-20 08:14:51 -0500 |
commit | 1ed25a355bc2c0c168943eea1a6a1332cc710209 (patch) | |
tree | 95e635e4dbf01b414c75ee3678d8387c206fd357 | |
parent | dd548abe4b309c4b6b6d5e2d7ca8e0594183ecac (diff) |
Move box drawing routine up to GuiComponent for use by other box-shaped components
-rw-r--r-- | gui.lua | 39 |
1 files changed, 24 insertions, 15 deletions
@@ -115,8 +115,8 @@ function GuiComponent:__init(x, y, w, h, bg, fg) self.w = functionize(w) self.h = functionize(h) - self.bg = bg - self.fg = fg + self.bg = functionize(bg) + self.fg = functionize(fg) self.clicked = {} self.clicklisteners = {} @@ -134,7 +134,11 @@ function GuiComponent:draw() end function GuiComponent:drawbox() + love.graphics.setColor(self:bg()) + love.graphics.rectangle('fill', self:x(), self:y(), self:w(), self:h()) + love.graphics.setColor(self:fg()) + love.graphics.rectangle('line', self:x(), self:y(), self:w(), self:h()) end function GuiComponent:addclicklistener(listener) @@ -195,24 +199,29 @@ end Button = class(GuiComponent) -function Button:draw() - if not self._base.draw(self) then - return false - end +function Button:__init(x, y, w, h, bg, fg) + self._base.__init(self, x, y, w, h, bg, fg) - local bg = {self.bg[1], self.bg[2], self.bg[3]} - local mx, my = love.mouse.getPosition() - if self.clicked[1] and self:contains(mx, my) then - for i,val in ipairs(bg) do - bg[i] = bg[i] - 50 + self._origbg = self.bg + self.bg = function() + local bg = { unpack(self:_origbg()) } + local mx, my = love.mouse.getPosition() + if self.clicked[1] and self:contains(mx, my) then + for i,val in ipairs(bg) do + bg[i] = bg[i] - 50 + end end + + return bg end +end - love.graphics.setColor(bg) - love.graphics.rectangle('fill', self:x(), self:y(), self:w(), self:h()) +function Button:draw() + if not self._base.draw(self) then + return false + end - love.graphics.setColor(self.fg) - love.graphics.rectangle('line', self:x(), self:y(), self:w(), self:h()) + self:drawbox() if not self._lasth or self:h() ~= self._lasth then self._font = love.graphics.newFont(self:h() * 0.8) |