Mercurial > wow > askmrrobot
comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua @ 57:01b63b8ed811 v21
total rewrite to version 21
| author | yellowfive |
|---|---|
| date | Fri, 05 Jun 2015 11:05:15 -0700 |
| parents | |
| children | e635cd648e01 |
comparison
equal
deleted
inserted
replaced
| 56:75431c084aa0 | 57:01b63b8ed811 |
|---|---|
| 1 --[[----------------------------------------------------------------------------- | |
| 2 Icon Widget | |
| 3 -------------------------------------------------------------------------------]] | |
| 4 local Type, Version = "Icon", 21 | |
| 5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true) | |
| 6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end | |
| 7 | |
| 8 -- Lua APIs | |
| 9 local select, pairs, print = select, pairs, print | |
| 10 | |
| 11 -- WoW APIs | |
| 12 local CreateFrame, UIParent, GetBuildInfo = CreateFrame, UIParent, GetBuildInfo | |
| 13 | |
| 14 --[[----------------------------------------------------------------------------- | |
| 15 Scripts | |
| 16 -------------------------------------------------------------------------------]] | |
| 17 local function Control_OnEnter(frame) | |
| 18 frame.obj:Fire("OnEnter") | |
| 19 end | |
| 20 | |
| 21 local function Control_OnLeave(frame) | |
| 22 frame.obj:Fire("OnLeave") | |
| 23 end | |
| 24 | |
| 25 local function Button_OnClick(frame, button) | |
| 26 frame.obj:Fire("OnClick", button) | |
| 27 AceGUI:ClearFocus() | |
| 28 end | |
| 29 | |
| 30 --[[----------------------------------------------------------------------------- | |
| 31 Methods | |
| 32 -------------------------------------------------------------------------------]] | |
| 33 local methods = { | |
| 34 ["OnAcquire"] = function(self) | |
| 35 self:SetHeight(110) | |
| 36 self:SetWidth(110) | |
| 37 self:SetLabel() | |
| 38 self:SetImage(nil) | |
| 39 self:SetImageSize(64, 64) | |
| 40 self:SetDisabled(false) | |
| 41 end, | |
| 42 | |
| 43 -- ["OnRelease"] = nil, | |
| 44 | |
| 45 ["SetLabel"] = function(self, text) | |
| 46 if text and text ~= "" then | |
| 47 self.label:Show() | |
| 48 self.label:SetText(text) | |
| 49 self:SetHeight(self.image:GetHeight() + 25) | |
| 50 else | |
| 51 self.label:Hide() | |
| 52 self:SetHeight(self.image:GetHeight() + 10) | |
| 53 end | |
| 54 end, | |
| 55 | |
| 56 ["SetImage"] = function(self, path, ...) | |
| 57 local image = self.image | |
| 58 image:SetTexture(path) | |
| 59 | |
| 60 if image:GetTexture() then | |
| 61 local n = select("#", ...) | |
| 62 if n == 4 or n == 8 then | |
| 63 image:SetTexCoord(...) | |
| 64 else | |
| 65 image:SetTexCoord(0, 1, 0, 1) | |
| 66 end | |
| 67 end | |
| 68 end, | |
| 69 | |
| 70 ["SetImageSize"] = function(self, width, height) | |
| 71 self.image:SetWidth(width) | |
| 72 self.image:SetHeight(height) | |
| 73 --self.frame:SetWidth(width + 30) | |
| 74 if self.label:IsShown() then | |
| 75 self:SetHeight(height + 25) | |
| 76 else | |
| 77 self:SetHeight(height + 10) | |
| 78 end | |
| 79 end, | |
| 80 | |
| 81 ["SetDisabled"] = function(self, disabled) | |
| 82 self.disabled = disabled | |
| 83 if disabled then | |
| 84 self.frame:Disable() | |
| 85 self.label:SetTextColor(0.5, 0.5, 0.5) | |
| 86 self.image:SetVertexColor(0.5, 0.5, 0.5, 0.5) | |
| 87 else | |
| 88 self.frame:Enable() | |
| 89 self.label:SetTextColor(1, 1, 1) | |
| 90 self.image:SetVertexColor(1, 1, 1, 1) | |
| 91 end | |
| 92 end | |
| 93 } | |
| 94 | |
| 95 --[[----------------------------------------------------------------------------- | |
| 96 Constructor | |
| 97 -------------------------------------------------------------------------------]] | |
| 98 local function Constructor() | |
| 99 local frame = CreateFrame("Button", nil, UIParent) | |
| 100 frame:Hide() | |
| 101 | |
| 102 frame:EnableMouse(true) | |
| 103 frame:SetScript("OnEnter", Control_OnEnter) | |
| 104 frame:SetScript("OnLeave", Control_OnLeave) | |
| 105 frame:SetScript("OnClick", Button_OnClick) | |
| 106 | |
| 107 local label = frame:CreateFontString(nil, "BACKGROUND", "GameFontHighlight") | |
| 108 label:SetPoint("BOTTOMLEFT") | |
| 109 label:SetPoint("BOTTOMRIGHT") | |
| 110 label:SetJustifyH("CENTER") | |
| 111 label:SetJustifyV("TOP") | |
| 112 label:SetHeight(18) | |
| 113 | |
| 114 local image = frame:CreateTexture(nil, "BACKGROUND") | |
| 115 image:SetWidth(64) | |
| 116 image:SetHeight(64) | |
| 117 image:SetPoint("TOP", 0, -5) | |
| 118 | |
| 119 local highlight = frame:CreateTexture(nil, "HIGHLIGHT") | |
| 120 highlight:SetAllPoints(image) | |
| 121 highlight:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight") | |
| 122 highlight:SetTexCoord(0, 1, 0.23, 0.77) | |
| 123 highlight:SetBlendMode("ADD") | |
| 124 | |
| 125 local widget = { | |
| 126 label = label, | |
| 127 image = image, | |
| 128 frame = frame, | |
| 129 type = Type | |
| 130 } | |
| 131 for method, func in pairs(methods) do | |
| 132 widget[method] = func | |
| 133 end | |
| 134 -- SetText is deprecated, but keep it around for a while. (say, to WoW 4.0) | |
| 135 if (select(4, GetBuildInfo()) < 40000) then | |
| 136 widget.SetText = widget.SetLabel | |
| 137 else | |
| 138 widget.SetText = function(self, ...) print("AceGUI-3.0-Icon: SetText is deprecated! Use SetLabel instead!"); self:SetLabel(...) end | |
| 139 end | |
| 140 | |
| 141 return AceGUI:RegisterAsWidget(widget) | |
| 142 end | |
| 143 | |
| 144 AceGUI:RegisterWidgetType(Type, Constructor, Version) |
