PageRenderTime 185ms CodeModel.GetById 101ms app.highlight 20ms RepoModel.GetById 60ms app.codeStats 1ms

/Tukui/modules/skins/core.lua

http://github.com/Asphyxia/Tukui
Lua | 316 lines | 260 code | 54 blank | 2 comment | 61 complexity | aa2d9de5a1412a0d37411e02be7f3915 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants, Config, Locales
  2
  3T.SkinFuncs = {}
  4T.SkinFuncs["Tukui"] = {}
  5
  6function T.SetModifiedBackdrop(self)
  7	local color = RAID_CLASS_COLORS[T.myclass]
  8	self:SetBackdropColor(color.r*.15, color.g*.15, color.b*.15)
  9	self:SetBackdropBorderColor(color.r, color.g, color.b)
 10end
 11
 12function T.SetOriginalBackdrop(self)
 13	self:SetTemplate("Transparent")
 14end
 15
 16function T.SkinButton(f, strip)
 17	if f:GetName() then
 18		local l = _G[f:GetName().."Left"]
 19		local m = _G[f:GetName().."Middle"]
 20		local r = _G[f:GetName().."Right"]
 21		
 22		
 23		if l then l:SetAlpha(0) end
 24		if m then m:SetAlpha(0) end
 25		if r then r:SetAlpha(0) end
 26	end
 27
 28	if f.SetNormalTexture then f:SetNormalTexture("") end
 29	
 30	if f.SetHighlightTexture then f:SetHighlightTexture("") end
 31	
 32	if f.SetPushedTexture then f:SetPushedTexture("") end
 33	
 34	if f.SetDisabledTexture then f:SetDisabledTexture("") end
 35	
 36	if strip then f:StripTextures() end
 37	
 38	f:SetTemplate("Transparent")
 39	f:HookScript("OnEnter", T.SetModifiedBackdrop)
 40	f:HookScript("OnLeave", T.SetOriginalBackdrop)
 41end
 42
 43function T.SkinScrollBar(frame, thumbTrim)
 44	if _G[frame:GetName().."BG"] then _G[frame:GetName().."BG"]:SetTexture(nil) end
 45	if _G[frame:GetName().."Track"] then _G[frame:GetName().."Track"]:SetTexture(nil) end
 46	
 47	if _G[frame:GetName().."Top"] then
 48		_G[frame:GetName().."Top"]:SetTexture(nil)
 49		_G[frame:GetName().."Bottom"]:SetTexture(nil)
 50		_G[frame:GetName().."Middle"]:SetTexture(nil)
 51	end
 52	
 53	if _G[frame:GetName().."ScrollUpButton"] and _G[frame:GetName().."ScrollDownButton"] then
 54		_G[frame:GetName().."ScrollUpButton"]:StripTextures()
 55		_G[frame:GetName().."ScrollUpButton"]:SetTemplate("Transparent", true)
 56		_G[frame:GetName().."ScrollUpButton"]:HookScript('OnEnter', T.SetModifiedBackdrop)
 57		_G[frame:GetName().."ScrollUpButton"]:HookScript('OnLeave', T.SetOriginalBackdrop)		
 58		if not _G[frame:GetName().."ScrollUpButton"].texture then
 59			_G[frame:GetName().."ScrollUpButton"].texture = _G[frame:GetName().."ScrollUpButton"]:CreateTexture(nil, 'OVERLAY')
 60			_G[frame:GetName().."ScrollUpButton"].texture:Point("TOPLEFT", 2, -2)
 61			_G[frame:GetName().."ScrollUpButton"].texture:Point("BOTTOMRIGHT", -2, 2)
 62			_G[frame:GetName().."ScrollUpButton"].texture:SetTexture([[Interface\AddOns\Tukui\medias\textures\arrowup.tga]])
 63			_G[frame:GetName().."ScrollUpButton"].texture:SetVertexColor(unpack(C["media"].bordercolor))
 64		end
 65		_G[frame:GetName().."ScrollUpButton"]:HookScript('OnEnter', function(self)
 66			local color = RAID_CLASS_COLORS[T.myclass]
 67			self.texture:SetVertexColor(color.r, color.g, color.b)	
 68		end)	
 69		_G[frame:GetName().."ScrollUpButton"]:HookScript('OnLeave', function(self)
 70			self.texture:SetVertexColor(unpack(C["media"].bordercolor)) 
 71		end)		
 72
 73		_G[frame:GetName().."ScrollDownButton"]:StripTextures()
 74		_G[frame:GetName().."ScrollDownButton"]:SetTemplate("Transparent", true)
 75		_G[frame:GetName().."ScrollDownButton"]:HookScript('OnEnter', T.SetModifiedBackdrop)
 76		_G[frame:GetName().."ScrollDownButton"]:HookScript('OnLeave', T.SetOriginalBackdrop)		
 77		if not _G[frame:GetName().."ScrollDownButton"].texture then
 78			_G[frame:GetName().."ScrollDownButton"].texture = _G[frame:GetName().."ScrollDownButton"]:CreateTexture(nil, 'OVERLAY')
 79			_G[frame:GetName().."ScrollDownButton"].texture:Point("TOPLEFT", 2, -2)
 80			_G[frame:GetName().."ScrollDownButton"].texture:Point("BOTTOMRIGHT", -2, 2)
 81			_G[frame:GetName().."ScrollDownButton"].texture:SetTexture([[Interface\AddOns\Tukui\medias\textures\arrowdown.tga]])
 82			_G[frame:GetName().."ScrollDownButton"].texture:SetVertexColor(unpack(C["media"].bordercolor))
 83		end
 84
 85		_G[frame:GetName().."ScrollDownButton"]:HookScript('OnEnter', function(self)
 86			local color = RAID_CLASS_COLORS[T.myclass]
 87			self.texture:SetVertexColor(color.r, color.g, color.b)	
 88		end)	
 89		_G[frame:GetName().."ScrollDownButton"]:HookScript('OnLeave', function(self)
 90			self.texture:SetVertexColor(unpack(C["media"].bordercolor)) 
 91		end)				
 92
 93		if not frame.trackbg then
 94			frame.trackbg = CreateFrame("Frame", nil, frame)
 95			frame.trackbg:Point("TOPLEFT", _G[frame:GetName().."ScrollUpButton"], "BOTTOMLEFT", 0, -1)
 96			frame.trackbg:Point("BOTTOMRIGHT", _G[frame:GetName().."ScrollDownButton"], "TOPRIGHT", 0, 1)
 97			frame.trackbg:SetTemplate("Transparent")
 98		end
 99
100		if frame:GetThumbTexture() then
101			if not thumbTrim then thumbTrim = 3 end
102			frame:GetThumbTexture():SetTexture(nil)
103			if not frame.thumbbg then
104				frame.thumbbg = CreateFrame("Frame", nil, frame)
105				frame.thumbbg:Point("TOPLEFT", frame:GetThumbTexture(), "TOPLEFT", 2, -thumbTrim)
106				frame.thumbbg:Point("BOTTOMRIGHT", frame:GetThumbTexture(), "BOTTOMRIGHT", -2, thumbTrim)
107				frame.thumbbg:SetTemplate("Transparent", true)
108				if frame.trackbg then
109					frame.thumbbg:SetFrameLevel(frame.trackbg:GetFrameLevel())
110				end
111			end
112		end
113	end
114end
115
116function T.SkinSlideBar(frame,height,movetext)
117
118	frame:SetTemplate("Transparent")
119	frame:SetBackdropColor(0,0,0,.8)
120
121	if not height then height = frame:GetHeight() end
122	frame:Height(height)
123
124	if movetext then
125		if _G[frame:GetName().."Low"] then _G[frame:GetName().."Low"]:Point("BOTTOM",0,-18) end
126		if _G[frame:GetName().."High"] then _G[frame:GetName().."High"]:Point("BOTTOM",0,-18) end
127		if _G[frame:GetName().."Text"] then _G[frame:GetName().."Text"]:Point("TOP",0,19) end
128	end
129
130	if _G[frame:GetName().."Thumb"] then
131		_G[frame:GetName().."Thumb"]:SetTexture([[Interface\AddOns\Tukui\medias\textures\blank.tga]])
132		_G[frame:GetName().."Thumb"]:SetVertexColor(unpack(C["media"].bordercolor))
133		_G[frame:GetName().."Thumb"]:Size(height-4,height+4)
134	end
135end
136
137--Tab Regions
138local tabs = {
139	"LeftDisabled",
140	"MiddleDisabled",
141	"RightDisabled",
142	"Left",
143	"Middle",
144	"Right",
145}
146
147function T.SkinTab(tab)
148	if not tab then return end
149	for _, object in pairs(tabs) do
150		local tex = _G[tab:GetName()..object]
151		if tex then
152			tex:SetTexture(nil)
153		end
154	end
155	
156	if tab.GetHighlightTexture and tab:GetHighlightTexture() then
157		tab:GetHighlightTexture():SetTexture(nil)
158	else
159		tab:StripTextures()
160	end
161	
162	tab.backdrop = CreateFrame("Frame", nil, tab)
163	tab.backdrop:SetTemplate("Transparent")
164	tab.backdrop:SetFrameLevel(tab:GetFrameLevel() - 1)
165	tab.backdrop:Point("TOPLEFT", 10, -3)
166	tab.backdrop:Point("BOTTOMRIGHT", -10, 3)
167
168	-- always set tab text centered
169	local name = tab:GetName()
170	_G[name.."Text"]:ClearAllPoints()
171	_G[name.."Text"]:SetPoint("TOP", name, 0, -11)
172end
173
174function T.SkinNextPrevButton(btn, horizonal)
175	btn:SetTemplate("Transparent")
176	btn:Size(btn:GetWidth() - 7, btn:GetHeight() - 7)	
177	
178	if horizonal then
179		btn:GetNormalTexture():SetTexCoord(0.3, 0.29, 0.3, 0.72, 0.65, 0.29, 0.65, 0.72)
180		btn:GetPushedTexture():SetTexCoord(0.3, 0.35, 0.3, 0.8, 0.65, 0.35, 0.65, 0.8)
181		btn:GetDisabledTexture():SetTexCoord(0.3, 0.29, 0.3, 0.75, 0.65, 0.29, 0.65, 0.75)	
182	else
183		btn:GetNormalTexture():SetTexCoord(0.3, 0.29, 0.3, 0.81, 0.65, 0.29, 0.65, 0.81)
184		if btn:GetPushedTexture() then
185			btn:GetPushedTexture():SetTexCoord(0.3, 0.35, 0.3, 0.81, 0.65, 0.35, 0.65, 0.81)
186		end
187		if btn:GetDisabledTexture() then
188			btn:GetDisabledTexture():SetTexCoord(0.3, 0.29, 0.3, 0.75, 0.65, 0.29, 0.65, 0.75)
189		end
190	end
191	
192	btn:GetNormalTexture():ClearAllPoints()
193	btn:GetNormalTexture():Point("TOPLEFT", 2, -2)
194	btn:GetNormalTexture():Point("BOTTOMRIGHT", -2, 2)
195	if btn:GetDisabledTexture() then
196		btn:GetDisabledTexture():SetAllPoints(btn:GetNormalTexture())
197	end
198	if btn:GetPushedTexture() then
199		btn:GetPushedTexture():SetAllPoints(btn:GetNormalTexture())
200	end
201	btn:GetHighlightTexture():SetTexture(1, 1, 1, 0.3)
202	btn:GetHighlightTexture():SetAllPoints(btn:GetNormalTexture())
203end
204
205function T.SkinRotateButton(btn)
206	btn:SetTemplate("Transparent")
207	btn:Size(btn:GetWidth() - 14, btn:GetHeight() - 14)	
208	
209	btn:GetNormalTexture():SetTexCoord(0.3, 0.29, 0.3, 0.65, 0.69, 0.29, 0.69, 0.65)
210	btn:GetPushedTexture():SetTexCoord(0.3, 0.29, 0.3, 0.65, 0.69, 0.29, 0.69, 0.65)	
211	
212	btn:GetHighlightTexture():SetTexture(1, 1, 1, 0.3)
213	
214	btn:GetNormalTexture():ClearAllPoints()
215	btn:GetNormalTexture():Point("TOPLEFT", 2, -2)
216	btn:GetNormalTexture():Point("BOTTOMRIGHT", -2, 2)
217	btn:GetPushedTexture():SetAllPoints(btn:GetNormalTexture())	
218	btn:GetHighlightTexture():SetAllPoints(btn:GetNormalTexture())
219end
220
221function T.SkinEditBox(frame)
222	if _G[frame:GetName().."Left"] then _G[frame:GetName().."Left"]:Kill() end
223	if _G[frame:GetName().."Middle"] then _G[frame:GetName().."Middle"]:Kill() end
224	if _G[frame:GetName().."Right"] then _G[frame:GetName().."Right"]:Kill() end
225	if _G[frame:GetName().."Mid"] then _G[frame:GetName().."Mid"]:Kill() end
226	frame:CreateBackdrop("Transparent")
227	
228	if frame:GetName() and frame:GetName():find("Silver") or frame:GetName():find("Copper") then
229		frame.backdrop:Point("BOTTOMRIGHT", -12, -2)
230	end
231end
232
233function T.SkinDropDownBox(frame, width)
234	local button = _G[frame:GetName().."Button"]
235	if not width then width = 155 end
236	
237	frame:StripTextures()
238	frame:Width(width)
239	
240	_G[frame:GetName().."Text"]:ClearAllPoints()
241	_G[frame:GetName().."Text"]:Point("RIGHT", button, "LEFT", -2, 0)
242
243	
244	button:ClearAllPoints()
245	button:Point("RIGHT", frame, "RIGHT", -10, 3)
246	button.SetPoint = T.dummy
247	
248	T.SkinNextPrevButton(button, true)
249	
250	frame:CreateBackdrop("Transparent")
251	frame.backdrop:Point("TOPLEFT", 20, -2)
252	frame.backdrop:Point("BOTTOMRIGHT", button, "BOTTOMRIGHT", 2, -2)
253end
254
255function T.SkinCheckBox(frame)
256	frame:StripTextures()
257	frame:CreateBackdrop("Transparent")
258	frame.backdrop:Point("TOPLEFT", 4, -4)
259	frame.backdrop:Point("BOTTOMRIGHT", -4, 4)
260	
261	if frame.SetCheckedTexture then
262		frame:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check")
263	end
264	
265	if frame.SetDisabledTexture then
266		frame:SetDisabledTexture("Interface\\Buttons\\UI-CheckBox-Check-Disabled")
267	end
268	
269	frame.SetNormalTexture = T.dummy
270	frame.SetPushedTexture = T.dummy
271	frame.SetHighlightTexture = T.dummy
272end
273
274function T.SkinCloseButton(f, point)
275	for i=1, f:GetNumRegions() do
276		local region = select(i, f:GetRegions())
277		if region:GetObjectType() == "Texture" then
278			region:SetDesaturated(1)
279			
280			if region:GetTexture() == "Interface\\DialogFrame\\UI-DialogBox-Corner" then
281				region:Kill()
282			end
283		end
284	end	
285	
286	if point then
287		f:Point("TOPRIGHT", point, "TOPRIGHT", 2, 2)
288	end
289end
290
291local LoadBlizzardSkin = CreateFrame("Frame")
292LoadBlizzardSkin:RegisterEvent("ADDON_LOADED")
293LoadBlizzardSkin:SetScript("OnEvent", function(self, event, addon)
294	if IsAddOnLoaded("Skinner") or IsAddOnLoaded("Aurora") or not C.general.blizzardreskin then
295		self:UnregisterEvent("ADDON_LOADED")
296		return 
297	end
298	
299	for _addon, skinfunc in pairs(T.SkinFuncs) do
300		if type(skinfunc) == "function" then
301			if _addon == addon then
302				if skinfunc then
303					skinfunc()
304				end
305			end
306		elseif type(skinfunc) == "table" then
307			if _addon == addon then
308				for _, skinfunc in pairs(T.SkinFuncs[_addon]) do
309					if skinfunc then
310						skinfunc()
311					end
312				end
313			end
314		end
315	end
316end)