Asa@0: local AceGUI = LibStub("AceGUI-3.0") Asa@0: Asa@0: Asa@0: ------------- Asa@0: -- Widgets -- Asa@0: ------------- Asa@0: --[[ Asa@0: Widgets must provide the following functions Asa@0: Acquire() - Called when the object is aquired, should set everything to a default hidden state Asa@0: Release() - Called when the object is Released, should remove any anchors and hide the Widget Asa@0: Asa@0: And the following members Asa@0: frame - the frame or derivitive object that will be treated as the widget for size and anchoring purposes Asa@0: type - the type of the object, same as the name given to :RegisterWidget() Asa@0: Asa@0: Widgets contain a table called userdata, this is a safe place to store data associated with the wigdet Asa@0: It will be cleared automatically when a widget is released Asa@0: Placing values directly into a widget object should be avoided Asa@0: Asa@0: If the Widget can act as a container for other Widgets the following Asa@0: content - frame or derivitive that children will be anchored to Asa@0: Asa@0: The Widget can supply the following Optional Members Asa@0: Asa@0: Asa@0: ]] Asa@0: Asa@0: ---------------------------------- Asa@0: -- Blizzard Options Group -- Asa@0: ---------------------------------- Asa@0: --[[ Asa@0: Group Designed to be added to the bliz interface options panel Asa@0: ]] Asa@0: Asa@0: -- WoW APIs Asa@0: local CreateFrame = CreateFrame Asa@0: Asa@0: do Asa@0: local Type = "BlizOptionsGroup" Asa@0: local Version = 10 Asa@0: Asa@0: local function OnAcquire(self) Asa@0: Asa@0: end Asa@0: Asa@0: local function OnRelease(self) Asa@0: self.frame:ClearAllPoints() Asa@0: self.frame:Hide() Asa@0: self:SetName() Asa@0: end Asa@0: Asa@0: local function okay(this) Asa@0: this.obj:Fire("okay") Asa@0: end Asa@0: Asa@0: local function cancel(this) Asa@0: this.obj:Fire("cancel") Asa@0: end Asa@0: Asa@0: local function defaults(this) Asa@0: this.obj:Fire("defaults") Asa@0: end Asa@0: Asa@0: local function SetName(self, name, parent) Asa@0: self.frame.name = name Asa@0: self.frame.parent = parent Asa@0: end Asa@0: Asa@0: local function OnShow(this) Asa@0: this.obj:Fire("OnShow") Asa@0: end Asa@0: Asa@0: local function OnHide(this) Asa@0: this.obj:Fire("OnHide") Asa@0: end Asa@0: Asa@0: local function OnWidthSet(self, width) Asa@0: local content = self.content Asa@0: local contentwidth = width - 63 Asa@0: if contentwidth < 0 then Asa@0: contentwidth = 0 Asa@0: end Asa@0: content:SetWidth(contentwidth) Asa@0: content.width = contentwidth Asa@0: end Asa@0: Asa@0: Asa@0: local function OnHeightSet(self, height) Asa@0: local content = self.content Asa@0: local contentheight = height - 26 Asa@0: if contentheight < 0 then Asa@0: contentheight = 0 Asa@0: end Asa@0: content:SetHeight(contentheight) Asa@0: content.height = contentheight Asa@0: end Asa@0: Asa@0: local function SetTitle(self, title) Asa@0: local content = self.content Asa@0: content:ClearAllPoints() Asa@0: if not title or title == "" then Asa@0: content:SetPoint("TOPLEFT",self.frame,"TOPLEFT",10,-10) Asa@0: self.label:SetText("") Asa@0: else Asa@0: content:SetPoint("TOPLEFT",self.frame,"TOPLEFT",10,-40) Asa@0: self.label:SetText(title) Asa@0: end Asa@0: content:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT",-10,10) Asa@0: end Asa@0: Asa@0: local function Constructor() Asa@0: local frame = CreateFrame("Frame") Asa@0: local self = {} Asa@0: self.type = Type Asa@0: Asa@0: self.OnRelease = OnRelease Asa@0: self.OnAcquire = OnAcquire Asa@0: self.frame = frame Asa@0: self.SetName = SetName Asa@0: Asa@0: self.OnWidthSet = OnWidthSet Asa@0: self.OnHeightSet = OnHeightSet Asa@0: self.SetTitle = SetTitle Asa@0: Asa@0: frame.obj = self Asa@0: frame.okay = okay Asa@0: frame.cancel = cancel Asa@0: frame.defaults = defaults Asa@0: Asa@0: frame:Hide() Asa@0: frame:SetScript("OnHide",OnHide) Asa@0: frame:SetScript("OnShow",OnShow) Asa@0: Asa@0: local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalLarge") Asa@0: self.label = label Asa@0: label:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -15) Asa@0: label:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 10, -45) Asa@0: label:SetJustifyH("LEFT") Asa@0: label:SetJustifyV("TOP") Asa@0: Asa@0: --Container Support Asa@0: local content = CreateFrame("Frame",nil,frame) Asa@0: self.content = content Asa@0: content.obj = self Asa@0: content:SetPoint("TOPLEFT",frame,"TOPLEFT",15,-10) Asa@0: content:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-10,10) Asa@0: Asa@0: AceGUI:RegisterAsContainer(self) Asa@0: return self Asa@0: end Asa@0: Asa@0: AceGUI:RegisterWidgetType(Type,Constructor,Version) Asa@0: end