annotate Libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua @ 106:e635cd648e01 v49

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