annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-Window.lua @ 106:e635cd648e01 v49

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