yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Icon Container yellowfive@57: Simple container widget that is an icon, and can optionally contain children. yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "AmrUiIcon", 1 yellowfive@57: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) yellowfive@57: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end yellowfive@57: yellowfive@57: local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") yellowfive@57: yellowfive@57: -- Lua APIs yellowfive@57: local pairs = pairs yellowfive@57: yellowfive@57: -- WoW APIs yellowfive@57: local CreateFrame, UIParent = CreateFrame, UIParent yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Support Functions yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function setIconBorderWidth(frame, icon, width) yellowfive@57: icon:ClearAllPoints() yellowfive@57: icon:SetPoint("TOPLEFT", frame, "TOPLEFT", width, -width) yellowfive@57: icon:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -width, width) yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: yellowfive@57: local function frameOnEnter(frame) yellowfive@57: frame.obj:Fire("OnEnter") yellowfive@57: end yellowfive@57: yellowfive@57: local function frameOnLeave(frame) yellowfive@57: frame.obj:Fire("OnLeave") yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Methods yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local methods = { yellowfive@57: ["OnAcquire"] = function(self) yellowfive@57: self:SetAutoAdjustHeight(false) yellowfive@57: self:SetWidth(64) yellowfive@57: self:SetHeight(64) yellowfive@57: self:SetBorderWidth(2) yellowfive@57: self:HideIconBorder() yellowfive@57: self:SetIcon(nil) yellowfive@57: self:SetStrata("FULLSCREEN_DIALOG") yellowfive@57: self:SetLevel(0) yellowfive@57: self:SetVisible(true) yellowfive@57: self.frame:ClearAllPoints() yellowfive@57: self.icon:SetDesaturated(false) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetIcon"] = function(self, icon) yellowfive@57: if not icon then yellowfive@57: self.icon:SetTexture(0, 0, 0, 0) yellowfive@57: else yellowfive@57: self.icon:SetTexture(icon) yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetBorderWidth"] = function(self, width) yellowfive@57: setIconBorderWidth(self.frame, self.icon, width) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetIconBorderColor"] = function(self, color, a) yellowfive@57: self.bg:SetTexture(color.R, color.G, color.B, a or 1) yellowfive@57: end, yellowfive@57: yellowfive@57: ["HideIconBorder"] = function(self) yellowfive@57: self.bg:SetTexture(0, 0, 0, 0) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetStrata"] = function(self, strata) yellowfive@57: self.frame:SetFrameStrata(strata) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetLevel"] = function(self, level) yellowfive@57: self.frame:SetFrameLevel(level) yellowfive@57: end, yellowfive@57: yellowfive@57: yellowfive@57: ["SetVisible"] = function(self, visible) yellowfive@57: if visible then yellowfive@57: self.frame:Show() yellowfive@57: else yellowfive@57: self.frame:Hide() yellowfive@57: end yellowfive@57: end yellowfive@57: } yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Constructor yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function Constructor() yellowfive@57: local frame = CreateFrame("Frame", nil, UIParent) yellowfive@57: frame:SetFrameStrata("FULLSCREEN_DIALOG") yellowfive@57: yellowfive@57: frame:SetScript("OnEnter", frameOnEnter) yellowfive@57: frame:SetScript("OnLeave", frameOnLeave) yellowfive@57: yellowfive@57: local bg = frame:CreateTexture(nil, "BORDER") yellowfive@57: bg:SetAllPoints() yellowfive@57: yellowfive@57: local icon = frame:CreateTexture(nil, "ARTWORK", nil, 1) yellowfive@57: icon:SetTexCoord(0.05, 0.95, 0.05, 0.95) yellowfive@57: yellowfive@57: local borderTop = frame:CreateTexture(nil, "ARTWORK", nil, 2) yellowfive@57: borderTop:SetTexture(0, 0, 0, 1) yellowfive@57: borderTop:SetHeight(1) yellowfive@57: borderTop:SetPoint("TOPLEFT", icon, "TOPLEFT") yellowfive@57: borderTop:SetPoint("TOPRIGHT", icon, "TOPRIGHT") yellowfive@57: yellowfive@57: local borderRight = frame:CreateTexture(nil, "ARTWORK", nil, 2) yellowfive@57: borderRight:SetTexture(0, 0, 0, 1) yellowfive@57: borderRight:SetWidth(1) yellowfive@57: borderRight:SetPoint("TOPRIGHT", icon, "TOPRIGHT") yellowfive@57: borderRight:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT") yellowfive@57: yellowfive@57: local borderBottom = frame:CreateTexture(nil, "ARTWORK", nil, 2) yellowfive@57: borderBottom:SetTexture(0, 0, 0, 1) yellowfive@57: borderBottom:SetHeight(1) yellowfive@57: borderBottom:SetPoint("BOTTOMLEFT", icon, "BOTTOMLEFT") yellowfive@57: borderBottom:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT") yellowfive@57: yellowfive@57: local borderLeft = frame:CreateTexture(nil, "ARTWORK", nil, 2) yellowfive@57: borderLeft:SetTexture(0, 0, 0, 1) yellowfive@57: borderLeft:SetWidth(1) yellowfive@57: borderLeft:SetPoint("TOPLEFT", icon, "TOPLEFT") yellowfive@57: borderLeft:SetPoint("BOTTOMLEFT", icon, "BOTTOMLEFT") yellowfive@57: yellowfive@57: local widget = { yellowfive@57: bg = bg, yellowfive@57: icon = icon, yellowfive@57: frame = frame, yellowfive@57: content = frame, yellowfive@57: type = Type yellowfive@57: } yellowfive@57: for method, func in pairs(methods) do yellowfive@57: widget[method] = func yellowfive@57: end yellowfive@57: yellowfive@57: return AceGUI:RegisterAsContainer(widget) yellowfive@57: end yellowfive@57: yellowfive@57: AceGUI:RegisterWidgetType(Type, Constructor, Version)