annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua @ 59:8a4c1438dbdf

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