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