First commit.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
------------------------------------------------------------------------------
|
||||
-- Imports
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
local love = require 'love'
|
||||
local make_class = require 'src.utils.classes'
|
||||
local Button = require 'src.ui.button'
|
||||
local Color = require 'src.utils.color'
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Class definitions
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
local Checkbox = make_class(Button)
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Class methods
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
function Checkbox:_init(callback, value, w, h, color, sel_color, press_col, float, x, y)
|
||||
Button._init(self, x, y, callback, float)
|
||||
self.value = value
|
||||
self.w = w ~= nil and w or 20
|
||||
self.h = h ~= nil and h or 20
|
||||
self.base_col = color ~= nil and color or Color(255, 255, 255)
|
||||
self.sel_color = sel_color ~= nil and sel_color or Color(215, 0, 0)
|
||||
self.press_col = press_col ~= nil and press_col or Color(99, 99, 139)
|
||||
self.disbl_col = Color(95, 63, 75)
|
||||
end
|
||||
|
||||
|
||||
function Checkbox:set_dimensions()
|
||||
self.w = self.w
|
||||
self.h = self.h
|
||||
end
|
||||
|
||||
|
||||
function Checkbox:draw()
|
||||
local color = self.callback == nil and self.disbl_col or ((self.pressed and self.press_col) or ((self.selected and self.sel_color) or self.base_col))
|
||||
local mode = nil
|
||||
if self.value() then mode = 'fill' else mode = 'line' end
|
||||
|
||||
love.graphics.setColor(color.r, color.g, color.b)
|
||||
love.graphics.rectangle(mode, self.x, self.y, self.w, self.h)
|
||||
love.graphics.setColor()
|
||||
end
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- Module return
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
return Checkbox
|
||||
Reference in New Issue
Block a user