Mercurial > wow > icu
comparison Libs/AceGUI-3.0/widgets/AceGUIContainer-Frame.lua @ 0:98c6f55e6619
First commit
| author | Xiiph |
|---|---|
| date | Sat, 05 Feb 2011 16:45:02 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:98c6f55e6619 |
|---|---|
| 1 --[[----------------------------------------------------------------------------- | |
| 2 Frame Container | |
| 3 -------------------------------------------------------------------------------]] | |
| 4 local Type, Version = "Frame", 22 | |
| 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 self.titlebg:SetWidth((self.titletext:GetWidth() or 0) + 10) | |
| 116 end, | |
| 117 | |
| 118 ["SetStatusText"] = function(self, text) | |
| 119 self.statustext:SetText(text) | |
| 120 end, | |
| 121 | |
| 122 ["Hide"] = function(self) | |
| 123 self.frame:Hide() | |
| 124 end, | |
| 125 | |
| 126 ["Show"] = function(self) | |
| 127 self.frame:Show() | |
| 128 end, | |
| 129 | |
| 130 -- called to set an external table to store status in | |
| 131 ["SetStatusTable"] = function(self, status) | |
| 132 assert(type(status) == "table") | |
| 133 self.status = status | |
| 134 self:ApplyStatus() | |
| 135 end, | |
| 136 | |
| 137 ["ApplyStatus"] = function(self) | |
| 138 local status = self.status or self.localstatus | |
| 139 local frame = self.frame | |
| 140 self:SetWidth(status.width or 700) | |
| 141 self:SetHeight(status.height or 500) | |
| 142 frame:ClearAllPoints() | |
| 143 if status.top and status.left then | |
| 144 frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top) | |
| 145 frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0) | |
| 146 else | |
| 147 frame:SetPoint("CENTER") | |
| 148 end | |
| 149 end | |
| 150 } | |
| 151 | |
| 152 --[[----------------------------------------------------------------------------- | |
| 153 Constructor | |
| 154 -------------------------------------------------------------------------------]] | |
| 155 local FrameBackdrop = { | |
| 156 bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", | |
| 157 edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", | |
| 158 tile = true, tileSize = 32, edgeSize = 32, | |
| 159 insets = { left = 8, right = 8, top = 8, bottom = 8 } | |
| 160 } | |
| 161 | |
| 162 local PaneBackdrop = { | |
| 163 bgFile = "Interface\\ChatFrame\\ChatFrameBackground", | |
| 164 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", | |
| 165 tile = true, tileSize = 16, edgeSize = 16, | |
| 166 insets = { left = 3, right = 3, top = 5, bottom = 3 } | |
| 167 } | |
| 168 | |
| 169 local function Constructor() | |
| 170 local frame = CreateFrame("Frame", nil, UIParent) | |
| 171 frame:Hide() | |
| 172 | |
| 173 frame:EnableMouse(true) | |
| 174 frame:SetMovable(true) | |
| 175 frame:SetResizable(true) | |
| 176 frame:SetFrameStrata("FULLSCREEN_DIALOG") | |
| 177 frame:SetBackdrop(FrameBackdrop) | |
| 178 frame:SetBackdropColor(0, 0, 0, 1) | |
| 179 frame:SetMinResize(400, 200) | |
| 180 frame:SetToplevel(true) | |
| 181 frame:SetScript("OnHide", Frame_OnClose) | |
| 182 frame:SetScript("OnMouseDown", Frame_OnMouseDown) | |
| 183 | |
| 184 local closebutton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") | |
| 185 closebutton:SetScript("OnClick", Button_OnClick) | |
| 186 closebutton:SetPoint("BOTTOMRIGHT", -27, 17) | |
| 187 closebutton:SetHeight(20) | |
| 188 closebutton:SetWidth(100) | |
| 189 closebutton:SetText(CLOSE) | |
| 190 | |
| 191 local statusbg = CreateFrame("Button", nil, frame) | |
| 192 statusbg:SetPoint("BOTTOMLEFT", 15, 15) | |
| 193 statusbg:SetPoint("BOTTOMRIGHT", -132, 15) | |
| 194 statusbg:SetHeight(24) | |
| 195 statusbg:SetBackdrop(PaneBackdrop) | |
| 196 statusbg:SetBackdropColor(0.1,0.1,0.1) | |
| 197 statusbg:SetBackdropBorderColor(0.4,0.4,0.4) | |
| 198 statusbg:SetScript("OnEnter", StatusBar_OnEnter) | |
| 199 statusbg:SetScript("OnLeave", StatusBar_OnLeave) | |
| 200 | |
| 201 local statustext = statusbg:CreateFontString(nil, "OVERLAY", "GameFontNormal") | |
| 202 statustext:SetPoint("TOPLEFT", 7, -2) | |
| 203 statustext:SetPoint("BOTTOMRIGHT", -7, 2) | |
| 204 statustext:SetHeight(20) | |
| 205 statustext:SetJustifyH("LEFT") | |
| 206 statustext:SetText("") | |
| 207 | |
| 208 local titlebg = frame:CreateTexture(nil, "OVERLAY") | |
| 209 titlebg:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") | |
| 210 titlebg:SetTexCoord(0.31, 0.67, 0, 0.63) | |
| 211 titlebg:SetPoint("TOP", 0, 12) | |
| 212 titlebg:SetWidth(100) | |
| 213 titlebg:SetHeight(40) | |
| 214 | |
| 215 local title = CreateFrame("Frame", nil, frame) | |
| 216 title:EnableMouse(true) | |
| 217 title:SetScript("OnMouseDown", Title_OnMouseDown) | |
| 218 title:SetScript("OnMouseUp", MoverSizer_OnMouseUp) | |
| 219 title:SetAllPoints(titlebg) | |
| 220 | |
| 221 local titletext = title:CreateFontString(nil, "OVERLAY", "GameFontNormal") | |
| 222 titletext:SetPoint("TOP", titlebg, "TOP", 0, -14) | |
| 223 | |
| 224 local titlebg_l = frame:CreateTexture(nil, "OVERLAY") | |
| 225 titlebg_l:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") | |
| 226 titlebg_l:SetTexCoord(0.21, 0.31, 0, 0.63) | |
| 227 titlebg_l:SetPoint("RIGHT", titlebg, "LEFT") | |
| 228 titlebg_l:SetWidth(30) | |
| 229 titlebg_l:SetHeight(40) | |
| 230 | |
| 231 local titlebg_r = frame:CreateTexture(nil, "OVERLAY") | |
| 232 titlebg_r:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") | |
| 233 titlebg_r:SetTexCoord(0.67, 0.77, 0, 0.63) | |
| 234 titlebg_r:SetPoint("LEFT", titlebg, "RIGHT") | |
| 235 titlebg_r:SetWidth(30) | |
| 236 titlebg_r:SetHeight(40) | |
| 237 | |
| 238 local sizer_se = CreateFrame("Frame", nil, frame) | |
| 239 sizer_se:SetPoint("BOTTOMRIGHT") | |
| 240 sizer_se:SetWidth(25) | |
| 241 sizer_se:SetHeight(25) | |
| 242 sizer_se:EnableMouse() | |
| 243 sizer_se:SetScript("OnMouseDown",SizerSE_OnMouseDown) | |
| 244 sizer_se:SetScript("OnMouseUp", MoverSizer_OnMouseUp) | |
| 245 | |
| 246 local line1 = sizer_se:CreateTexture(nil, "BACKGROUND") | |
| 247 line1:SetWidth(14) | |
| 248 line1:SetHeight(14) | |
| 249 line1:SetPoint("BOTTOMRIGHT", -8, 8) | |
| 250 line1:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") | |
| 251 local x = 0.1 * 14/17 | |
| 252 line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) | |
| 253 | |
| 254 local line2 = sizer_se:CreateTexture(nil, "BACKGROUND") | |
| 255 line2:SetWidth(8) | |
| 256 line2:SetHeight(8) | |
| 257 line2:SetPoint("BOTTOMRIGHT", -8, 8) | |
| 258 line2:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") | |
| 259 local x = 0.1 * 8/17 | |
| 260 line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) | |
| 261 | |
| 262 local sizer_s = CreateFrame("Frame", nil, frame) | |
| 263 sizer_s:SetPoint("BOTTOMRIGHT", -25, 0) | |
| 264 sizer_s:SetPoint("BOTTOMLEFT") | |
| 265 sizer_s:SetHeight(25) | |
| 266 sizer_s:EnableMouse(true) | |
| 267 sizer_s:SetScript("OnMouseDown", SizerS_OnMouseDown) | |
| 268 sizer_s:SetScript("OnMouseUp", MoverSizer_OnMouseUp) | |
| 269 | |
| 270 local sizer_e = CreateFrame("Frame", nil, frame) | |
| 271 sizer_e:SetPoint("BOTTOMRIGHT", 0, 25) | |
| 272 sizer_e:SetPoint("TOPRIGHT") | |
| 273 sizer_e:SetWidth(25) | |
| 274 sizer_e:EnableMouse(true) | |
| 275 sizer_e:SetScript("OnMouseDown", SizerE_OnMouseDown) | |
| 276 sizer_e:SetScript("OnMouseUp", MoverSizer_OnMouseUp) | |
| 277 | |
| 278 --Container Support | |
| 279 local content = CreateFrame("Frame", nil, frame) | |
| 280 content:SetPoint("TOPLEFT", 17, -27) | |
| 281 content:SetPoint("BOTTOMRIGHT", -17, 40) | |
| 282 | |
| 283 local widget = { | |
| 284 localstatus = {}, | |
| 285 titletext = titletext, | |
| 286 statustext = statustext, | |
| 287 titlebg = titlebg, | |
| 288 content = content, | |
| 289 frame = frame, | |
| 290 type = Type | |
| 291 } | |
| 292 for method, func in pairs(methods) do | |
| 293 widget[method] = func | |
| 294 end | |
| 295 closebutton.obj, statusbg.obj = widget, widget | |
| 296 | |
| 297 return AceGUI:RegisterAsContainer(widget) | |
| 298 end | |
| 299 | |
| 300 AceGUI:RegisterWidgetType(Type, Constructor, Version) |
