annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 57:01b63b8ed811 v21

total rewrite to version 21
author yellowfive
date Fri, 05 Jun 2015 11:05:15 -0700
parents
children e635cd648e01
rev   line source
yellowfive@57 1 --[[-----------------------------------------------------------------------------
yellowfive@57 2 Button Widget
yellowfive@57 3 Graphical Button.
yellowfive@57 4 -------------------------------------------------------------------------------]]
yellowfive@57 5 local Type, Version = "Button", 23
yellowfive@57 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
yellowfive@57 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
yellowfive@57 8
yellowfive@57 9 -- Lua APIs
yellowfive@57 10 local pairs = pairs
yellowfive@57 11
yellowfive@57 12 -- WoW APIs
yellowfive@57 13 local _G = _G
yellowfive@57 14 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
yellowfive@57 15
yellowfive@57 16 local wowMoP
yellowfive@57 17 do
yellowfive@57 18 local _, _, _, interface = GetBuildInfo()
yellowfive@57 19 wowMoP = (interface >= 50000)
yellowfive@57 20 end
yellowfive@57 21
yellowfive@57 22 --[[-----------------------------------------------------------------------------
yellowfive@57 23 Scripts
yellowfive@57 24 -------------------------------------------------------------------------------]]
yellowfive@57 25 local function Button_OnClick(frame, ...)
yellowfive@57 26 AceGUI:ClearFocus()
yellowfive@57 27 PlaySound("igMainMenuOption")
yellowfive@57 28 frame.obj:Fire("OnClick", ...)
yellowfive@57 29 end
yellowfive@57 30
yellowfive@57 31 local function Control_OnEnter(frame)
yellowfive@57 32 frame.obj:Fire("OnEnter")
yellowfive@57 33 end
yellowfive@57 34
yellowfive@57 35 local function Control_OnLeave(frame)
yellowfive@57 36 frame.obj:Fire("OnLeave")
yellowfive@57 37 end
yellowfive@57 38
yellowfive@57 39 --[[-----------------------------------------------------------------------------
yellowfive@57 40 Methods
yellowfive@57 41 -------------------------------------------------------------------------------]]
yellowfive@57 42 local methods = {
yellowfive@57 43 ["OnAcquire"] = function(self)
yellowfive@57 44 -- restore default values
yellowfive@57 45 self:SetHeight(24)
yellowfive@57 46 self:SetWidth(200)
yellowfive@57 47 self:SetDisabled(false)
yellowfive@57 48 self:SetAutoWidth(false)
yellowfive@57 49 self:SetText()
yellowfive@57 50 end,
yellowfive@57 51
yellowfive@57 52 -- ["OnRelease"] = nil,
yellowfive@57 53
yellowfive@57 54 ["SetText"] = function(self, text)
yellowfive@57 55 self.text:SetText(text)
yellowfive@57 56 if self.autoWidth then
yellowfive@57 57 self:SetWidth(self.text:GetStringWidth() + 30)
yellowfive@57 58 end
yellowfive@57 59 end,
yellowfive@57 60
yellowfive@57 61 ["SetAutoWidth"] = function(self, autoWidth)
yellowfive@57 62 self.autoWidth = autoWidth
yellowfive@57 63 if self.autoWidth then
yellowfive@57 64 self:SetWidth(self.text:GetStringWidth() + 30)
yellowfive@57 65 end
yellowfive@57 66 end,
yellowfive@57 67
yellowfive@57 68 ["SetDisabled"] = function(self, disabled)
yellowfive@57 69 self.disabled = disabled
yellowfive@57 70 if disabled then
yellowfive@57 71 self.frame:Disable()
yellowfive@57 72 else
yellowfive@57 73 self.frame:Enable()
yellowfive@57 74 end
yellowfive@57 75 end
yellowfive@57 76 }
yellowfive@57 77
yellowfive@57 78 --[[-----------------------------------------------------------------------------
yellowfive@57 79 Constructor
yellowfive@57 80 -------------------------------------------------------------------------------]]
yellowfive@57 81 local function Constructor()
yellowfive@57 82 local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type)
yellowfive@57 83 local frame = CreateFrame("Button", name, UIParent, wowMoP and "UIPanelButtonTemplate" or "UIPanelButtonTemplate2")
yellowfive@57 84 frame:Hide()
yellowfive@57 85
yellowfive@57 86 frame:EnableMouse(true)
yellowfive@57 87 frame:SetScript("OnClick", Button_OnClick)
yellowfive@57 88 frame:SetScript("OnEnter", Control_OnEnter)
yellowfive@57 89 frame:SetScript("OnLeave", Control_OnLeave)
yellowfive@57 90
yellowfive@57 91 local text = frame:GetFontString()
yellowfive@57 92 text:ClearAllPoints()
yellowfive@57 93 text:SetPoint("TOPLEFT", 15, -1)
yellowfive@57 94 text:SetPoint("BOTTOMRIGHT", -15, 1)
yellowfive@57 95 text:SetJustifyV("MIDDLE")
yellowfive@57 96
yellowfive@57 97 local widget = {
yellowfive@57 98 text = text,
yellowfive@57 99 frame = frame,
yellowfive@57 100 type = Type
yellowfive@57 101 }
yellowfive@57 102 for method, func in pairs(methods) do
yellowfive@57 103 widget[method] = func
yellowfive@57 104 end
yellowfive@57 105
yellowfive@57 106 return AceGUI:RegisterAsWidget(widget)
yellowfive@57 107 end
yellowfive@57 108
yellowfive@57 109 AceGUI:RegisterWidgetType(Type, Constructor, Version)