comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-CheckBox.lua @ 0:169f5211fc7f

First public revision. At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 20 May 2010 19:22:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:169f5211fc7f
1 local AceGUI = LibStub("AceGUI-3.0")
2
3 -- Lua APIs
4 local select = select
5
6 -- WoW APIs
7 local CreateFrame, UIParent = CreateFrame, UIParent
8
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
12
13 --------------------------
14 -- Check Box --
15 --------------------------
16 --[[
17 Events :
18 OnValueChanged
19
20 ]]
21 do
22 local Type = "CheckBox"
23 local Version = 13
24
25 local function OnAcquire(self)
26 self:SetValue(false)
27 self.tristate = nil
28 self:SetHeight(24)
29 self:SetWidth(200)
30 self:SetImage()
31 end
32
33 local function OnRelease(self)
34 self.frame:ClearAllPoints()
35 self.frame:Hide()
36 self.check:Hide()
37 self.highlight:Hide()
38 self.down = nil
39 self.checked = nil
40 self:SetType()
41 self:SetDisabled(false)
42 self:SetDescription(nil)
43 end
44
45 local function CheckBox_OnEnter(this)
46 local self = this.obj
47 self.highlight:Show()
48 self:Fire("OnEnter")
49 end
50
51 local function CheckBox_OnLeave(this)
52 local self = this.obj
53 self.highlight:Hide()
54 self:Fire("OnLeave")
55 end
56
57 local function CheckBox_OnMouseUp(this)
58 local self = this.obj
59 if not self.disabled then
60 self:ToggleChecked()
61 self:Fire("OnValueChanged",self.checked)
62 self.text:SetPoint("LEFT",self.check,"RIGHT",0,0)
63 end
64 self.down = nil
65 end
66
67 local function CheckBox_OnMouseDown(this)
68 local self = this.obj
69 if not self.disabled then
70 self.text:SetPoint("LEFT",self.check,"RIGHT",1,-1)
71 self.down = true
72 end
73 AceGUI:ClearFocus()
74 end
75
76 local function SetDisabled(self,disabled)
77 self.disabled = disabled
78 if disabled then
79 self.frame:Disable()
80 self.text:SetTextColor(0.5,0.5,0.5)
81 SetDesaturation(self.check, true)
82 else
83 self.frame:Enable()
84 self.text:SetTextColor(1,1,1)
85 if self.tristate and self.checked == nil then
86 SetDesaturation(self.check, true)
87 else
88 SetDesaturation(self.check, false)
89 end
90 end
91 end
92
93 local function SetValue(self,value)
94 local check = self.check
95 self.checked = value
96 if value then
97 SetDesaturation(self.check, false)
98 self.check:Show()
99 else
100 --Nil is the unknown tristate value
101 if self.tristate and value == nil then
102 SetDesaturation(self.check, true)
103 self.check:Show()
104 else
105 SetDesaturation(self.check, false)
106 self.check:Hide()
107 end
108 end
109 end
110
111 local function SetTriState(self, enabled)
112 self.tristate = enabled
113 self:SetValue(self:GetValue())
114 end
115
116 local function GetValue(self)
117 return self.checked
118 end
119
120 local function SetType(self, type)
121 local checkbg = self.checkbg
122 local check = self.check
123 local highlight = self.highlight
124
125 if type == "radio" then
126 checkbg:SetHeight(16)
127 checkbg:SetWidth(16)
128 checkbg:SetTexture("Interface\\Buttons\\UI-RadioButton")
129 checkbg:SetTexCoord(0,0.25,0,1)
130 check:SetHeight(16)
131 check:SetWidth(16)
132 check:SetTexture("Interface\\Buttons\\UI-RadioButton")
133 check:SetTexCoord(0.25,0.5,0,1)
134 check:SetBlendMode("ADD")
135 highlight:SetTexture("Interface\\Buttons\\UI-RadioButton")
136 highlight:SetTexCoord(0.5,0.75,0,1)
137 else
138 checkbg:SetHeight(24)
139 checkbg:SetWidth(24)
140 checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
141 checkbg:SetTexCoord(0,1,0,1)
142 check:SetHeight(24)
143 check:SetWidth(24)
144 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
145 check:SetTexCoord(0,1,0,1)
146 check:SetBlendMode("BLEND")
147 highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
148 highlight:SetTexCoord(0,1,0,1)
149 end
150 end
151
152 local function ToggleChecked(self)
153 local value = self:GetValue()
154 if self.tristate then
155 --cycle in true, nil, false order
156 if value then
157 self:SetValue(nil)
158 elseif value == nil then
159 self:SetValue(false)
160 else
161 self:SetValue(true)
162 end
163 else
164 self:SetValue(not self:GetValue())
165 end
166 end
167
168 local function SetLabel(self, label)
169 self.text:SetText(label)
170 end
171
172 local function SetDescription(self, desc)
173 if desc then
174 if not self.desc then
175 local desc = self.frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
176 desc:ClearAllPoints()
177 desc:SetPoint("TOPLEFT", self.check, "TOPRIGHT", 5, -21)
178 desc:SetWidth(self.frame.width - 30)
179 desc:SetJustifyH("LEFT")
180 desc:SetJustifyV("TOP")
181 self.desc = desc
182 end
183 self.desc:Show()
184 --self.text:SetFontObject(GameFontNormal)
185 self.desc:SetText(desc)
186 self:SetHeight(28 + self.desc:GetHeight())
187 else
188 if self.desc then
189 self.desc:SetText("")
190 self.desc:Hide()
191 end
192 self.text:SetFontObject(GameFontHighlight)
193 self:SetHeight(24)
194 end
195 end
196
197 local function SetImage(self, path, ...)
198 local image = self.image
199 image:SetTexture(path)
200
201 if image:GetTexture() then
202 local n = select('#', ...)
203 if n == 4 or n == 8 then
204 image:SetTexCoord(...)
205 else
206 image:SetTexCoord(0, 1, 0, 1)
207 end
208 end
209 self:AlignImage()
210 end
211
212 local function AlignImage(self)
213 local img = self.image:GetTexture()
214 self.text:ClearAllPoints()
215 if not img then
216 self.text:SetPoint("LEFT", self.check, "RIGHT", 0, 0)
217 self.text:SetPoint("RIGHT", self.frame, "RIGHT", 0, 0)
218 else
219 self.text:SetPoint("LEFT", self.image,"RIGHT", 1, 0)
220 self.text:SetPoint("RIGHT", self.frame,"RIGHT", 0, 0)
221 end
222 end
223
224 local function OnWidthSet(self, width)
225 if self.desc and self.desc:GetText() ~= "" then
226 self.desc:SetWidth(width - 30)
227 self:SetHeight(28 + self.desc:GetHeight())
228 end
229 end
230
231 local function Constructor()
232 local frame = CreateFrame("Button",nil,UIParent)
233 local self = {}
234 self.type = Type
235
236 self.OnRelease = OnRelease
237 self.OnAcquire = OnAcquire
238
239 self.SetValue = SetValue
240 self.GetValue = GetValue
241 self.SetDisabled = SetDisabled
242 self.SetType = SetType
243 self.ToggleChecked = ToggleChecked
244 self.SetLabel = SetLabel
245 self.SetTriState = SetTriState
246 self.SetDescription = SetDescription
247 self.OnWidthSet = OnWidthSet
248 self.SetImage = SetImage
249 self.AlignImage = AlignImage
250
251 self.frame = frame
252 frame.obj = self
253
254 local text = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight")
255 self.text = text
256
257 frame:SetScript("OnEnter",CheckBox_OnEnter)
258 frame:SetScript("OnLeave",CheckBox_OnLeave)
259 frame:SetScript("OnMouseUp",CheckBox_OnMouseUp)
260 frame:SetScript("OnMouseDown",CheckBox_OnMouseDown)
261 frame:EnableMouse()
262 local checkbg = frame:CreateTexture(nil,"ARTWORK")
263 self.checkbg = checkbg
264 checkbg:SetWidth(24)
265 checkbg:SetHeight(24)
266 checkbg:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
267 checkbg:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
268 local check = frame:CreateTexture(nil,"OVERLAY")
269 self.check = check
270 check:SetWidth(24)
271 check:SetHeight(24)
272 check:SetPoint("CENTER",checkbg,"CENTER",0,0)
273 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
274
275 local highlight = frame:CreateTexture(nil, "OVERLAY")
276 self.highlight = highlight
277 highlight:SetTexture("Interface\\Buttons\\UI-CheckBox-Highlight")
278 highlight:SetBlendMode("ADD")
279 highlight:SetAllPoints(checkbg)
280 highlight:Hide()
281
282 local image = frame:CreateTexture(nil, "OVERLAY")
283 self.image = image
284 image:SetHeight(16)
285 image:SetWidth(16)
286 image:SetPoint("LEFT", check, "RIGHT", 1, 0)
287
288 text:SetJustifyH("LEFT")
289 frame:SetHeight(24)
290 frame:SetWidth(200)
291 text:SetHeight(18)
292 text:SetPoint("LEFT",check,"RIGHT",0,0)
293 text:SetPoint("RIGHT",frame,"RIGHT",0,0)
294
295 AceGUI:RegisterAsWidget(self)
296 return self
297 end
298
299 AceGUI:RegisterWidgetType(Type,Constructor,Version)
300 end