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