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