Relintais-Enemy-Kooldown-Tr.../lib/AceGUI-3.0/widgets/AceGUIWidget-CheckBox.lua

218 lines
5.1 KiB
Lua
Raw Normal View History

local AceGUI = LibStub("AceGUI-3.0")
--------------------------
-- Check Box --
--------------------------
--[[
Events :
OnValueChanged
]]
do
local Type = "CheckBox"
local Version = 4
local function OnAcquire(self)
self:SetValue(false)
self.tristate = nil
2016-05-06 15:25:00 +02:00
end
local function OnRelease(self)
self.frame:ClearAllPoints()
self.frame:Hide()
self.check:Hide()
self.highlight:Hide()
self.down = nil
self.checked = nil
self:SetType()
self:SetDisabled(false)
end
local function CheckBox_OnEnter(this)
local self = this.obj
if not self.disabled then
self.highlight:Show()
2016-05-06 15:25:00 +02:00
end
self:Fire("OnEnter")
2016-05-06 15:25:00 +02:00
end
local function CheckBox_OnLeave(this)
local self = this.obj
if not self.down then
self.highlight:Hide()
2016-05-06 15:25:00 +02:00
end
self:Fire("OnLeave")
2016-05-06 15:25:00 +02:00
end
local function CheckBox_OnMouseUp(this)
local self = this.obj
if not self.disabled then
self:ToggleChecked()
self:Fire("OnValueChanged",self.checked)
self.text:SetPoint("LEFT",self.check,"RIGHT",0,0)
end
self.down = nil
end
local function CheckBox_OnMouseDown(this)
local self = this.obj
if not self.disabled then
self.text:SetPoint("LEFT",self.check,"RIGHT",1,-1)
self.down = true
2016-05-06 15:25:00 +02:00
end
AceGUI:ClearFocus()
end
2016-05-06 15:25:00 +02:00
local function SetDisabled(self,disabled)
2016-05-06 15:25:00 +02:00
self.disabled = disabled
if disabled then
self.text:SetTextColor(0.5,0.5,0.5)
2016-05-06 15:25:00 +02:00
SetDesaturation(self.check, true)
else
self.text:SetTextColor(1,1,1)
2016-05-06 15:25:00 +02:00
if self.tristate and self.checked == nil then
SetDesaturation(self.check, true)
else
SetDesaturation(self.check, false)
end
end
end
local function SetValue(self,value)
2016-05-06 15:25:00 +02:00
local check = self.check
self.checked = value
if value then
SetDesaturation(self.check, false)
check:SetWidth(24)
check:SetHeight(24)
2016-05-06 15:25:00 +02:00
self.check:Show()
else
--Nil is the unknown tristate value
if self.tristate and value == nil then
SetDesaturation(self.check, true)
check:SetWidth(20)
check:SetHeight(20)
2016-05-06 15:25:00 +02:00
self.check:Show()
else
SetDesaturation(self.check, false)
check:SetWidth(24)
check:SetHeight(24)
2016-05-06 15:25:00 +02:00
self.check:Hide()
end
end
end
local function SetTriState(self, enabled)
2016-05-06 15:25:00 +02:00
self.tristate = enabled
self:SetValue(self:GetValue())
end
local function GetValue(self)
return self.checked
end
local function SetType(self, type)
2016-05-06 15:25:00 +02:00
local checkbg = self.checkbg
local check = self.check
local highlight = self.highlight
2016-05-06 15:25:00 +02:00
if type == "radio" then
checkbg:SetTexture("Interface\\Buttons\\UI-RadioButton")
checkbg:SetTexCoord(0,0.25,0,1)
2016-05-06 15:25:00 +02:00
check:SetTexture("Interface\\Buttons\\UI-RadioButton")
check:SetTexCoord(0.5,0.75,0,1)
2016-05-06 15:25:00 +02:00
check:SetBlendMode("ADD")
highlight:SetTexture("Interface\\Buttons\\UI-RadioButton")
highlight:SetTexCoord(0.5,0.75,0,1)
2016-05-06 15:25:00 +02:00
else
checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
checkbg:SetTexCoord(0,1,0,1)
2016-05-06 15:25:00 +02:00
check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
check:SetTexCoord(0,1,0,1)
2016-05-06 15:25:00 +02:00
check:SetBlendMode("BLEND")
highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
highlight:SetTexCoord(0,1,0,1)
2016-05-06 15:25:00 +02:00
end
end
local function ToggleChecked(self)
2016-05-06 15:25:00 +02:00
local value = self:GetValue()
if self.tristate then
--cycle in true, nil, false order
if value then
self:SetValue(nil)
elseif value == nil then
self:SetValue(false)
else
self:SetValue(true)
end
else
self:SetValue(not self:GetValue())
end
end
local function SetLabel(self, label)
2016-05-06 15:25:00 +02:00
self.text:SetText(label)
end
2016-05-06 15:25:00 +02:00
local function Constructor()
local frame = CreateFrame("Button",nil,UIParent)
local self = {}
self.type = Type
self.OnRelease = OnRelease
self.OnAcquire = OnAcquire
self.SetValue = SetValue
self.GetValue = GetValue
self.SetDisabled = SetDisabled
self.SetType = SetType
self.ToggleChecked = ToggleChecked
self.SetLabel = SetLabel
self.SetTriState = SetTriState
2016-05-06 15:25:00 +02:00
self.frame = frame
frame.obj = self
local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight")
self.text = text
frame:SetScript("OnEnter",CheckBox_OnEnter)
frame:SetScript("OnLeave",CheckBox_OnLeave)
frame:SetScript("OnMouseUp",CheckBox_OnMouseUp)
frame:SetScript("OnMouseDown",CheckBox_OnMouseDown)
frame:EnableMouse()
local checkbg = frame:CreateTexture(nil,"ARTWORK")
self.checkbg = checkbg
checkbg:SetWidth(24)
checkbg:SetHeight(24)
checkbg:SetPoint("LEFT",frame,"LEFT",0,0)
checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
local check = frame:CreateTexture(nil,"OVERLAY")
self.check = check
check:SetWidth(24)
check:SetHeight(24)
check:SetPoint("CENTER",checkbg,"CENTER",0,0)
check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
local highlight = frame:CreateTexture(nil, "BACKGROUND")
self.highlight = highlight
highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
highlight:SetBlendMode("ADD")
highlight:SetAllPoints(checkbg)
highlight:Hide()
text:SetJustifyH("LEFT")
frame:SetHeight(24)
frame:SetWidth(200)
text:SetHeight(18)
text:SetPoint("LEFT",check,"RIGHT",0,0)
text:SetPoint("RIGHT",frame,"RIGHT",0,0)
AceGUI:RegisterAsWidget(self)
return self
2016-05-06 15:25:00 +02:00
end
AceGUI:RegisterWidgetType(Type,Constructor,Version)
2016-05-06 15:25:00 +02:00
end