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