Zerotorescue@0: --[[----------------------------------------------------------------------------- Zerotorescue@0: Button Widget Zerotorescue@0: Graphical Button. Zerotorescue@0: -------------------------------------------------------------------------------]] Zerotorescue@0: local Type, Version = "Button", 20 Zerotorescue@0: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) Zerotorescue@0: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end Zerotorescue@0: Zerotorescue@0: -- Lua APIs Zerotorescue@0: local pairs = pairs Zerotorescue@0: Zerotorescue@0: -- WoW APIs Zerotorescue@0: local _G = _G Zerotorescue@0: local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent Zerotorescue@0: Zerotorescue@0: --[[----------------------------------------------------------------------------- Zerotorescue@0: Scripts Zerotorescue@0: -------------------------------------------------------------------------------]] Zerotorescue@0: local function Button_OnClick(frame, ...) Zerotorescue@0: PlaySound("igMainMenuOption") Zerotorescue@0: frame.obj:Fire("OnClick", ...) Zerotorescue@0: AceGUI:ClearFocus() Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function Control_OnEnter(frame) Zerotorescue@0: frame.obj:Fire("OnEnter") Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local function Control_OnLeave(frame) Zerotorescue@0: frame.obj:Fire("OnLeave") Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: --[[----------------------------------------------------------------------------- Zerotorescue@0: Methods Zerotorescue@0: -------------------------------------------------------------------------------]] Zerotorescue@0: local methods = { Zerotorescue@0: ["OnAcquire"] = function(self) Zerotorescue@0: -- restore default values Zerotorescue@0: self:SetHeight(24) Zerotorescue@0: self:SetWidth(200) Zerotorescue@0: self:SetDisabled(false) Zerotorescue@0: self:SetText() Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: -- ["OnRelease"] = nil, Zerotorescue@0: Zerotorescue@0: ["SetText"] = function(self, text) Zerotorescue@0: self.text:SetText(text) Zerotorescue@0: end, Zerotorescue@0: Zerotorescue@0: ["SetDisabled"] = function(self, disabled) Zerotorescue@0: self.disabled = disabled Zerotorescue@0: if disabled then Zerotorescue@0: self.frame:Disable() Zerotorescue@0: else Zerotorescue@0: self.frame:Enable() Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: } Zerotorescue@0: Zerotorescue@0: --[[----------------------------------------------------------------------------- Zerotorescue@0: Constructor Zerotorescue@0: -------------------------------------------------------------------------------]] Zerotorescue@0: local function Constructor() Zerotorescue@0: local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type) Zerotorescue@0: local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate2") Zerotorescue@0: frame:Hide() Zerotorescue@0: Zerotorescue@0: frame:EnableMouse(true) Zerotorescue@0: frame:SetScript("OnClick", Button_OnClick) Zerotorescue@0: frame:SetScript("OnEnter", Control_OnEnter) Zerotorescue@0: frame:SetScript("OnLeave", Control_OnLeave) Zerotorescue@0: Zerotorescue@0: local text = frame:GetFontString() Zerotorescue@0: text:ClearAllPoints() Zerotorescue@0: text:SetPoint("TOPLEFT", 15, -1) Zerotorescue@0: text:SetPoint("BOTTOMRIGHT", -15, 1) Zerotorescue@0: text:SetJustifyV("MIDDLE") Zerotorescue@0: Zerotorescue@0: local widget = { Zerotorescue@0: text = text, Zerotorescue@0: frame = frame, Zerotorescue@0: type = Type Zerotorescue@0: } Zerotorescue@0: for method, func in pairs(methods) do Zerotorescue@0: widget[method] = func Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: return AceGUI:RegisterAsWidget(widget) Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: AceGUI:RegisterWidgetType(Type, Constructor, Version)