annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 8:1b2d819b4fa8

Now using the global MailAddonBusy to indicate MailOpener is busy, read comments in Core.lua for more info. Default status is now ?enabled without automatic mail opening? to let first time users look around before MailOpener messes up their heads. A StaticPopupDialog will be added later to ask if they want to auto-enable. When ?enabled without automatic mail opening? is on and you toggle the mail opening checkbox on, mail opening will automatically start.
author Zerotorescue
date Thu, 09 Sep 2010 10:53:19 +0200
parents 823e33465b6e
children
rev   line source
Zerotorescue@0 1 --[[-----------------------------------------------------------------------------
Zerotorescue@0 2 Button Widget
Zerotorescue@0 3 Graphical Button.
Zerotorescue@0 4 -------------------------------------------------------------------------------]]
Zerotorescue@0 5 local Type, Version = "Button", 20
Zerotorescue@0 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
Zerotorescue@0 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
Zerotorescue@0 8
Zerotorescue@0 9 -- Lua APIs
Zerotorescue@0 10 local pairs = pairs
Zerotorescue@0 11
Zerotorescue@0 12 -- WoW APIs
Zerotorescue@0 13 local _G = _G
Zerotorescue@0 14 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
Zerotorescue@0 15
Zerotorescue@0 16 --[[-----------------------------------------------------------------------------
Zerotorescue@0 17 Scripts
Zerotorescue@0 18 -------------------------------------------------------------------------------]]
Zerotorescue@0 19 local function Button_OnClick(frame, ...)
Zerotorescue@0 20 PlaySound("igMainMenuOption")
Zerotorescue@0 21 frame.obj:Fire("OnClick", ...)
Zerotorescue@0 22 AceGUI:ClearFocus()
Zerotorescue@0 23 end
Zerotorescue@0 24
Zerotorescue@0 25 local function Control_OnEnter(frame)
Zerotorescue@0 26 frame.obj:Fire("OnEnter")
Zerotorescue@0 27 end
Zerotorescue@0 28
Zerotorescue@0 29 local function Control_OnLeave(frame)
Zerotorescue@0 30 frame.obj:Fire("OnLeave")
Zerotorescue@0 31 end
Zerotorescue@0 32
Zerotorescue@0 33 --[[-----------------------------------------------------------------------------
Zerotorescue@0 34 Methods
Zerotorescue@0 35 -------------------------------------------------------------------------------]]
Zerotorescue@0 36 local methods = {
Zerotorescue@0 37 ["OnAcquire"] = function(self)
Zerotorescue@0 38 -- restore default values
Zerotorescue@0 39 self:SetHeight(24)
Zerotorescue@0 40 self:SetWidth(200)
Zerotorescue@0 41 self:SetDisabled(false)
Zerotorescue@0 42 self:SetText()
Zerotorescue@0 43 end,
Zerotorescue@0 44
Zerotorescue@0 45 -- ["OnRelease"] = nil,
Zerotorescue@0 46
Zerotorescue@0 47 ["SetText"] = function(self, text)
Zerotorescue@0 48 self.text:SetText(text)
Zerotorescue@0 49 end,
Zerotorescue@0 50
Zerotorescue@0 51 ["SetDisabled"] = function(self, disabled)
Zerotorescue@0 52 self.disabled = disabled
Zerotorescue@0 53 if disabled then
Zerotorescue@0 54 self.frame:Disable()
Zerotorescue@0 55 else
Zerotorescue@0 56 self.frame:Enable()
Zerotorescue@0 57 end
Zerotorescue@0 58 end
Zerotorescue@0 59 }
Zerotorescue@0 60
Zerotorescue@0 61 --[[-----------------------------------------------------------------------------
Zerotorescue@0 62 Constructor
Zerotorescue@0 63 -------------------------------------------------------------------------------]]
Zerotorescue@0 64 local function Constructor()
Zerotorescue@0 65 local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type)
Zerotorescue@0 66 local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate2")
Zerotorescue@0 67 frame:Hide()
Zerotorescue@0 68
Zerotorescue@0 69 frame:EnableMouse(true)
Zerotorescue@0 70 frame:SetScript("OnClick", Button_OnClick)
Zerotorescue@0 71 frame:SetScript("OnEnter", Control_OnEnter)
Zerotorescue@0 72 frame:SetScript("OnLeave", Control_OnLeave)
Zerotorescue@0 73
Zerotorescue@0 74 local text = frame:GetFontString()
Zerotorescue@0 75 text:ClearAllPoints()
Zerotorescue@0 76 text:SetPoint("TOPLEFT", 15, -1)
Zerotorescue@0 77 text:SetPoint("BOTTOMRIGHT", -15, 1)
Zerotorescue@0 78 text:SetJustifyV("MIDDLE")
Zerotorescue@0 79
Zerotorescue@0 80 local widget = {
Zerotorescue@0 81 text = text,
Zerotorescue@0 82 frame = frame,
Zerotorescue@0 83 type = Type
Zerotorescue@0 84 }
Zerotorescue@0 85 for method, func in pairs(methods) do
Zerotorescue@0 86 widget[method] = func
Zerotorescue@0 87 end
Zerotorescue@0 88
Zerotorescue@0 89 return AceGUI:RegisterAsWidget(widget)
Zerotorescue@0 90 end
Zerotorescue@0 91
Zerotorescue@0 92 AceGUI:RegisterWidgetType(Type, Constructor, Version)