annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-Window.lua @ 0:c6ff7ba0e8f6

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