/Tukui/modules/skins/core.lua

http://github.com/Asphyxia/Tukui · Lua · 316 lines · 301 code · 15 blank · 0 comment · 15 complexity · aa2d9de5a1412a0d37411e02be7f3915 MD5 · raw file

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