1 local AceGUI
= LibStub("AceGUI-3.0")
7 local CreateFrame
, UIParent
= CreateFrame
, UIParent
9 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
10 -- List them here for Mikk's FindGlobals script
11 -- GLOBALS: SetDesaturation, GameFontHighlight
13 --------------------------
15 --------------------------
22 local Type
= "CheckBox"
25 local function OnAcquire(self
)
33 local function OnRelease(self
)
34 self
.frame
:ClearAllPoints()
41 self
:SetDisabled(false)
42 self
:SetDescription(nil)
45 local function CheckBox_OnEnter(this
)
51 local function CheckBox_OnLeave(this
)
57 local function CheckBox_OnMouseUp(this
)
59 if not self
.disabled
then
61 self
:Fire("OnValueChanged",self
.checked
)
62 self
.text
:SetPoint("LEFT",self
.check
,"RIGHT",0,0)
67 local function CheckBox_OnMouseDown(this
)
69 if not self
.disabled
then
70 self
.text
:SetPoint("LEFT",self
.check
,"RIGHT",1,-1)
76 local function SetDisabled(self
,disabled
)
77 self
.disabled
= disabled
80 self
.text
:SetTextColor(0.5,0.5,0.5)
81 SetDesaturation(self
.check
, true)
84 self
.text
:SetTextColor(1,1,1)
85 if self
.tristate
and self
.checked
== nil then
86 SetDesaturation(self
.check
, true)
88 SetDesaturation(self
.check
, false)
93 local function SetValue(self
,value
)
94 local check
= self
.check
97 SetDesaturation(self
.check
, false)
100 --Nil is the unknown tristate value
101 if self
.tristate
and value
== nil then
102 SetDesaturation(self
.check
, true)
105 SetDesaturation(self
.check
, false)
109 SetDisabled(self
, self
.disabled
)
112 local function SetTriState(self
, enabled
)
113 self
.tristate
= enabled
114 self
:SetValue(self
:GetValue())
117 local function GetValue(self
)
121 local function SetType(self
, type)
122 local checkbg
= self
.checkbg
123 local check
= self
.check
124 local highlight
= self
.highlight
126 if type == "radio" then
127 checkbg
:SetHeight(16)
129 checkbg
:SetTexture("Interface\\Buttons\\UI-RadioButton")
130 checkbg
:SetTexCoord(0,0.25,0,1)
133 check
:SetTexture("Interface\\Buttons\\UI-RadioButton")
134 check
:SetTexCoord(0.25,0.5,0,1)
135 check
:SetBlendMode("ADD")
136 highlight
:SetTexture("Interface\\Buttons\\UI-RadioButton")
137 highlight
:SetTexCoord(0.5,0.75,0,1)
139 checkbg
:SetHeight(24)
141 checkbg
:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
142 checkbg
:SetTexCoord(0,1,0,1)
145 check
:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
146 check
:SetTexCoord(0,1,0,1)
147 check
:SetBlendMode("BLEND")
148 highlight
:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
149 highlight
:SetTexCoord(0,1,0,1)
153 local function ToggleChecked(self
)
154 local value
= self
:GetValue()
155 if self
.tristate
then
156 --cycle in true, nil, false order
159 elseif value
== nil then
165 self
:SetValue(not self
:GetValue())
169 local function SetLabel(self
, label
)
170 self
.text
:SetText(label
)
173 local function SetDescription(self
, desc
)
175 if not self
.desc
then
176 local desc
= self
.frame
:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
177 desc
:ClearAllPoints()
178 desc
:SetPoint("TOPLEFT", self
.check
, "TOPRIGHT", 5, -21)
179 desc
:SetWidth(self
.frame
.width
- 30)
180 desc
:SetJustifyH("LEFT")
181 desc
:SetJustifyV("TOP")
185 --self.text:SetFontObject(GameFontNormal)
186 self
.desc
:SetText(desc
)
187 self
:SetHeight(28 + self
.desc
:GetHeight())
190 self
.desc
:SetText("")
193 self
.text
:SetFontObject(GameFontHighlight
)
198 local function SetImage(self
, path
, ...)
199 local image
= self
.image
200 image
:SetTexture(path
)
202 if image
:GetTexture() then
203 local n
= select('#', ...)
204 if n
== 4 or n
== 8 then
205 image
:SetTexCoord(...)
207 image
:SetTexCoord(0, 1, 0, 1)
213 local function AlignImage(self
)
214 local img
= self
.image
:GetTexture()
215 self
.text
:ClearAllPoints()
217 self
.text
:SetPoint("LEFT", self
.check
, "RIGHT", 0, 0)
218 self
.text
:SetPoint("RIGHT", self
.frame
, "RIGHT", 0, 0)
220 self
.text
:SetPoint("LEFT", self
.image
,"RIGHT", 1, 0)
221 self
.text
:SetPoint("RIGHT", self
.frame
,"RIGHT", 0, 0)
225 local function OnWidthSet(self
, width
)
226 if self
.desc
and self
.desc
:GetText() ~= "" then
227 self
.desc
:SetWidth(width
- 30)
228 self
:SetHeight(28 + self
.desc
:GetHeight())
232 local function Constructor()
233 local frame
= CreateFrame("Button",nil,UIParent
)
237 self
.OnRelease
= OnRelease
238 self
.OnAcquire
= OnAcquire
240 self
.SetValue
= SetValue
241 self
.GetValue
= GetValue
242 self
.SetDisabled
= SetDisabled
243 self
.SetType
= SetType
244 self
.ToggleChecked
= ToggleChecked
245 self
.SetLabel
= SetLabel
246 self
.SetTriState
= SetTriState
247 self
.SetDescription
= SetDescription
248 self
.OnWidthSet
= OnWidthSet
249 self
.SetImage
= SetImage
250 self
.AlignImage
= AlignImage
255 local text
= frame
:CreateFontString(nil,"OVERLAY","GameFontHighlight")
258 frame
:SetScript("OnEnter",CheckBox_OnEnter
)
259 frame
:SetScript("OnLeave",CheckBox_OnLeave
)
260 frame
:SetScript("OnMouseUp",CheckBox_OnMouseUp
)
261 frame
:SetScript("OnMouseDown",CheckBox_OnMouseDown
)
263 local checkbg
= frame
:CreateTexture(nil,"ARTWORK")
264 self
.checkbg
= checkbg
266 checkbg
:SetHeight(24)
267 checkbg
:SetPoint("TOPLEFT",frame
,"TOPLEFT",0,0)
268 checkbg
:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
269 local check
= frame
:CreateTexture(nil,"OVERLAY")
273 check
:SetPoint("CENTER",checkbg
,"CENTER",0,0)
274 check
:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
276 local highlight
= frame
:CreateTexture(nil, "OVERLAY")
277 self
.highlight
= highlight
278 highlight
:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
279 highlight
:SetBlendMode("ADD")
280 highlight
:SetAllPoints(checkbg
)
283 local image
= frame
:CreateTexture(nil, "OVERLAY")
287 image
:SetPoint("LEFT", check
, "RIGHT", 1, 0)
289 text
:SetJustifyH("LEFT")
293 text
:SetPoint("LEFT",check
,"RIGHT",0,0)
294 text
:SetPoint("RIGHT",frame
,"RIGHT",0,0)
296 AceGUI
:RegisterAsWidget(self
)
300 AceGUI
:RegisterWidgetType(Type
,Constructor
,Version
)