annotate ui/AmrUiIcon.lua @ 201:3447634f0388 tip

Added tag v97 for changeset 6e8838b231d4
author Yellowfive
date Wed, 13 Jan 2021 13:12:13 -0600
parents 0515882856f1
children
rev   line source
yellowfive@57 1 --[[-----------------------------------------------------------------------------
yellowfive@57 2 Icon Container
yellowfive@57 3 Simple container widget that is an icon, and can optionally contain children.
yellowfive@57 4 -------------------------------------------------------------------------------]]
yellowfive@57 5 local Type, Version = "AmrUiIcon", 1
yellowfive@57 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
yellowfive@57 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
yellowfive@57 8
yellowfive@57 9 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 10
yellowfive@57 11 -- Lua APIs
yellowfive@57 12 local pairs = pairs
yellowfive@57 13
yellowfive@57 14 -- WoW APIs
yellowfive@57 15 local CreateFrame, UIParent = CreateFrame, UIParent
yellowfive@57 16
yellowfive@57 17 --[[-----------------------------------------------------------------------------
yellowfive@57 18 Support Functions
yellowfive@57 19 -------------------------------------------------------------------------------]]
yellowfive@57 20 local function setIconBorderWidth(frame, icon, width)
yellowfive@57 21 icon:ClearAllPoints()
yellowfive@57 22 icon:SetPoint("TOPLEFT", frame, "TOPLEFT", width, -width)
yellowfive@57 23 icon:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -width, width)
yellowfive@57 24 end
yellowfive@57 25
yellowfive@57 26 --[[-----------------------------------------------------------------------------
yellowfive@57 27 Scripts
yellowfive@57 28 -------------------------------------------------------------------------------]]
yellowfive@57 29
yellowfive@57 30 local function frameOnEnter(frame)
yellowfive@57 31 frame.obj:Fire("OnEnter")
yellowfive@57 32 end
yellowfive@57 33
yellowfive@57 34 local function frameOnLeave(frame)
yellowfive@57 35 frame.obj:Fire("OnLeave")
yellowfive@57 36 end
yellowfive@57 37
yellowfive@57 38 --[[-----------------------------------------------------------------------------
yellowfive@57 39 Methods
yellowfive@57 40 -------------------------------------------------------------------------------]]
yellowfive@57 41 local methods = {
yellowfive@57 42 ["OnAcquire"] = function(self)
yellowfive@57 43 self:SetAutoAdjustHeight(false)
yellowfive@57 44 self:SetWidth(64)
yellowfive@57 45 self:SetHeight(64)
yellowfive@57 46 self:SetBorderWidth(2)
yellowfive@57 47 self:HideIconBorder()
yellowfive@57 48 self:SetIcon(nil)
yellowfive@57 49 self:SetStrata("FULLSCREEN_DIALOG")
yellowfive@57 50 self:SetLevel(0)
yellowfive@57 51 self:SetVisible(true)
yellowfive@57 52 self.frame:ClearAllPoints()
yellowfive@57 53 self.icon:SetDesaturated(false)
yellowfive@57 54 end,
yellowfive@57 55
yellowfive@57 56 ["SetIcon"] = function(self, icon)
yellowfive@57 57 if not icon then
yellowfive@81 58 self.icon:SetColorTexture(0, 0, 0, 0)
yellowfive@57 59 else
yellowfive@57 60 self.icon:SetTexture(icon)
yellowfive@57 61 end
yellowfive@57 62 end,
yellowfive@57 63
yellowfive@57 64 ["SetBorderWidth"] = function(self, width)
yellowfive@57 65 setIconBorderWidth(self.frame, self.icon, width)
yellowfive@57 66 end,
yellowfive@57 67
yellowfive@57 68 ["SetIconBorderColor"] = function(self, color, a)
yellowfive@81 69 self.bg:SetColorTexture(color.R, color.G, color.B, a or 1)
yellowfive@57 70 end,
yellowfive@57 71
yellowfive@57 72 ["HideIconBorder"] = function(self)
yellowfive@81 73 self.bg:SetColorTexture(0, 0, 0, 0)
yellowfive@57 74 end,
yellowfive@57 75
yellowfive@57 76 ["SetStrata"] = function(self, strata)
yellowfive@57 77 self.frame:SetFrameStrata(strata)
yellowfive@57 78 end,
yellowfive@57 79
yellowfive@57 80 ["SetLevel"] = function(self, level)
yellowfive@57 81 self.frame:SetFrameLevel(level)
yellowfive@57 82 end,
yellowfive@57 83
yellowfive@57 84
yellowfive@57 85 ["SetVisible"] = function(self, visible)
yellowfive@57 86 if visible then
yellowfive@57 87 self.frame:Show()
yellowfive@57 88 else
yellowfive@57 89 self.frame:Hide()
yellowfive@57 90 end
yellowfive@57 91 end
yellowfive@57 92 }
yellowfive@57 93
yellowfive@57 94 --[[-----------------------------------------------------------------------------
yellowfive@57 95 Constructor
yellowfive@57 96 -------------------------------------------------------------------------------]]
yellowfive@57 97 local function Constructor()
yellowfive@57 98 local frame = CreateFrame("Frame", nil, UIParent)
yellowfive@57 99 frame:SetFrameStrata("FULLSCREEN_DIALOG")
yellowfive@57 100
yellowfive@57 101 frame:SetScript("OnEnter", frameOnEnter)
yellowfive@57 102 frame:SetScript("OnLeave", frameOnLeave)
yellowfive@57 103
yellowfive@57 104 local bg = frame:CreateTexture(nil, "BORDER")
yellowfive@57 105 bg:SetAllPoints()
yellowfive@57 106
yellowfive@57 107 local icon = frame:CreateTexture(nil, "ARTWORK", nil, 1)
yellowfive@57 108 icon:SetTexCoord(0.05, 0.95, 0.05, 0.95)
yellowfive@57 109
yellowfive@57 110 local borderTop = frame:CreateTexture(nil, "ARTWORK", nil, 2)
yellowfive@81 111 borderTop:SetColorTexture(0, 0, 0, 1)
yellowfive@57 112 borderTop:SetHeight(1)
yellowfive@57 113 borderTop:SetPoint("TOPLEFT", icon, "TOPLEFT")
yellowfive@57 114 borderTop:SetPoint("TOPRIGHT", icon, "TOPRIGHT")
yellowfive@57 115
yellowfive@57 116 local borderRight = frame:CreateTexture(nil, "ARTWORK", nil, 2)
yellowfive@81 117 borderRight:SetColorTexture(0, 0, 0, 1)
yellowfive@57 118 borderRight:SetWidth(1)
yellowfive@57 119 borderRight:SetPoint("TOPRIGHT", icon, "TOPRIGHT")
yellowfive@57 120 borderRight:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT")
yellowfive@57 121
yellowfive@57 122 local borderBottom = frame:CreateTexture(nil, "ARTWORK", nil, 2)
yellowfive@81 123 borderBottom:SetColorTexture(0, 0, 0, 1)
yellowfive@57 124 borderBottom:SetHeight(1)
yellowfive@57 125 borderBottom:SetPoint("BOTTOMLEFT", icon, "BOTTOMLEFT")
yellowfive@57 126 borderBottom:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT")
yellowfive@57 127
yellowfive@57 128 local borderLeft = frame:CreateTexture(nil, "ARTWORK", nil, 2)
yellowfive@81 129 borderLeft:SetColorTexture(0, 0, 0, 1)
yellowfive@57 130 borderLeft:SetWidth(1)
yellowfive@57 131 borderLeft:SetPoint("TOPLEFT", icon, "TOPLEFT")
yellowfive@57 132 borderLeft:SetPoint("BOTTOMLEFT", icon, "BOTTOMLEFT")
yellowfive@57 133
yellowfive@57 134 local widget = {
yellowfive@57 135 bg = bg,
yellowfive@57 136 icon = icon,
yellowfive@57 137 frame = frame,
yellowfive@57 138 content = frame,
yellowfive@57 139 type = Type
yellowfive@57 140 }
yellowfive@57 141 for method, func in pairs(methods) do
yellowfive@57 142 widget[method] = func
yellowfive@57 143 end
yellowfive@57 144
yellowfive@57 145 return AceGUI:RegisterAsContainer(widget)
yellowfive@57 146 end
yellowfive@57 147
yellowfive@57 148 AceGUI:RegisterWidgetType(Type, Constructor, Version)