annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 23:52973d00a183

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