Mercurial > wow > icu
comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua @ 0:98c6f55e6619
First commit
| author | Xiiph |
|---|---|
| date | Sat, 05 Feb 2011 16:45:02 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:98c6f55e6619 |
|---|---|
| 1 --[[----------------------------------------------------------------------------- | |
| 2 Button Widget | |
| 3 Graphical Button. | |
| 4 -------------------------------------------------------------------------------]] | |
| 5 local Type, Version = "Button", 21 | |
| 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true) | |
| 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end | |
| 8 | |
| 9 -- Lua APIs | |
| 10 local pairs = pairs | |
| 11 | |
| 12 -- WoW APIs | |
| 13 local _G = _G | |
| 14 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent | |
| 15 | |
| 16 --[[----------------------------------------------------------------------------- | |
| 17 Scripts | |
| 18 -------------------------------------------------------------------------------]] | |
| 19 local function Button_OnClick(frame, ...) | |
| 20 AceGUI:ClearFocus() | |
| 21 PlaySound("igMainMenuOption") | |
| 22 frame.obj:Fire("OnClick", ...) | |
| 23 end | |
| 24 | |
| 25 local function Control_OnEnter(frame) | |
| 26 frame.obj:Fire("OnEnter") | |
| 27 end | |
| 28 | |
| 29 local function Control_OnLeave(frame) | |
| 30 frame.obj:Fire("OnLeave") | |
| 31 end | |
| 32 | |
| 33 --[[----------------------------------------------------------------------------- | |
| 34 Methods | |
| 35 -------------------------------------------------------------------------------]] | |
| 36 local methods = { | |
| 37 ["OnAcquire"] = function(self) | |
| 38 -- restore default values | |
| 39 self:SetHeight(24) | |
| 40 self:SetWidth(200) | |
| 41 self:SetDisabled(false) | |
| 42 self:SetText() | |
| 43 end, | |
| 44 | |
| 45 -- ["OnRelease"] = nil, | |
| 46 | |
| 47 ["SetText"] = function(self, text) | |
| 48 self.text:SetText(text) | |
| 49 end, | |
| 50 | |
| 51 ["SetDisabled"] = function(self, disabled) | |
| 52 self.disabled = disabled | |
| 53 if disabled then | |
| 54 self.frame:Disable() | |
| 55 else | |
| 56 self.frame:Enable() | |
| 57 end | |
| 58 end | |
| 59 } | |
| 60 | |
| 61 --[[----------------------------------------------------------------------------- | |
| 62 Constructor | |
| 63 -------------------------------------------------------------------------------]] | |
| 64 local function Constructor() | |
| 65 local name = "AceGUI30Button" .. AceGUI:GetNextWidgetNum(Type) | |
| 66 local frame = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate2") | |
| 67 frame:Hide() | |
| 68 | |
| 69 frame:EnableMouse(true) | |
| 70 frame:SetScript("OnClick", Button_OnClick) | |
| 71 frame:SetScript("OnEnter", Control_OnEnter) | |
| 72 frame:SetScript("OnLeave", Control_OnLeave) | |
| 73 | |
| 74 local text = frame:GetFontString() | |
| 75 text:ClearAllPoints() | |
| 76 text:SetPoint("TOPLEFT", 15, -1) | |
| 77 text:SetPoint("BOTTOMRIGHT", -15, 1) | |
| 78 text:SetJustifyV("MIDDLE") | |
| 79 | |
| 80 local widget = { | |
| 81 text = text, | |
| 82 frame = frame, | |
| 83 type = Type | |
| 84 } | |
| 85 for method, func in pairs(methods) do | |
| 86 widget[method] = func | |
| 87 end | |
| 88 | |
| 89 return AceGUI:RegisterAsWidget(widget) | |
| 90 end | |
| 91 | |
| 92 AceGUI:RegisterWidgetType(Type, Constructor, Version) |
