annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Window.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 pairs, assert, type = pairs, assert, type
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: GameFontNormal
Asa@0 12
Asa@0 13 ----------------
Asa@0 14 -- Main Frame --
Asa@0 15 ----------------
Asa@0 16 --[[
Asa@0 17 Events :
Asa@0 18 OnClose
Asa@0 19
Asa@0 20 ]]
Asa@0 21 do
Asa@0 22 local Type = "Window"
Asa@0 23 local Version = 2
Asa@0 24
Asa@0 25 local function frameOnClose(this)
Asa@0 26 this.obj:Fire("OnClose")
Asa@0 27 end
Asa@0 28
Asa@0 29 local function closeOnClick(this)
Asa@0 30 this.obj:Hide()
Asa@0 31 end
Asa@0 32
Asa@0 33 local function frameOnMouseDown(this)
Asa@0 34 AceGUI:ClearFocus()
Asa@0 35 end
Asa@0 36
Asa@0 37 local function titleOnMouseDown(this)
Asa@0 38 this:GetParent():StartMoving()
Asa@0 39 AceGUI:ClearFocus()
Asa@0 40 end
Asa@0 41
Asa@0 42 local function frameOnMouseUp(this)
Asa@0 43 local frame = this:GetParent()
Asa@0 44 frame:StopMovingOrSizing()
Asa@0 45 local self = frame.obj
Asa@0 46 local status = self.status or self.localstatus
Asa@0 47 status.width = frame:GetWidth()
Asa@0 48 status.height = frame:GetHeight()
Asa@0 49 status.top = frame:GetTop()
Asa@0 50 status.left = frame:GetLeft()
Asa@0 51 end
Asa@0 52
Asa@0 53 local function sizerseOnMouseDown(this)
Asa@0 54 this:GetParent():StartSizing("BOTTOMRIGHT")
Asa@0 55 AceGUI:ClearFocus()
Asa@0 56 end
Asa@0 57
Asa@0 58 local function sizersOnMouseDown(this)
Asa@0 59 this:GetParent():StartSizing("BOTTOM")
Asa@0 60 AceGUI:ClearFocus()
Asa@0 61 end
Asa@0 62
Asa@0 63 local function sizereOnMouseDown(this)
Asa@0 64 this:GetParent():StartSizing("RIGHT")
Asa@0 65 AceGUI:ClearFocus()
Asa@0 66 end
Asa@0 67
Asa@0 68 local function sizerOnMouseUp(this)
Asa@0 69 this:GetParent():StopMovingOrSizing()
Asa@0 70 end
Asa@0 71
Asa@0 72 local function SetTitle(self,title)
Asa@0 73 self.titletext:SetText(title)
Asa@0 74 end
Asa@0 75
Asa@0 76 local function SetStatusText(self,text)
Asa@0 77 -- self.statustext:SetText(text)
Asa@0 78 end
Asa@0 79
Asa@0 80 local function Hide(self)
Asa@0 81 self.frame:Hide()
Asa@0 82 end
Asa@0 83
Asa@0 84 local function Show(self)
Asa@0 85 self.frame:Show()
Asa@0 86 end
Asa@0 87
Asa@0 88 local function OnAcquire(self)
Asa@0 89 self.frame:SetParent(UIParent)
Asa@0 90 self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
Asa@0 91 self:ApplyStatus()
Asa@0 92 self:EnableResize(true)
Asa@0 93 end
Asa@0 94
Asa@0 95 local function OnRelease(self)
Asa@0 96 self.status = nil
Asa@0 97 for k in pairs(self.localstatus) do
Asa@0 98 self.localstatus[k] = nil
Asa@0 99 end
Asa@0 100 end
Asa@0 101
Asa@0 102 -- called to set an external table to store status in
Asa@0 103 local function SetStatusTable(self, status)
Asa@0 104 assert(type(status) == "table")
Asa@0 105 self.status = status
Asa@0 106 self:ApplyStatus()
Asa@0 107 end
Asa@0 108
Asa@0 109 local function ApplyStatus(self)
Asa@0 110 local status = self.status or self.localstatus
Asa@0 111 local frame = self.frame
Asa@0 112 self:SetWidth(status.width or 700)
Asa@0 113 self:SetHeight(status.height or 500)
Asa@0 114 if status.top and status.left then
Asa@0 115 frame:SetPoint("TOP",UIParent,"BOTTOM",0,status.top)
Asa@0 116 frame:SetPoint("LEFT",UIParent,"LEFT",status.left,0)
Asa@0 117 else
Asa@0 118 frame:SetPoint("CENTER",UIParent,"CENTER")
Asa@0 119 end
Asa@0 120 end
Asa@0 121
Asa@0 122 local function OnWidthSet(self, width)
Asa@0 123 local content = self.content
Asa@0 124 local contentwidth = width - 34
Asa@0 125 if contentwidth < 0 then
Asa@0 126 contentwidth = 0
Asa@0 127 end
Asa@0 128 content:SetWidth(contentwidth)
Asa@0 129 content.width = contentwidth
Asa@0 130 end
Asa@0 131
Asa@0 132
Asa@0 133 local function OnHeightSet(self, height)
Asa@0 134 local content = self.content
Asa@0 135 local contentheight = height - 57
Asa@0 136 if contentheight < 0 then
Asa@0 137 contentheight = 0
Asa@0 138 end
Asa@0 139 content:SetHeight(contentheight)
Asa@0 140 content.height = contentheight
Asa@0 141 end
Asa@0 142
Asa@0 143 local function EnableResize(self, state)
Asa@0 144 local func = state and "Show" or "Hide"
Asa@0 145 self.sizer_se[func](self.sizer_se)
Asa@0 146 self.sizer_s[func](self.sizer_s)
Asa@0 147 self.sizer_e[func](self.sizer_e)
Asa@0 148 end
Asa@0 149
Asa@0 150 local function Constructor()
Asa@0 151 local frame = CreateFrame("Frame",nil,UIParent)
Asa@0 152 local self = {}
Asa@0 153 self.type = "Window"
Asa@0 154
Asa@0 155 self.Hide = Hide
Asa@0 156 self.Show = Show
Asa@0 157 self.SetTitle = SetTitle
Asa@0 158 self.OnRelease = OnRelease
Asa@0 159 self.OnAcquire = OnAcquire
Asa@0 160 self.SetStatusText = SetStatusText
Asa@0 161 self.SetStatusTable = SetStatusTable
Asa@0 162 self.ApplyStatus = ApplyStatus
Asa@0 163 self.OnWidthSet = OnWidthSet
Asa@0 164 self.OnHeightSet = OnHeightSet
Asa@0 165 self.EnableResize = EnableResize
Asa@0 166
Asa@0 167 self.localstatus = {}
Asa@0 168
Asa@0 169 self.frame = frame
Asa@0 170 frame.obj = self
Asa@0 171 frame:SetWidth(700)
Asa@0 172 frame:SetHeight(500)
Asa@0 173 frame:SetPoint("CENTER",UIParent,"CENTER",0,0)
Asa@0 174 frame:EnableMouse()
Asa@0 175 frame:SetMovable(true)
Asa@0 176 frame:SetResizable(true)
Asa@0 177 frame:SetFrameStrata("FULLSCREEN_DIALOG")
Asa@0 178 frame:SetScript("OnMouseDown", frameOnMouseDown)
Asa@0 179
Asa@0 180 frame:SetScript("OnHide",frameOnClose)
Asa@0 181 frame:SetMinResize(240,240)
Asa@0 182 frame:SetToplevel(true)
Asa@0 183
Asa@0 184 local titlebg = frame:CreateTexture(nil, "BACKGROUND")
Asa@0 185 titlebg:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Title-Background]])
Asa@0 186 titlebg:SetPoint("TOPLEFT", 9, -6)
Asa@0 187 titlebg:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -28, -24)
Asa@0 188
Asa@0 189 local dialogbg = frame:CreateTexture(nil, "BACKGROUND")
Asa@0 190 dialogbg:SetTexture([[Interface\Tooltips\UI-Tooltip-Background]])
Asa@0 191 dialogbg:SetPoint("TOPLEFT", 8, -24)
Asa@0 192 dialogbg:SetPoint("BOTTOMRIGHT", -6, 8)
Asa@0 193 dialogbg:SetVertexColor(0, 0, 0, .75)
Asa@0 194
Asa@0 195 local topleft = frame:CreateTexture(nil, "BORDER")
Asa@0 196 topleft:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 197 topleft:SetWidth(64)
Asa@0 198 topleft:SetHeight(64)
Asa@0 199 topleft:SetPoint("TOPLEFT")
Asa@0 200 topleft:SetTexCoord(0.501953125, 0.625, 0, 1)
Asa@0 201
Asa@0 202 local topright = frame:CreateTexture(nil, "BORDER")
Asa@0 203 topright:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 204 topright:SetWidth(64)
Asa@0 205 topright:SetHeight(64)
Asa@0 206 topright:SetPoint("TOPRIGHT")
Asa@0 207 topright:SetTexCoord(0.625, 0.75, 0, 1)
Asa@0 208
Asa@0 209 local top = frame:CreateTexture(nil, "BORDER")
Asa@0 210 top:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 211 top:SetHeight(64)
Asa@0 212 top:SetPoint("TOPLEFT", topleft, "TOPRIGHT")
Asa@0 213 top:SetPoint("TOPRIGHT", topright, "TOPLEFT")
Asa@0 214 top:SetTexCoord(0.25, 0.369140625, 0, 1)
Asa@0 215
Asa@0 216 local bottomleft = frame:CreateTexture(nil, "BORDER")
Asa@0 217 bottomleft:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 218 bottomleft:SetWidth(64)
Asa@0 219 bottomleft:SetHeight(64)
Asa@0 220 bottomleft:SetPoint("BOTTOMLEFT")
Asa@0 221 bottomleft:SetTexCoord(0.751953125, 0.875, 0, 1)
Asa@0 222
Asa@0 223 local bottomright = frame:CreateTexture(nil, "BORDER")
Asa@0 224 bottomright:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 225 bottomright:SetWidth(64)
Asa@0 226 bottomright:SetHeight(64)
Asa@0 227 bottomright:SetPoint("BOTTOMRIGHT")
Asa@0 228 bottomright:SetTexCoord(0.875, 1, 0, 1)
Asa@0 229
Asa@0 230 local bottom = frame:CreateTexture(nil, "BORDER")
Asa@0 231 bottom:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 232 bottom:SetHeight(64)
Asa@0 233 bottom:SetPoint("BOTTOMLEFT", bottomleft, "BOTTOMRIGHT")
Asa@0 234 bottom:SetPoint("BOTTOMRIGHT", bottomright, "BOTTOMLEFT")
Asa@0 235 bottom:SetTexCoord(0.376953125, 0.498046875, 0, 1)
Asa@0 236
Asa@0 237 local left = frame:CreateTexture(nil, "BORDER")
Asa@0 238 left:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 239 left:SetWidth(64)
Asa@0 240 left:SetPoint("TOPLEFT", topleft, "BOTTOMLEFT")
Asa@0 241 left:SetPoint("BOTTOMLEFT", bottomleft, "TOPLEFT")
Asa@0 242 left:SetTexCoord(0.001953125, 0.125, 0, 1)
Asa@0 243
Asa@0 244 local right = frame:CreateTexture(nil, "BORDER")
Asa@0 245 right:SetTexture([[Interface\PaperDollInfoFrame\UI-GearManager-Border]])
Asa@0 246 right:SetWidth(64)
Asa@0 247 right:SetPoint("TOPRIGHT", topright, "BOTTOMRIGHT")
Asa@0 248 right:SetPoint("BOTTOMRIGHT", bottomright, "TOPRIGHT")
Asa@0 249 right:SetTexCoord(0.1171875, 0.2421875, 0, 1)
Asa@0 250
Asa@0 251 local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
Asa@0 252 close:SetPoint("TOPRIGHT", 2, 1)
Asa@0 253 close:SetScript("OnClick", closeOnClick)
Asa@0 254 self.closebutton = close
Asa@0 255 close.obj = self
Asa@0 256
Asa@0 257 local titletext = frame:CreateFontString(nil, "ARTWORK")
Asa@0 258 titletext:SetFontObject(GameFontNormal)
Asa@0 259 titletext:SetPoint("TOPLEFT", 12, -8)
Asa@0 260 titletext:SetPoint("TOPRIGHT", -32, -8)
Asa@0 261 self.titletext = titletext
Asa@0 262
Asa@0 263 local title = CreateFrame("Button", nil, frame)
Asa@0 264 title:SetPoint("TOPLEFT", titlebg)
Asa@0 265 title:SetPoint("BOTTOMRIGHT", titlebg)
Asa@0 266 title:EnableMouse()
Asa@0 267 title:SetScript("OnMouseDown",titleOnMouseDown)
Asa@0 268 title:SetScript("OnMouseUp", frameOnMouseUp)
Asa@0 269 self.title = title
Asa@0 270
Asa@0 271 local sizer_se = CreateFrame("Frame",nil,frame)
Asa@0 272 sizer_se:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0)
Asa@0 273 sizer_se:SetWidth(25)
Asa@0 274 sizer_se:SetHeight(25)
Asa@0 275 sizer_se:EnableMouse()
Asa@0 276 sizer_se:SetScript("OnMouseDown",sizerseOnMouseDown)
Asa@0 277 sizer_se:SetScript("OnMouseUp", sizerOnMouseUp)
Asa@0 278 self.sizer_se = sizer_se
Asa@0 279
Asa@0 280 local line1 = sizer_se:CreateTexture(nil, "BACKGROUND")
Asa@0 281 self.line1 = line1
Asa@0 282 line1:SetWidth(14)
Asa@0 283 line1:SetHeight(14)
Asa@0 284 line1:SetPoint("BOTTOMRIGHT", -8, 8)
Asa@0 285 line1:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
Asa@0 286 local x = 0.1 * 14/17
Asa@0 287 line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5)
Asa@0 288
Asa@0 289 local line2 = sizer_se:CreateTexture(nil, "BACKGROUND")
Asa@0 290 self.line2 = line2
Asa@0 291 line2:SetWidth(8)
Asa@0 292 line2:SetHeight(8)
Asa@0 293 line2:SetPoint("BOTTOMRIGHT", -8, 8)
Asa@0 294 line2:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
Asa@0 295 local x = 0.1 * 8/17
Asa@0 296 line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5)
Asa@0 297
Asa@0 298 local sizer_s = CreateFrame("Frame",nil,frame)
Asa@0 299 sizer_s:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-25,0)
Asa@0 300 sizer_s:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",0,0)
Asa@0 301 sizer_s:SetHeight(25)
Asa@0 302 sizer_s:EnableMouse()
Asa@0 303 sizer_s:SetScript("OnMouseDown",sizersOnMouseDown)
Asa@0 304 sizer_s:SetScript("OnMouseUp", sizerOnMouseUp)
Asa@0 305 self.sizer_s = sizer_s
Asa@0 306
Asa@0 307 local sizer_e = CreateFrame("Frame",nil,frame)
Asa@0 308 sizer_e:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,25)
Asa@0 309 sizer_e:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0)
Asa@0 310 sizer_e:SetWidth(25)
Asa@0 311 sizer_e:EnableMouse()
Asa@0 312 sizer_e:SetScript("OnMouseDown",sizereOnMouseDown)
Asa@0 313 sizer_e:SetScript("OnMouseUp", sizerOnMouseUp)
Asa@0 314 self.sizer_e = sizer_e
Asa@0 315
Asa@0 316 --Container Support
Asa@0 317 local content = CreateFrame("Frame",nil,frame)
Asa@0 318 self.content = content
Asa@0 319 content.obj = self
Asa@0 320 content:SetPoint("TOPLEFT",frame,"TOPLEFT",12,-32)
Asa@0 321 content:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-12,13)
Asa@0 322
Asa@0 323 AceGUI:RegisterAsContainer(self)
Asa@0 324 return self
Asa@0 325 end
Asa@0 326
Asa@0 327 AceGUI:RegisterWidgetType(Type,Constructor,Version)
Asa@0 328 end