annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-Window.lua @ 63:3552946c0b9a tip

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