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