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