From 339d927d516ed213a06ea3e41ec7968d7d410ff1 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 28 Aug 2021 21:15:27 +0200 Subject: [PATCH] fix(textwidget): better color management --- .../birb/modules/gui/menus/widgets/text.lua | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua index 511bb0f..9ecfb42 100644 --- a/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua +++ b/sonic-radiance.love/birb/modules/gui/menus/widgets/text.lua @@ -35,7 +35,7 @@ function TextWidget:new(menuName, font, label, position, padding) -- We add the first label local position = position or "center" self:addLabel(label, position) - self:setSelectedColor(1, 1, 1) + self:setColor(1, 1, 1) end function TextWidget:addLabel(label, position) @@ -49,6 +49,13 @@ function TextWidget:replaceLabel(id, newLabel) self.labels[id].label = newLabel end +function TextWidget:setColor(r, g, b) + self.color = {} + self.color.r = r + self.color.g = g + self.color.b = b +end + function TextWidget:setSelectedColor(r, g, b) self.selectedColor = {} self.selectedColor.r = r @@ -61,7 +68,15 @@ function TextWidget:getFont() end function TextWidget:getSelectedColor() - return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b + if (self.selectedColor ~= nil) then + return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b + else + return self:getColor() + end +end + +function TextWidget:getColor() + return self.color.r, self.color.g, self.color.b end function TextWidget:getPadding() @@ -87,10 +102,21 @@ function TextWidget:drawCanvas() end end +function TextWidget:draw(x, y, w, h) + local r, g, b = self:getColor() + love.graphics.setColor(r, g, b, 1) + if self.canvas.texture ~= nil then + love.graphics.draw(self.canvas.texture, x, y) + end + utils.graphics.resetColor() +end + function TextWidget:drawSelected(x, y, w, h) local r, g, b = self:getSelectedColor() love.graphics.setColor(r, g, b, 1) - self:draw(x, y) + if self.canvas.texture ~= nil then + love.graphics.draw(self.canvas.texture, x, y) + end utils.graphics.resetColor() end