annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua @ 11:371e14cd2feb

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