annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 12:2d952bc9897a

Managed to overwrite my local development copy of the project with the latest uploaded revision ... /facepalm This commit/push is the same as r11
author Xiiph
date Sat, 19 Feb 2011 19:22:44 +0100
parents 98c6f55e6619
children
rev   line source
Xiiph@0 1 --[[-----------------------------------------------------------------------------
Xiiph@0 2 Button Widget
Xiiph@0 3 Graphical Button.
Xiiph@0 4 -------------------------------------------------------------------------------]]
Xiiph@0 5 local Type, Version = "Button", 21
Xiiph@0 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
Xiiph@0 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
Xiiph@0 8
Xiiph@0 9 -- Lua APIs
Xiiph@0 10 local pairs = pairs
Xiiph@0 11
Xiiph@0 12 -- WoW APIs
Xiiph@0 13 local _G = _G
Xiiph@0 14 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
Xiiph@0 15
Xiiph@0 16 --[[-----------------------------------------------------------------------------
Xiiph@0 17 Scripts
Xiiph@0 18 -------------------------------------------------------------------------------]]
Xiiph@0 19 local function Button_OnClick(frame, ...)
Xiiph@0 20 AceGUI:ClearFocus()
Xiiph@0 21 PlaySound("igMainMenuOption")
Xiiph@0 22 frame.obj:Fire("OnClick", ...)
Xiiph@0 23 end
Xiiph@0 24
Xiiph@0 25 local function Control_OnEnter(frame)
Xiiph@0 26 frame.obj:Fire("OnEnter")
Xiiph@0 27 end
Xiiph@0 28
Xiiph@0 29 local function Control_OnLeave(frame)
Xiiph@0 30 frame.obj:Fire("OnLeave")
Xiiph@0 31 end
Xiiph@0 32
Xiiph@0 33 --[[-----------------------------------------------------------------------------
Xiiph@0 34 Methods
Xiiph@0 35 -------------------------------------------------------------------------------]]
Xiiph@0 36 local methods = {
Xiiph@0 37 ["OnAcquire"] = function(self)
Xiiph@0 38 -- restore default values
Xiiph@0 39 self:SetHeight(24)
Xiiph@0 40 self:SetWidth(200)
Xiiph@0 41 self:SetDisabled(false)
Xiiph@0 42 self:SetText()
Xiiph@0 43 end,
Xiiph@0 44
Xiiph@0 45 -- ["OnRelease"] = nil,
Xiiph@0 46
Xiiph@0 47 ["SetText"] = function(self, text)
Xiiph@0 48 self.text:SetText(text)
Xiiph@0 49 end,
Xiiph@0 50
Xiiph@0 51 ["SetDisabled"] = function(self, disabled)
Xiiph@0 52 self.disabled = disabled
Xiiph@0 53 if disabled then
Xiiph@0 54 self.frame:Disable()
Xiiph@0 55 else
Xiiph@0 56 self.frame:Enable()
Xiiph@0 57 end
Xiiph@0 58 end
Xiiph@0 59 }
Xiiph@0 60
Xiiph@0 61 --[[-----------------------------------------------------------------------------
Xiiph@0 62 Constructor
Xiiph@0 63 -------------------------------------------------------------------------------]]
Xiiph@0 64 local function Constructor()
Xiiph@0 65 local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type)
Xiiph@0 66 local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate2")
Xiiph@0 67 frame:Hide()
Xiiph@0 68
Xiiph@0 69 frame:EnableMouse(true)
Xiiph@0 70 frame:SetScript("OnClick", Button_OnClick)
Xiiph@0 71 frame:SetScript("OnEnter", Control_OnEnter)
Xiiph@0 72 frame:SetScript("OnLeave", Control_OnLeave)
Xiiph@0 73
Xiiph@0 74 local text = frame:GetFontString()
Xiiph@0 75 text:ClearAllPoints()
Xiiph@0 76 text:SetPoint("TOPLEFT", 15, -1)
Xiiph@0 77 text:SetPoint("BOTTOMRIGHT", -15, 1)
Xiiph@0 78 text:SetJustifyV("MIDDLE")
Xiiph@0 79
Xiiph@0 80 local widget = {
Xiiph@0 81 text = text,
Xiiph@0 82 frame = frame,
Xiiph@0 83 type = Type
Xiiph@0 84 }
Xiiph@0 85 for method, func in pairs(methods) do
Xiiph@0 86 widget[method] = func
Xiiph@0 87 end
Xiiph@0 88
Xiiph@0 89 return AceGUI:RegisterAsWidget(widget)
Xiiph@0 90 end
Xiiph@0 91
Xiiph@0 92 AceGUI:RegisterWidgetType(Type, Constructor, Version)