annotate Libs/AceGUI-3.0/widgets/AceGUIContainer-Frame.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 --[[-----------------------------------------------------------------------------
Zerotorescue@0 2 Frame Container
Zerotorescue@0 3 -------------------------------------------------------------------------------]]
Zerotorescue@0 4 local Type, Version = "Frame", 21
Zerotorescue@0 5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
Zerotorescue@0 6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
Zerotorescue@0 7
Zerotorescue@0 8 -- Lua APIs
Zerotorescue@0 9 local pairs, assert, type = pairs, assert, type
Zerotorescue@0 10 local wipe = table.wipe
Zerotorescue@0 11
Zerotorescue@0 12 -- WoW APIs
Zerotorescue@0 13 local PlaySound = PlaySound
Zerotorescue@0 14 local CreateFrame, UIParent = CreateFrame, UIParent
Zerotorescue@0 15
Zerotorescue@0 16 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
Zerotorescue@0 17 -- List them here for Mikk's FindGlobals script
Zerotorescue@0 18 -- GLOBALS: CLOSE
Zerotorescue@0 19
Zerotorescue@0 20 --[[-----------------------------------------------------------------------------
Zerotorescue@0 21 Scripts
Zerotorescue@0 22 -------------------------------------------------------------------------------]]
Zerotorescue@0 23 local function Button_OnClick(frame)
Zerotorescue@0 24 PlaySound("gsTitleOptionExit")
Zerotorescue@0 25 frame.obj:Hide()
Zerotorescue@0 26 end
Zerotorescue@0 27
Zerotorescue@0 28 local function Frame_OnClose(frame)
Zerotorescue@0 29 frame.obj:Fire("OnClose")
Zerotorescue@0 30 end
Zerotorescue@0 31
Zerotorescue@0 32 local function Frame_OnMouseDown(frame)
Zerotorescue@0 33 AceGUI:ClearFocus()
Zerotorescue@0 34 end
Zerotorescue@0 35
Zerotorescue@0 36 local function Title_OnMouseDown(frame)
Zerotorescue@0 37 frame:GetParent():StartMoving()
Zerotorescue@0 38 AceGUI:ClearFocus()
Zerotorescue@0 39 end
Zerotorescue@0 40
Zerotorescue@0 41 local function MoverSizer_OnMouseUp(mover)
Zerotorescue@0 42 local frame = mover:GetParent()
Zerotorescue@0 43 frame:StopMovingOrSizing()
Zerotorescue@0 44 local self = frame.obj
Zerotorescue@0 45 local status = self.status or self.localstatus
Zerotorescue@0 46 status.width = frame:GetWidth()
Zerotorescue@0 47 status.height = frame:GetHeight()
Zerotorescue@0 48 status.top = frame:GetTop()
Zerotorescue@0 49 status.left = frame:GetLeft()
Zerotorescue@0 50 end
Zerotorescue@0 51
Zerotorescue@0 52 local function SizerSE_OnMouseDown(frame)
Zerotorescue@0 53 frame:GetParent():StartSizing("BOTTOMRIGHT")
Zerotorescue@0 54 AceGUI:ClearFocus()
Zerotorescue@0 55 end
Zerotorescue@0 56
Zerotorescue@0 57 local function SizerS_OnMouseDown(frame)
Zerotorescue@0 58 frame:GetParent():StartSizing("BOTTOM")
Zerotorescue@0 59 AceGUI:ClearFocus()
Zerotorescue@0 60 end
Zerotorescue@0 61
Zerotorescue@0 62 local function SizerE_OnMouseDown(frame)
Zerotorescue@0 63 frame:GetParent():StartSizing("RIGHT")
Zerotorescue@0 64 AceGUI:ClearFocus()
Zerotorescue@0 65 end
Zerotorescue@0 66
Zerotorescue@0 67 local function StatusBar_OnEnter(frame)
Zerotorescue@0 68 frame.obj:Fire("OnEnterStatusBar")
Zerotorescue@0 69 end
Zerotorescue@0 70
Zerotorescue@0 71 local function StatusBar_OnLeave(frame)
Zerotorescue@0 72 frame.obj:Fire("OnLeaveStatusBar")
Zerotorescue@0 73 end
Zerotorescue@0 74
Zerotorescue@0 75 --[[-----------------------------------------------------------------------------
Zerotorescue@0 76 Methods
Zerotorescue@0 77 -------------------------------------------------------------------------------]]
Zerotorescue@0 78 local methods = {
Zerotorescue@0 79 ["OnAcquire"] = function(self)
Zerotorescue@0 80 self.frame:SetParent(UIParent)
Zerotorescue@0 81 self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
Zerotorescue@0 82 self:SetTitle()
Zerotorescue@0 83 self:SetStatusText()
Zerotorescue@0 84 self:ApplyStatus()
Zerotorescue@0 85 self:Show()
Zerotorescue@0 86 end,
Zerotorescue@0 87
Zerotorescue@0 88 ["OnRelease"] = function(self)
Zerotorescue@0 89 self.status = nil
Zerotorescue@0 90 wipe(self.localstatus)
Zerotorescue@0 91 end,
Zerotorescue@0 92
Zerotorescue@0 93 ["OnWidthSet"] = function(self, width)
Zerotorescue@0 94 local content = self.content
Zerotorescue@0 95 local contentwidth = width - 34
Zerotorescue@0 96 if contentwidth < 0 then
Zerotorescue@0 97 contentwidth = 0
Zerotorescue@0 98 end
Zerotorescue@0 99 content:SetWidth(contentwidth)
Zerotorescue@0 100 content.width = contentwidth
Zerotorescue@0 101 end,
Zerotorescue@0 102
Zerotorescue@0 103 ["OnHeightSet"] = function(self, height)
Zerotorescue@0 104 local content = self.content
Zerotorescue@0 105 local contentheight = height - 57
Zerotorescue@0 106 if contentheight < 0 then
Zerotorescue@0 107 contentheight = 0
Zerotorescue@0 108 end
Zerotorescue@0 109 content:SetHeight(contentheight)
Zerotorescue@0 110 content.height = contentheight
Zerotorescue@0 111 end,
Zerotorescue@0 112
Zerotorescue@0 113 ["SetTitle"] = function(self, title)
Zerotorescue@0 114 self.titletext:SetText(title)
Zerotorescue@0 115 end,
Zerotorescue@0 116
Zerotorescue@0 117 ["SetStatusText"] = function(self, text)
Zerotorescue@0 118 self.statustext:SetText(text)
Zerotorescue@0 119 end,
Zerotorescue@0 120
Zerotorescue@0 121 ["Hide"] = function(self)
Zerotorescue@0 122 self.frame:Hide()
Zerotorescue@0 123 end,
Zerotorescue@0 124
Zerotorescue@0 125 ["Show"] = function(self)
Zerotorescue@0 126 self.frame:Show()
Zerotorescue@0 127 end,
Zerotorescue@0 128
Zerotorescue@0 129 -- called to set an external table to store status in
Zerotorescue@0 130 ["SetStatusTable"] = function(self, status)
Zerotorescue@0 131 assert(type(status) == "table")
Zerotorescue@0 132 self.status = status
Zerotorescue@0 133 self:ApplyStatus()
Zerotorescue@0 134 end,
Zerotorescue@0 135
Zerotorescue@0 136 ["ApplyStatus"] = function(self)
Zerotorescue@0 137 local status = self.status or self.localstatus
Zerotorescue@0 138 local frame = self.frame
Zerotorescue@0 139 self:SetWidth(status.width or 700)
Zerotorescue@0 140 self:SetHeight(status.height or 500)
Zerotorescue@0 141 frame:ClearAllPoints()
Zerotorescue@0 142 if status.top and status.left then
Zerotorescue@0 143 frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top)
Zerotorescue@0 144 frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0)
Zerotorescue@0 145 else
Zerotorescue@0 146 frame:SetPoint("CENTER")
Zerotorescue@0 147 end
Zerotorescue@0 148 end
Zerotorescue@0 149 }
Zerotorescue@0 150
Zerotorescue@0 151 --[[-----------------------------------------------------------------------------
Zerotorescue@0 152 Constructor
Zerotorescue@0 153 -------------------------------------------------------------------------------]]
Zerotorescue@0 154 local FrameBackdrop = {
Zerotorescue@0 155 bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
Zerotorescue@0 156 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
Zerotorescue@0 157 tile = true, tileSize = 32, edgeSize = 32,
Zerotorescue@0 158 insets = { left = 8, right = 8, top = 8, bottom = 8 }
Zerotorescue@0 159 }
Zerotorescue@0 160
Zerotorescue@0 161 local PaneBackdrop = {
Zerotorescue@0 162 bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
Zerotorescue@0 163 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
Zerotorescue@0 164 tile = true, tileSize = 16, edgeSize = 16,
Zerotorescue@0 165 insets = { left = 3, right = 3, top = 5, bottom = 3 }
Zerotorescue@0 166 }
Zerotorescue@0 167
Zerotorescue@0 168 local function Constructor()
Zerotorescue@0 169 local frame = CreateFrame("Frame", nil, UIParent)
Zerotorescue@0 170 frame:Hide()
Zerotorescue@0 171
Zerotorescue@0 172 frame:EnableMouse(true)
Zerotorescue@0 173 frame:SetMovable(true)
Zerotorescue@0 174 frame:SetResizable(true)
Zerotorescue@0 175 frame:SetFrameStrata("FULLSCREEN_DIALOG")
Zerotorescue@0 176 frame:SetBackdrop(FrameBackdrop)
Zerotorescue@0 177 frame:SetBackdropColor(0, 0, 0, 1)
Zerotorescue@0 178 frame:SetMinResize(400, 200)
Zerotorescue@0 179 frame:SetToplevel(true)
Zerotorescue@0 180 frame:SetScript("OnHide", Frame_OnClose)
Zerotorescue@0 181 frame:SetScript("OnMouseDown", Frame_OnMouseDown)
Zerotorescue@0 182
Zerotorescue@0 183 local closebutton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
Zerotorescue@0 184 closebutton:SetScript("OnClick", Button_OnClick)
Zerotorescue@0 185 closebutton:SetPoint("BOTTOMRIGHT", -27, 17)
Zerotorescue@0 186 closebutton:SetHeight(20)
Zerotorescue@0 187 closebutton:SetWidth(100)
Zerotorescue@0 188 closebutton:SetText(CLOSE)
Zerotorescue@0 189
Zerotorescue@0 190 local statusbg = CreateFrame("Button", nil, frame)
Zerotorescue@0 191 statusbg:SetPoint("BOTTOMLEFT", 15, 15)
Zerotorescue@0 192 statusbg:SetPoint("BOTTOMRIGHT", -132, 15)
Zerotorescue@0 193 statusbg:SetHeight(24)
Zerotorescue@0 194 statusbg:SetBackdrop(PaneBackdrop)
Zerotorescue@0 195 statusbg:SetBackdropColor(0.1,0.1,0.1)
Zerotorescue@0 196 statusbg:SetBackdropBorderColor(0.4,0.4,0.4)
Zerotorescue@0 197 statusbg:SetScript("OnEnter", StatusBar_OnEnter)
Zerotorescue@0 198 statusbg:SetScript("OnLeave", StatusBar_OnLeave)
Zerotorescue@0 199
Zerotorescue@0 200 local statustext = statusbg:CreateFontString(nil, "OVERLAY", "GameFontNormal")
Zerotorescue@0 201 statustext:SetPoint("TOPLEFT", 7, -2)
Zerotorescue@0 202 statustext:SetPoint("BOTTOMRIGHT", -7, 2)
Zerotorescue@0 203 statustext:SetHeight(20)
Zerotorescue@0 204 statustext:SetJustifyH("LEFT")
Zerotorescue@0 205 statustext:SetText("")
Zerotorescue@0 206
Zerotorescue@0 207 local titlebg = frame:CreateTexture(nil, "OVERLAY")
Zerotorescue@0 208 titlebg:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
Zerotorescue@0 209 titlebg:SetTexCoord(0.31, 0.67, 0, 0.63)
Zerotorescue@0 210 titlebg:SetPoint("TOP", 0, 12)
Zerotorescue@0 211 titlebg:SetWidth(100)
Zerotorescue@0 212 titlebg:SetHeight(40)
Zerotorescue@0 213
Zerotorescue@0 214 local title = CreateFrame("Frame", nil, frame)
Zerotorescue@0 215 title:EnableMouse(true)
Zerotorescue@0 216 title:SetScript("OnMouseDown", Title_OnMouseDown)
Zerotorescue@0 217 title:SetScript("OnMouseUp", MoverSizer_OnMouseUp)
Zerotorescue@0 218 title:SetAllPoints(titlebg)
Zerotorescue@0 219
Zerotorescue@0 220 local titletext = title:CreateFontString(nil, "OVERLAY", "GameFontNormal")
Zerotorescue@0 221 titletext:SetPoint("TOP", titlebg, "TOP", 0, -14)
Zerotorescue@0 222
Zerotorescue@0 223 local titlebg_l = frame:CreateTexture(nil, "OVERLAY")
Zerotorescue@0 224 titlebg_l:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
Zerotorescue@0 225 titlebg_l:SetTexCoord(0.21, 0.31, 0, 0.63)
Zerotorescue@0 226 titlebg_l:SetPoint("RIGHT", titlebg, "LEFT")
Zerotorescue@0 227 titlebg_l:SetWidth(30)
Zerotorescue@0 228 titlebg_l:SetHeight(40)
Zerotorescue@0 229
Zerotorescue@0 230 local titlebg_r = frame:CreateTexture(nil, "OVERLAY")
Zerotorescue@0 231 titlebg_r:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
Zerotorescue@0 232 titlebg_r:SetTexCoord(0.67, 0.77, 0, 0.63)
Zerotorescue@0 233 titlebg_r:SetPoint("LEFT", titlebg, "RIGHT")
Zerotorescue@0 234 titlebg_r:SetWidth(30)
Zerotorescue@0 235 titlebg_r:SetHeight(40)
Zerotorescue@0 236
Zerotorescue@0 237 local sizer_se = CreateFrame("Frame", nil, frame)
Zerotorescue@0 238 sizer_se:SetPoint("BOTTOMRIGHT")
Zerotorescue@0 239 sizer_se:SetWidth(25)
Zerotorescue@0 240 sizer_se:SetHeight(25)
Zerotorescue@0 241 sizer_se:EnableMouse()
Zerotorescue@0 242 sizer_se:SetScript("OnMouseDown",SizerSE_OnMouseDown)
Zerotorescue@0 243 sizer_se:SetScript("OnMouseUp", MoverSizer_OnMouseUp)
Zerotorescue@0 244
Zerotorescue@0 245 local line1 = sizer_se:CreateTexture(nil, "BACKGROUND")
Zerotorescue@0 246 line1:SetWidth(14)
Zerotorescue@0 247 line1:SetHeight(14)
Zerotorescue@0 248 line1:SetPoint("BOTTOMRIGHT", -8, 8)
Zerotorescue@0 249 line1:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
Zerotorescue@0 250 local x = 0.1 * 14/17
Zerotorescue@0 251 line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5)
Zerotorescue@0 252
Zerotorescue@0 253 local line2 = sizer_se:CreateTexture(nil, "BACKGROUND")
Zerotorescue@0 254 line2:SetWidth(8)
Zerotorescue@0 255 line2:SetHeight(8)
Zerotorescue@0 256 line2:SetPoint("BOTTOMRIGHT", -8, 8)
Zerotorescue@0 257 line2:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border")
Zerotorescue@0 258 local x = 0.1 * 8/17
Zerotorescue@0 259 line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5)
Zerotorescue@0 260
Zerotorescue@0 261 local sizer_s = CreateFrame("Frame", nil, frame)
Zerotorescue@0 262 sizer_s:SetPoint("BOTTOMRIGHT", -25, 0)
Zerotorescue@0 263 sizer_s:SetPoint("BOTTOMLEFT")
Zerotorescue@0 264 sizer_s:SetHeight(25)
Zerotorescue@0 265 sizer_s:EnableMouse(true)
Zerotorescue@0 266 sizer_s:SetScript("OnMouseDown", SizerS_OnMouseDown)
Zerotorescue@0 267 sizer_s:SetScript("OnMouseUp", MoverSizer_OnMouseUp)
Zerotorescue@0 268
Zerotorescue@0 269 local sizer_e = CreateFrame("Frame", nil, frame)
Zerotorescue@0 270 sizer_e:SetPoint("BOTTOMRIGHT", 0, 25)
Zerotorescue@0 271 sizer_e:SetPoint("TOPRIGHT")
Zerotorescue@0 272 sizer_e:SetWidth(25)
Zerotorescue@0 273 sizer_e:EnableMouse(true)
Zerotorescue@0 274 sizer_e:SetScript("OnMouseDown", SizerE_OnMouseDown)
Zerotorescue@0 275 sizer_e:SetScript("OnMouseUp", MoverSizer_OnMouseUp)
Zerotorescue@0 276
Zerotorescue@0 277 --Container Support
Zerotorescue@0 278 local content = CreateFrame("Frame", nil, frame)
Zerotorescue@0 279 content:SetPoint("TOPLEFT", 17, -27)
Zerotorescue@0 280 content:SetPoint("BOTTOMRIGHT", -17, 40)
Zerotorescue@0 281
Zerotorescue@0 282 local widget = {
Zerotorescue@0 283 localstatus = {},
Zerotorescue@0 284 titletext = titletext,
Zerotorescue@0 285 statustext = statustext,
Zerotorescue@0 286 content = content,
Zerotorescue@0 287 frame = frame,
Zerotorescue@0 288 type = Type
Zerotorescue@0 289 }
Zerotorescue@0 290 for method, func in pairs(methods) do
Zerotorescue@0 291 widget[method] = func
Zerotorescue@0 292 end
Zerotorescue@0 293 closebutton.obj, statusbg.obj = widget, widget
Zerotorescue@0 294
Zerotorescue@0 295 return AceGUI:RegisterAsContainer(widget)
Zerotorescue@0 296 end
Zerotorescue@0 297
Zerotorescue@0 298 AceGUI:RegisterWidgetType(Type, Constructor, Version)