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