2020-11-28 15:27:25 +01:00
|
|
|
-- widgets/text.lua :: basic text widget object
|
|
|
|
|
|
|
|
--[[
|
|
|
|
Copyright © 2019 Kazhnuz
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
]]
|
|
|
|
local BaseWidget = require "birb.modules.menusystem.menus.widgets.base"
|
|
|
|
local TextWidget = BaseWidget:extend()
|
|
|
|
|
|
|
|
-- TEXT WIDGET
|
|
|
|
-- Simple text widget
|
|
|
|
|
2020-12-05 09:02:22 +01:00
|
|
|
function TextWidget:new(menuName, font, label)
|
|
|
|
TextWidget.super.new(self, menuName)
|
2020-11-28 15:27:25 +01:00
|
|
|
self.font = font
|
|
|
|
self.label = label
|
2020-12-04 12:54:57 +01:00
|
|
|
self:setSelectedColor(1, 1, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextWidget:setSelectedColor(r, g, b)
|
|
|
|
self.selectedColor = {}
|
|
|
|
self.selectedColor.r = r
|
|
|
|
self.selectedColor.g = g
|
|
|
|
self.selectedColor.b = b
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextWidget:getSelectedColor()
|
|
|
|
return self.selectedColor.r, self.selectedColor.g, self.selectedColor.b
|
2020-11-28 15:27:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function TextWidget:drawCanvas()
|
|
|
|
local w, h
|
|
|
|
w = math.floor(self.width / 2)
|
|
|
|
h = math.floor(self.height / 2) - (self.font:getHeight() / 2)
|
|
|
|
self.font:draw(self.label, w, h, -1, "center")
|
|
|
|
end
|
|
|
|
|
2020-12-04 12:54:57 +01:00
|
|
|
function TextWidget:drawSelected(x, y, w, h)
|
|
|
|
local r, g, b = self:getSelectedColor()
|
|
|
|
love.graphics.setColor(r, g, b, 1)
|
|
|
|
self:draw(x, y)
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
end
|
|
|
|
|
2020-11-28 15:27:25 +01:00
|
|
|
return TextWidget
|