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 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
17 Scripts
|
yellowfive@57
|
18 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
19 local function Button_OnClick(frame, ...)
|
yellowfive@57
|
20 AceGUI:ClearFocus()
|
yellowfive@57
|
21 PlaySound("igMainMenuOption")
|
yellowfive@57
|
22 frame.obj:Fire("OnClick", ...)
|
yellowfive@57
|
23 end
|
yellowfive@57
|
24
|
yellowfive@57
|
25 local function Control_OnEnter(frame)
|
yellowfive@57
|
26 frame.obj:Fire("OnEnter")
|
yellowfive@57
|
27 end
|
yellowfive@57
|
28
|
yellowfive@57
|
29 local function Control_OnLeave(frame)
|
yellowfive@57
|
30 frame.obj:Fire("OnLeave")
|
yellowfive@57
|
31 end
|
yellowfive@57
|
32
|
yellowfive@57
|
33 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
34 Methods
|
yellowfive@57
|
35 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
36 local methods = {
|
yellowfive@57
|
37 ["OnAcquire"] = function(self)
|
yellowfive@57
|
38 -- restore default values
|
yellowfive@57
|
39 self:SetHeight(24)
|
yellowfive@57
|
40 self:SetWidth(200)
|
yellowfive@57
|
41 self:SetDisabled(false)
|
yellowfive@57
|
42 self:SetAutoWidth(false)
|
yellowfive@57
|
43 self:SetText()
|
yellowfive@57
|
44 end,
|
yellowfive@57
|
45
|
yellowfive@57
|
46 -- ["OnRelease"] = nil,
|
yellowfive@57
|
47
|
yellowfive@57
|
48 ["SetText"] = function(self, text)
|
yellowfive@57
|
49 self.text:SetText(text)
|
yellowfive@57
|
50 if self.autoWidth then
|
yellowfive@57
|
51 self:SetWidth(self.text:GetStringWidth() + 30)
|
yellowfive@57
|
52 end
|
yellowfive@57
|
53 end,
|
yellowfive@57
|
54
|
yellowfive@57
|
55 ["SetAutoWidth"] = function(self, autoWidth)
|
yellowfive@57
|
56 self.autoWidth = autoWidth
|
yellowfive@57
|
57 if self.autoWidth then
|
yellowfive@57
|
58 self:SetWidth(self.text:GetStringWidth() + 30)
|
yellowfive@57
|
59 end
|
yellowfive@57
|
60 end,
|
yellowfive@57
|
61
|
yellowfive@57
|
62 ["SetDisabled"] = function(self, disabled)
|
yellowfive@57
|
63 self.disabled = disabled
|
yellowfive@57
|
64 if disabled then
|
yellowfive@57
|
65 self.frame:Disable()
|
yellowfive@57
|
66 else
|
yellowfive@57
|
67 self.frame:Enable()
|
yellowfive@57
|
68 end
|
yellowfive@57
|
69 end
|
yellowfive@57
|
70 }
|
yellowfive@57
|
71
|
yellowfive@57
|
72 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
73 Constructor
|
yellowfive@57
|
74 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
75 local function Constructor()
|
yellowfive@57
|
76 local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type)
|
yellowfive@106
|
77 local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate")
|
yellowfive@57
|
78 frame:Hide()
|
yellowfive@57
|
79
|
yellowfive@57
|
80 frame:EnableMouse(true)
|
yellowfive@57
|
81 frame:SetScript("OnClick", Button_OnClick)
|
yellowfive@57
|
82 frame:SetScript("OnEnter", Control_OnEnter)
|
yellowfive@57
|
83 frame:SetScript("OnLeave", Control_OnLeave)
|
yellowfive@57
|
84
|
yellowfive@57
|
85 local text = frame:GetFontString()
|
yellowfive@57
|
86 text:ClearAllPoints()
|
yellowfive@57
|
87 text:SetPoint("TOPLEFT", 15, -1)
|
yellowfive@57
|
88 text:SetPoint("BOTTOMRIGHT", -15, 1)
|
yellowfive@57
|
89 text:SetJustifyV("MIDDLE")
|
yellowfive@57
|
90
|
yellowfive@57
|
91 local widget = {
|
yellowfive@57
|
92 text = text,
|
yellowfive@57
|
93 frame = frame,
|
yellowfive@57
|
94 type = Type
|
yellowfive@57
|
95 }
|
yellowfive@57
|
96 for method, func in pairs(methods) do
|
yellowfive@57
|
97 widget[method] = func
|
yellowfive@57
|
98 end
|
yellowfive@57
|
99
|
yellowfive@57
|
100 return AceGUI:RegisterAsWidget(widget)
|
yellowfive@57
|
101 end
|
yellowfive@57
|
102
|
yellowfive@57
|
103 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|