annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 0:fc346da3afd9

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