diff Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 0:98c6f55e6619

First commit
author Xiiph
date Sat, 05 Feb 2011 16:45:02 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua	Sat Feb 05 16:45:02 2011 +0100
@@ -0,0 +1,92 @@
+--[[-----------------------------------------------------------------------------
+Button Widget
+Graphical Button.
+-------------------------------------------------------------------------------]]
+local Type, Version = "Button", 21
+local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
+if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
+
+-- Lua APIs
+local pairs = pairs
+
+-- WoW APIs
+local _G = _G
+local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
+
+--[[-----------------------------------------------------------------------------
+Scripts
+-------------------------------------------------------------------------------]]
+local function Button_OnClick(frame, ...)
+	AceGUI:ClearFocus()
+	PlaySound("igMainMenuOption")
+	frame.obj:Fire("OnClick", ...)
+end
+
+local function Control_OnEnter(frame)
+	frame.obj:Fire("OnEnter")
+end
+
+local function Control_OnLeave(frame)
+	frame.obj:Fire("OnLeave")
+end
+
+--[[-----------------------------------------------------------------------------
+Methods
+-------------------------------------------------------------------------------]]
+local methods = {
+	["OnAcquire"] = function(self)
+		-- restore default values
+		self:SetHeight(24)
+		self:SetWidth(200)
+		self:SetDisabled(false)
+		self:SetText()
+	end,
+
+	-- ["OnRelease"] = nil,
+
+	["SetText"] = function(self, text)
+		self.text:SetText(text)
+	end,
+
+	["SetDisabled"] = function(self, disabled)
+		self.disabled = disabled
+		if disabled then
+			self.frame:Disable()
+		else
+			self.frame:Enable()
+		end
+	end
+}
+
+--[[-----------------------------------------------------------------------------
+Constructor
+-------------------------------------------------------------------------------]]
+local function Constructor()
+	local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type)
+	local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate2")
+	frame:Hide()
+
+	frame:EnableMouse(true)
+	frame:SetScript("OnClick", Button_OnClick)
+	frame:SetScript("OnEnter", Control_OnEnter)
+	frame:SetScript("OnLeave", Control_OnLeave)
+
+	local text = frame:GetFontString()
+	text:ClearAllPoints()
+	text:SetPoint("TOPLEFT", 15, -1)
+	text:SetPoint("BOTTOMRIGHT", -15, 1)
+	text:SetJustifyV("MIDDLE")
+
+	local widget = {
+		text  = text,
+		frame = frame,
+		type  = Type
+	}
+	for method, func in pairs(methods) do
+		widget[method] = func
+	end
+
+	return AceGUI:RegisterAsWidget(widget)
+end
+
+AceGUI:RegisterWidgetType(Type, Constructor, Version)