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