Files
PathOfBuilding/Classes/CheckBoxControl.lua
Openarl 6750deaf30 More changes for 1.0.27
- More tweaks to the skill gem select
- Skill gems can now be disabled
- Skill gem level defaults to 20
2016-09-13 02:50:30 +10:00

97 lines
2.5 KiB
Lua

-- Path of Building
--
-- Class: Check Box Control
-- Basic check box control.
--
local launch, main = ...
local CheckBoxClass = common.NewClass("CheckBoxControl", "Control", function(self, anchor, x, y, size, label, changeFunc)
self.Control(anchor, x, y, size, size)
self.label = label
self.changeFunc = changeFunc
end)
function CheckBoxClass:IsMouseOver()
if not self:IsShown() then
return false
end
local x, y = self:GetPos()
local width, height = self:GetSize()
local cursorX, cursorY = GetCursorPos()
return cursorX >= x and cursorY >= y and cursorX < x + width and cursorY < y + height
end
function CheckBoxClass:Draw(viewPort)
local x, y = self:GetPos()
local size = self.width
local enabled = self:IsEnabled()
local mOver = self:IsMouseOver()
if not enabled then
SetDrawColor(0.33, 0.33, 0.33)
elseif mOver then
SetDrawColor(1, 1, 1)
else
SetDrawColor(0.5, 0.5, 0.5)
end
DrawImage(nil, x, y, size, size)
if not enabled then
SetDrawColor(0, 0, 0)
elseif self.clicked and mOver then
SetDrawColor(0.5, 0.5, 0.5)
elseif mOver then
SetDrawColor(0.33, 0.33, 0.33)
else
SetDrawColor(0, 0, 0)
end
DrawImage(nil, x + 1, y + 1, size - 2, size - 2)
if self.state then
if not enabled then
SetDrawColor(0.33, 0.33, 0.33)
elseif mOver then
SetDrawColor(1, 1, 1)
else
SetDrawColor(0.75, 0.75, 0.75)
end
DrawImageQuad(nil, x + size * 0.15, y + size * 0.50, x + size * 0.30, y + size * 0.45, x + size * 0.50, y + size * 0.80, x + size * 0.40, y + size * 0.90)
DrawImageQuad(nil, x + size * 0.40, y + size * 0.90, x + size * 0.35, y + size * 0.75, x + size * 0.80, y + size * 0.10, x + size * 0.90, y + size * 0.20)
end
if enabled then
SetDrawColor(1, 1, 1)
else
SetDrawColor(0.33, 0.33, 0.33)
end
local label = self:GetProperty("label")
if label then
DrawString(x - 5, y + 2, "RIGHT_X", size - 4, "VAR", label)
end
if mOver and self.tooltip then
main:AddTooltipLine(16, self:GetProperty("tooltip"))
SetDrawLayer(nil, 100)
main:DrawTooltip(x, y, size, size, viewPort)
SetDrawLayer(nil, 0)
end
end
function CheckBoxClass:OnKeyDown(key)
if not self:IsShown() or not self:IsEnabled() then
return
end
if key == "LEFTBUTTON" then
self.clicked = true
end
return self
end
function CheckBoxClass:OnKeyUp(key)
if not self:IsShown() or not self:IsEnabled() then
return
end
if key == "LEFTBUTTON" then
if self:IsMouseOver() then
self.state = not self.state
self.changeFunc(self.state)
end
end
self.clicked = false
end