Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.84 KB | None | 0 0
  1. local E, L, V, P, G = unpack(select(2, ...)); --Inport: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
  2. local LSM = LibStub("LibSharedMedia-3.0")
  3.  
  4. --Cache global variables
  5. --Lua functions
  6. local _G = _G
  7. local unpack, type, select, getmetatable, assert = unpack, type, select, getmetatable, assert
  8. --WoW API / Variables
  9. local CreateFrame = CreateFrame
  10. local RAID_CLASS_COLORS = RAID_CLASS_COLORS
  11. local CUSTOM_CLASS_COLORS = CUSTOM_CLASS_COLORS
  12.  
  13. --Preload shit..
  14. E.mult = 1;
  15. local backdropr, backdropg, backdropb, backdropa, borderr, borderg, borderb = 0, 0, 0, 1, 0, 0, 0
  16.  
  17. local function GetTemplate(t, isPixelPerfectForced)
  18. backdropa = 1
  19.  
  20. if t == "ClassColor" then
  21. if CUSTOM_CLASS_COLORS then
  22. borderr, borderg, borderb = CUSTOM_CLASS_COLORS[E.myclass].r, CUSTOM_CLASS_COLORS[E.myclass].g, CUSTOM_CLASS_COLORS[E.myclass].b
  23. else
  24. borderr, borderg, borderb = RAID_CLASS_COLORS[E.myclass].r, RAID_CLASS_COLORS[E.myclass].g, RAID_CLASS_COLORS[E.myclass].b
  25. end
  26. if t ~= "Transparent" then
  27. backdropr, backdropg, backdropb = unpack(E["media"].backdropcolor)
  28. else
  29. backdropr, backdropg, backdropb, backdropa = unpack(E["media"].backdropfadecolor)
  30. end
  31. elseif t == "Transparent" then
  32. borderr, borderg, borderb = unpack(E["media"].bordercolor)
  33. backdropr, backdropg, backdropb, backdropa = unpack(E["media"].backdropfadecolor)
  34. else
  35. borderr, borderg, borderb = unpack(E["media"].bordercolor)
  36. backdropr, backdropg, backdropb = unpack(E["media"].backdropcolor)
  37. end
  38.  
  39. if(isPixelPerfectForced) then
  40. borderr, borderg, borderb = 0, 0, 0
  41. end
  42. end
  43.  
  44. local function Size(frame, width, height)
  45. assert(width)
  46. frame:SetSize(E:Scale(width), E:Scale(height or width))
  47. end
  48.  
  49. local function Width(frame, width)
  50. --[[if(not width) then
  51. if frame:GetName() then
  52. assert(width,frame:GetName()..' Width not set properly.')
  53. end
  54. assert(width,'Width not set properly.')
  55. end]]
  56.  
  57. frame:SetWidth(E:Scale(width))
  58. end
  59.  
  60. local function Height(frame, height)
  61. assert(height)
  62. frame:SetHeight(E:Scale(height))
  63. end
  64.  
  65. local function Point(obj, arg1, arg2, arg3, arg4, arg5)
  66. if arg2 == nil then
  67. arg2 = obj:GetParent()
  68. end
  69.  
  70. if type(arg1)=="number" then arg1 = E:Scale(arg1) end
  71. if type(arg2)=="number" then arg2 = E:Scale(arg2) end
  72. if type(arg3)=="number" then arg3 = E:Scale(arg3) end
  73. if type(arg4)=="number" then arg4 = E:Scale(arg4) end
  74. if type(arg5)=="number" then arg5 = E:Scale(arg5) end
  75.  
  76. obj:SetPoint(arg1, arg2, arg3, arg4, arg5)
  77. end
  78.  
  79. local function SetOutside(obj, anchor, xOffset, yOffset, anchor2)
  80. xOffset = xOffset or E.Border
  81. yOffset = yOffset or E.Border
  82. anchor = anchor or obj:GetParent()
  83.  
  84. assert(anchor)
  85. if obj:GetPoint() then
  86. obj:ClearAllPoints()
  87. end
  88.  
  89. obj:Point('TOPLEFT', anchor, 'TOPLEFT', -xOffset, yOffset)
  90. obj:Point('BOTTOMRIGHT', anchor2 or anchor, 'BOTTOMRIGHT', xOffset, -yOffset)
  91. end
  92.  
  93. local function SetInside(obj, anchor, xOffset, yOffset, anchor2)
  94. xOffset = xOffset or E.Border
  95. yOffset = yOffset or E.Border
  96. anchor = anchor or obj:GetParent()
  97.  
  98. assert(anchor)
  99. if obj:GetPoint() then
  100. obj:ClearAllPoints()
  101. end
  102.  
  103. obj:Point('TOPLEFT', anchor, 'TOPLEFT', xOffset, -yOffset)
  104. obj:Point('BOTTOMRIGHT', anchor2 or anchor, 'BOTTOMRIGHT', -xOffset, yOffset)
  105. end
  106.  
  107. local function SetTemplate(f, t, glossTex, ignoreUpdates, forcePixelMode)
  108. GetTemplate(t, f.forcePixelMode or forcePixelMode)
  109.  
  110. if(t) then
  111. f.template = t
  112. end
  113.  
  114. if(glossTex) then
  115. f.glossTex = glossTex
  116. end
  117.  
  118. if(ignoreUpdates) then
  119. f.ignoreUpdates = ignoreUpdates
  120. end
  121.  
  122. if(forcePixelMode) then
  123. f.forcePixelMode = forcePixelMode
  124. end
  125. if t ~= "NoBackdrop" then
  126. if E.private.general.pixelPerfect or f.forcePixelMode then
  127. f:SetBackdrop({
  128. bgFile = E["media"].blankTex,
  129. edgeFile = E["media"].blankTex,
  130. tile = false, tileSize = 0, edgeSize = 1,
  131. insets = { left = 1, right = 1, top = 1, bottom = 1 }
  132. })
  133. else
  134. f:SetBackdrop({
  135. bgFile = E["media"].blankTex,
  136. edgeFile = E["media"].blankTex,
  137. tile = false, tileSize = 0, edgeSize = 1,
  138. insets = { left = -0, right = -0, top = -0, bottom = -0 }
  139. })
  140. end
  141.  
  142. if not f.backdropTexture and t ~= 'Transparent' then
  143. local backdropTexture = f:CreateTexture(nil, "BORDER")
  144. backdropTexture:SetDrawLayer("BACKGROUND", 1)
  145. f.backdropTexture = backdropTexture
  146. elseif t == 'Transparent' then
  147. f:SetBackdropColor(backdropr, backdropg, backdropb, backdropa)
  148.  
  149. if f.backdropTexture then
  150. f.backdropTexture:Hide()
  151. f.backdropTexture = nil
  152. end
  153.  
  154. if not f.oborder and not f.iborder and not E.private.general.pixelPerfect and not f.forcePixelMode then
  155. local border = CreateFrame("Frame", nil, f)
  156. border:SetInside(f, E.mult-4, E.mult-4)
  157. border:SetBackdrop({
  158. edgeFile = E["media"].blankTex,
  159. edgeSize = 1,
  160. insets = { left = 1, right = 1, top = 1, bottom = 1 }
  161. })
  162. border:SetBackdropBorderColor(0, 0, 0, 0)
  163. f.iborder = border
  164.  
  165. if f.oborder then return end
  166. local border = CreateFrame("Frame", nil, f)
  167. border:SetOutside(f, E.mult, E.mult)
  168. border:SetFrameLevel(f:GetFrameLevel() + 1)
  169. border:SetBackdrop({
  170. edgeFile = E["media"].blankTex,
  171. edgeSize = 1,
  172. insets = { left = 1, right = 1, top = 1, bottom = 1 }
  173. })
  174. border:SetBackdropBorderColor(0, 0, 0, 1)
  175. f.oborder = border
  176. end
  177. end
  178.  
  179. if f.backdropTexture then
  180. f:SetBackdropColor(0, 0, 0, backdropa)
  181. f.backdropTexture:SetVertexColor(backdropr, backdropg, backdropb)
  182. f.backdropTexture:SetAlpha(backdropa)
  183. if glossTex then
  184. f.backdropTexture:SetTexture(E["media"].glossTex)
  185. else
  186. f.backdropTexture:SetTexture(E["media"].blankTex)
  187. end
  188.  
  189. if(f.forcePixelMode or forcePixelMode) then
  190. f.backdropTexture:SetInside(f, E.mult, E.mult)
  191. else
  192. f.backdropTexture:SetInside(f)
  193. end
  194. end
  195. else
  196. f:SetBackdrop(nil)
  197. if f.backdropTexture then f.backdropTexture:SetTexture(nil) end
  198. end
  199. f:SetBackdropBorderColor(borderr, borderg, borderb)
  200.  
  201. if not f.ignoreUpdates and not f.forcePixelMode then
  202. E["frames"][f] = true
  203. end
  204. end
  205.  
  206. local function CreateBackdrop(f, t, tex, ignoreUpdates, forcePixelMode)
  207. if not t then t = "Default" end
  208.  
  209. local b = CreateFrame("Frame", nil, f)
  210. if(f.forcePixelMode or forcePixelMode) then
  211. b:SetOutside(nil, E.mult, E.mult)
  212. else
  213. b:SetOutside()
  214. end
  215. b:SetTemplate(t, tex, ignoreUpdates, forcePixelMode)
  216.  
  217. if f:GetFrameLevel() - 1 >= 0 then
  218. b:SetFrameLevel(f:GetFrameLevel() - 1)
  219. else
  220. b:SetFrameLevel(0)
  221. end
  222.  
  223. f.backdrop = b
  224. end
  225.  
  226. local function CreateShadow(f)
  227. if f.shadow then return end
  228.  
  229. borderr, borderg, borderb = 0, 0, 0
  230. backdropr, backdropg, backdropb = 0, 0, 0
  231.  
  232. local shadow = CreateFrame("Frame", nil, f)
  233. shadow:SetFrameLevel(1)
  234. shadow:SetFrameStrata(f:GetFrameStrata())
  235. shadow:SetOutside(f, 3, 3)
  236. shadow:SetBackdrop( {
  237. edgeFile = LSM:Fetch("border", "ElvUI GlowBorder"), edgeSize = -4,
  238. insets = {left = 1, right = 1, top = 1, bottom = 1},
  239. })
  240. shadow:SetBackdropColor(backdropr, backdropg, backdropb, 0)
  241. shadow:SetBackdropBorderColor(borderr, borderg, borderb, 0.9)
  242. f.shadow = shadow
  243. end
  244.  
  245. local function Kill(object)
  246. if object.UnregisterAllEvents then
  247. object:UnregisterAllEvents()
  248. object:SetParent(E.HiddenFrame)
  249. else
  250. object.Show = object.Hide
  251. end
  252.  
  253. object:Hide()
  254. end
  255.  
  256. local function StripTextures(object, kill)
  257. for i=1, object:GetNumRegions() do
  258. local region = select(i, object:GetRegions())
  259. if region and region:GetObjectType() == "Texture" then
  260. if kill and type(kill) == 'boolean' then
  261. region:Kill()
  262. elseif region:GetDrawLayer() == kill then
  263. region:SetTexture(nil)
  264. elseif kill and type(kill) == 'string' and region:GetTexture() ~= kill then
  265. region:SetTexture(nil)
  266. else
  267. region:SetTexture(nil)
  268. end
  269. end
  270. end
  271. end
  272.  
  273. local function FontTemplate(fs, font, fontSize, fontStyle)
  274. fs.font = font
  275. fs.fontSize = fontSize
  276. fs.fontStyle = fontStyle
  277.  
  278. font = font or LSM:Fetch("font", E.db['general'].font)
  279. fontSize = fontSize or E.db.general.fontSize
  280.  
  281. if fontStyle == 'OUTLINE' and (E.db.general.font == "Homespun") then
  282. if (fontSize > 10 and not fs.fontSize) then
  283. fontStyle = 'MONOCHROMEOUTLINE'
  284. fontSize = 10
  285. end
  286. end
  287.  
  288. fs:SetFont(font, fontSize, fontStyle)
  289. if fontStyle and (fontStyle ~= "NONE") then
  290. fs:SetShadowColor(0, 0, 0, 0)
  291. else
  292. fs:SetShadowColor(0, 0, 0, 0)
  293. end
  294. fs:SetShadowOffset((E.mult or 1), -(E.mult or 1))
  295.  
  296. E["texts"][fs] = true
  297. end
  298.  
  299. local function StyleButton(button, noHover, noPushed, noChecked)
  300. if button.SetHighlightTexture and not button.hover and not noHover then
  301. local hover = button:CreateTexture()
  302. hover:SetColorTexture(1, 1, 1, 0.3)
  303. hover:SetInside()
  304. button.hover = hover
  305. button:SetHighlightTexture(hover)
  306. end
  307.  
  308. if button.SetPushedTexture and not button.pushed and not noPushed then
  309. local pushed = button:CreateTexture()
  310. pushed:SetColorTexture(0.9, 0.8, 0.1, 0.3)
  311. pushed:SetInside()
  312. button.pushed = pushed
  313. button:SetPushedTexture(pushed)
  314. end
  315.  
  316. if button.SetCheckedTexture and not button.checked and not noChecked then
  317. local checked = button:CreateTexture()
  318. checked:SetColorTexture(1, 1, 1, 0.3)
  319. checked:SetInside()
  320. button.checked = checked
  321. button:SetCheckedTexture(checked)
  322. end
  323.  
  324. local cooldown = button:GetName() and _G[button:GetName().."Cooldown"]
  325. if cooldown then
  326. cooldown:ClearAllPoints()
  327. cooldown:SetInside()
  328. cooldown:SetDrawEdge(false)
  329. cooldown:SetSwipeColor(0, 0, 0, 1)
  330. end
  331. end
  332.  
  333. local function addapi(object)
  334. local mt = getmetatable(object).__index
  335. if not object.Size then mt.Size = Size end
  336. if not object.Point then mt.Point = Point end
  337. if not object.SetOutside then mt.SetOutside = SetOutside end
  338. if not object.SetInside then mt.SetInside = SetInside end
  339. if not object.SetTemplate then mt.SetTemplate = SetTemplate end
  340. if not object.CreateBackdrop then mt.CreateBackdrop = CreateBackdrop end
  341. if not object.CreateShadow then mt.CreateShadow = CreateShadow end
  342. if not object.Kill then mt.Kill = Kill end
  343. if not object.Width then mt.Width = Width end
  344. if not object.Height then mt.Height = Height end
  345. if not object.FontTemplate then mt.FontTemplate = FontTemplate end
  346. if not object.StripTextures then mt.StripTextures = StripTextures end
  347. if not object.StyleButton then mt.StyleButton = StyleButton end
  348. end
  349.  
  350. local handled = {["Frame"] = true}
  351. local object = CreateFrame("Frame")
  352. addapi(object)
  353. addapi(object:CreateTexture())
  354. addapi(object:CreateFontString())
  355.  
  356. object = EnumerateFrames()
  357. while object do
  358. if not object:IsForbidden() and not handled[object:GetObjectType()] then
  359. addapi(object)
  360. handled[object:GetObjectType()] = true
  361. end
  362.  
  363. object = EnumerateFrames(object)
  364. end
  365.  
  366. --Hacky fix for issue on 7.1 PTR where scroll frames no longer seem to inherit the methods from the "Frame" widget
  367. local scrollFrame = CreateFrame("ScrollFrame")
  368. addapi(scrollFrame)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement