annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-Window.lua @ 57:01b63b8ed811 v21

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