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