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