Backdrop.lua

Backdrop.lua (9.0.5.38134; unchanged since 9.0.2.36665)
  1. BACKDROP_TOOLTIP_8_8_1111 = {
  2. bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  3. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  4. tile = true,
  5. tileEdge = true,
  6. tileSize = 8,
  7. edgeSize = 8,
  8. insets = { left = 1, right = 1, top = 1, bottom = 1 },
  9. };
  10. BACKDROP_TOOLTIP_8_12_1111 = {
  11. bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  12. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  13. tile = true,
  14. tileEdge = true,
  15. tileSize = 8,
  16. edgeSize = 12,
  17. insets = { left = 1, right = 1, top = 1, bottom = 1 },
  18. };
  19. BACKDROP_TOOLTIP_16_16_5555 = {
  20. bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  21. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  22. tile = true,
  23. tileEdge = true,
  24. tileSize = 16,
  25. edgeSize = 16,
  26. insets = { left = 5, right = 5, top = 5, bottom = 5 },
  27. };
  28. BACKDROP_TOOLTIP_12_12_4444 = {
  29. bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  30. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  31. tile = true,
  32. tileEdge = true,
  33. tileSize = 12,
  34. edgeSize = 12,
  35. insets = { left = 4, right = 4, top = 4, bottom = 4 },
  36. };
  37. BACKDROP_TOOLTIP_0_16 = {
  38. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  39. edgeSize = 16,
  40. tileEdge = true,
  41. };
  42. BACKDROP_TOOLTIP_0_12_0055 = {
  43. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  44. edgeSize = 12,
  45. tileEdge = true,
  46. insets = { left = 0, right = 0, top = 5, bottom = 5 },
  47. };
  48. BACKDROP_TOOLTIP_0_16_5555 = {
  49. edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  50. edgeSize = 16,
  51. tileEdge = true,
  52. insets = { left = 5, right = 5, top = 5, bottom = 5 },
  53. };
  54. BACKDROP_ACHIEVEMENTS_0_64 = {
  55. edgeFile = "Interface\\AchievementFrame\\UI-Achievement-WoodBorder",
  56. edgeSize = 64,
  57. tileEdge = true,
  58. };
  59. BACKDROP_ARENA_32_32 = {
  60. bgFile = "Interface\\CharacterFrame\\UI-Party-Background",
  61. edgeFile = "Interface\\ArenaEnemyFrame\\UI-Arena-Border",
  62. tile = true,
  63. tileEdge = true,
  64. tileSize = 32,
  65. edgeSize = 32,
  66. insets = { left = 32, right = 32, top = 32, bottom = 32 },
  67. };
  68. BACKDROP_DIALOG_32_32 = {
  69. bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  70. edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
  71. tile = true,
  72. tileEdge = true,
  73. tileSize = 32,
  74. edgeSize = 32,
  75. insets = { left = 11, right = 12, top = 12, bottom = 11 },
  76. };
  77. BACKDROP_GOLD_DIALOG_32_32 = {
  78. bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  79. edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border",
  80. tile = true,
  81. tileEdge = true,
  82. tileSize = 32,
  83. edgeSize = 32,
  84. insets = { left = 11, right = 12, top = 12, bottom = 11 },
  85. };
  86. BACKDROP_WATERMARK_DIALOG_0_16 = {
  87. edgeFile = "Interface\\DialogFrame\\UI-DialogBox-TestWatermark-Border",
  88. tileEdge = true,
  89. edgeSize = 16,
  90. };
  91. BACKDROP_SLIDER_8_8 = {
  92. bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
  93. edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
  94. tile = true,
  95. tileEdge = true,
  96. tileSize = 8,
  97. edgeSize = 8,
  98. insets = { left = 3, right = 3, top = 6, bottom = 6 },
  99. };
  100. BACKDROP_PARTY_32_32 = {
  101. bgFile = "Interface\\CharacterFrame\\UI-Party-Background",
  102. edgeFile = "Interface\\CharacterFrame\\UI-Party-Border",
  103. tile = true,
  104. tileEdge = true,
  105. tileSize = 32,
  106. edgeSize = 32,
  107. insets = { left = 32, right = 32, top = 32, bottom = 32 },
  108. };
  109. BACKDROP_TOAST_12_12 = {
  110. bgFile = "Interface\\FriendsFrame\\UI-Toast-Background",
  111. edgeFile = "Interface\\FriendsFrame\\UI-Toast-Border",
  112. tile = true,
  113. tileEdge = true,
  114. tileSize = 12,
  115. edgeSize = 12,
  116. insets = { left = 5, right = 5, top = 5, bottom = 5 },
  117. };
  118. BACKDROP_CALLOUT_GLOW_0_16 = {
  119. edgeFile = "Interface\\TutorialFrame\\UI-TutorialFrame-CalloutGlow",
  120. edgeSize = 16,
  121. tileEdge = true,
  122. };
  123. BACKDROP_CALLOUT_GLOW_0_20 = {
  124. edgeFile = "Interface\\TutorialFrame\\UI-TutorialFrame-CalloutGlow",
  125. edgeSize = 20,
  126. tileEdge = true,
  127. };
  128. BACKDROP_GLUE_TOOLTIP_16_16 = {
  129. bgFile = "Interface\\Glues\\Common\\Glue-Tooltip-Background",
  130. edgeFile = "Interface\\Glues\\Common\\Glue-Tooltip-Border",
  131. tile = true,
  132. tileEdge = true,
  133. tileSize = 16,
  134. edgeSize = 16,
  135. insets = { left = 10, right = 5, top = 4, bottom = 9 },
  136. };
  137. BACKDROP_GLUE_TOOLTIP_0_16 = {
  138. edgeFile = "Interface\\Glues\\Common\\Glue-Tooltip-Border",
  139. tileEdge = true,
  140. edgeSize = 16,
  141. };
  142. BACKDROP_MIXED_TOOLTIP_16_16 = {
  143. bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  144. edgeFile = "Interface\\Glues\\Common\\Glue-Tooltip-Border",
  145. tile = true,
  146. tileEdge = true,
  147. tileSize = 16,
  148. edgeSize = 16,
  149. insets = { left = 10, right = 5, top = 4, bottom = 9 },
  150. };
  151. BACKDROP_TEXT_PANEL_0_16 = {
  152. edgeFile = "Interface\\Glues\\Common\\TextPanel-Border",
  153. tileEdge = true,
  154. edgeSize = 16,
  155. };
  156. BackdropTemplateMixin = { };
  157. local coordStart = 0.0625;
  158. local coordEnd = 1 - coordStart;
  159. local textureUVs = { -- keys have to match pieceNames in nineSliceSetup table
  160. TopLeftCorner = { setWidth = true, setHeight = true, ULx = 0.5078125, ULy = coordStart, LLx = 0.5078125, LLy = coordEnd, URx = 0.6171875, URy = coordStart, LRx = 0.6171875, LRy = coordEnd },
  161. TopRightCorner = { setWidth = true, setHeight = true, ULx = 0.6328125, ULy = coordStart, LLx = 0.6328125, LLy = coordEnd, URx = 0.7421875, URy = coordStart, LRx = 0.7421875, LRy = coordEnd },
  162. BottomLeftCorner = { setWidth = true, setHeight = true, ULx = 0.7578125, ULy = coordStart, LLx = 0.7578125, LLy = coordEnd, URx = 0.8671875, URy = coordStart, LRx = 0.8671875, LRy = coordEnd },
  163. BottomRightCorner = { setWidth = true, setHeight = true, ULx = 0.8828125, ULy = coordStart, LLx = 0.8828125, LLy = coordEnd, URx = 0.9921875, URy = coordStart, LRx = 0.9921875, LRy = coordEnd },
  164. TopEdge = { setHeight = true, ULx = 0.2578125, ULy = "repeatX", LLx = 0.3671875, LLy = "repeatX", URx = 0.2578125, URy = coordStart, LRx = 0.3671875, LRy = coordStart },
  165. BottomEdge = { setHeight = true, ULx = 0.3828125, ULy = "repeatX", LLx = 0.4921875, LLy = "repeatX", URx = 0.3828125, URy = coordStart, LRx = 0.4921875, LRy = coordStart },
  166. LeftEdge = { setWidth = true, ULx = 0.0078125, ULy = coordStart, LLx = 0.0078125, LLy = "repeatY", URx = 0.1171875, URy = coordStart, LRx = 0.1171875, LRy = "repeatY" },
  167. RightEdge = { setWidth = true, ULx = 0.1328125, ULy = coordStart, LLx = 0.1328125, LLy = "repeatY", URx = 0.2421875, URy = coordStart, LRx = 0.2421875, LRy = "repeatY" },
  168. Center = { ULx = 0, ULy = 0, LLx = 0, LLy = "repeatY", URx = "repeatX", URy = 0, LRx = "repeatX", LRy = "repeatY" },
  169. };
  170. local defaultEdgeSize = 39; -- the old default
  171. function BackdropTemplateMixin:OnBackdropLoaded()
  172. if self.backdropInfo then
  173. -- check for invalid info
  174. if not self.backdropInfo.edgeFile and not self.backdropInfo.bgFile then
  175. self.backdropInfo = nil;
  176. return;
  177. end
  178. self:ApplyBackdrop();
  179. do
  180. local r, g, b = 1, 1, 1;
  181. if self.backdropColor then
  182. r, g, b = self.backdropColor:GetRGB();
  183. end
  184. local a = self.backdropColorAlpha or 1;
  185. self:SetBackdropColor(r, g, b, a);
  186. end
  187. do
  188. local r, g, b = 1, 1, 1;
  189. if self.backdropBorderColor then
  190. r, g, b = self.backdropBorderColor:GetRGB();
  191. end
  192. local a = self.backdropBorderColorAlpha or 1;
  193. self:SetBackdropBorderColor(r, g, b, a);
  194. end
  195. if self.backdropBorderBlendMode then
  196. self:SetBorderBlendMode(self.backdropBorderBlendMode);
  197. end
  198. end
  199. end
  200. function BackdropTemplateMixin:OnBackdropSizeChanged()
  201. if self.backdropInfo then
  202. self:SetupTextureCoordinates();
  203. end
  204. end
  205. function BackdropTemplateMixin:GetEdgeSize()
  206. if self.backdropInfo.edgeSize and self.backdropInfo.edgeSize > 0 then
  207. return self.backdropInfo.edgeSize;
  208. else
  209. return defaultEdgeSize;
  210. end
  211. end
  212. local function GetBackdropCoordValue(coord, pieceSetup, repeatX, repeatY)
  213. local value = pieceSetup[coord];
  214. if value == "repeatX" then
  215. return repeatX;
  216. elseif value == "repeatY" then
  217. return repeatY;
  218. else
  219. return value;
  220. end
  221. end
  222. local function SetupBackdropTextureCoordinates(region, pieceSetup, repeatX, repeatY)
  223. region:SetTexCoord( GetBackdropCoordValue("ULx", pieceSetup, repeatX, repeatY), GetBackdropCoordValue("ULy", pieceSetup, repeatX, repeatY),
  224. GetBackdropCoordValue("LLx", pieceSetup, repeatX, repeatY), GetBackdropCoordValue("LLy", pieceSetup, repeatX, repeatY),
  225. GetBackdropCoordValue("URx", pieceSetup, repeatX, repeatY), GetBackdropCoordValue("URy", pieceSetup, repeatX, repeatY),
  226. GetBackdropCoordValue("LRx", pieceSetup, repeatX, repeatY), GetBackdropCoordValue("LRy", pieceSetup, repeatX, repeatY));
  227. end
  228. function BackdropTemplateMixin:SetupTextureCoordinates()
  229. local width = self:GetWidth();
  230. local height = self:GetHeight();
  231. local effectiveScale = self:GetEffectiveScale();
  232. local edgeSize = self:GetEdgeSize();
  233. local edgeRepeatX = max(0, (width / edgeSize) * effectiveScale - 2 - coordStart);
  234. local edgeRepeatY = max(0, (height / edgeSize) * effectiveScale - 2 - coordStart);
  235. for pieceName, pieceSetup in pairs(textureUVs) do
  236. local region = self[pieceName];
  237. if region then
  238. if pieceName == "Center" then
  239. local repeatX = 1;
  240. local repeatY = 1;
  241. if self.backdropInfo.tile then
  242. local divisor = self.backdropInfo.tileSize;
  243. if not divisor or divisor == 0 then
  244. divisor = edgeSize;
  245. end
  246. if divisor ~= 0 then
  247. repeatX = (width / divisor) * effectiveScale;
  248. repeatY = (height / divisor) * effectiveScale;
  249. end
  250. end
  251. SetupBackdropTextureCoordinates(region, pieceSetup, repeatX, repeatY);
  252. else
  253. SetupBackdropTextureCoordinates(region, pieceSetup, edgeRepeatX, edgeRepeatY);
  254. end
  255. end
  256. end
  257. end
  258. function BackdropTemplateMixin:SetupPieceVisuals(piece, setupInfo, pieceLayout)
  259. local textureInfo = textureUVs[setupInfo.pieceName];
  260. local tileVerts = false;
  261. local file;
  262. if setupInfo.pieceName == "Center" then
  263. file = self.backdropInfo.bgFile;
  264. tileVerts = self.backdropInfo.tile;
  265. else
  266. if self.backdropInfo.tileEdge ~= false then
  267. tileVerts = true;
  268. end
  269. file = self.backdropInfo.edgeFile;
  270. end
  271. piece:SetTexture(file, tileVerts, tileVerts);
  272. local cornerWidth = textureInfo.setWidth and self:GetEdgeSize() or 0;
  273. local cornerHeight = textureInfo.setHeight and self:GetEdgeSize() or 0;
  274. piece:SetSize(cornerWidth, cornerHeight);
  275. end
  276. function BackdropTemplateMixin:SetBorderBlendMode(blendMode)
  277. if not self.backdropInfo then
  278. return;
  279. end
  280. for pieceName in pairs(textureUVs) do
  281. local region = self[pieceName];
  282. if region and pieceName ~= "Center" then
  283. region:SetBlendMode(blendMode);
  284. end
  285. end
  286. end
  287. function BackdropTemplateMixin:HasBackdropInfo(backdropInfo)
  288. return self.backdropInfo == backdropInfo;
  289. end
  290. function BackdropTemplateMixin:ClearBackdrop()
  291. if self.backdropInfo then
  292. for pieceName in pairs(textureUVs) do
  293. local region = self[pieceName];
  294. if region then
  295. region:SetTexture(nil);
  296. end
  297. end
  298. self.backdropInfo = nil;
  299. end
  300. end
  301. function BackdropTemplateMixin:ApplyBackdrop()
  302. local x, y, x1, y1 = 0, 0, 0, 0;
  303. if self.backdropInfo.bgFile then
  304. local edgeSize = self:GetEdgeSize();
  305. x = -edgeSize;
  306. y = edgeSize;
  307. x1 = edgeSize;
  308. y1 = -edgeSize;
  309. local insets = self.backdropInfo.insets;
  310. if insets then
  311. x = x + (insets.left or 0);
  312. y = y - (insets.top or 0);
  313. x1 = x1 - (insets.right or 0);
  314. y1 = y1 + (insets.bottom or 0);
  315. end
  316. end
  317. local layout = {
  318. TopLeftCorner = { },
  319. TopRightCorner = { },
  320. BottomLeftCorner = { },
  321. BottomRightCorner = { },
  322. TopEdge = { },
  323. BottomEdge = { },
  324. LeftEdge = { },
  325. RightEdge = { },
  326. Center = { layer = "BACKGROUND", x = x, y = y, x1 = x1, y1 = y1 },
  327. setupPieceVisualsFunction = BackdropTemplateMixin.SetupPieceVisuals,
  328. };
  329. NineSliceUtil.ApplyLayout(self, layout);
  330. self:SetBackdropColor(1, 1, 1, 1);
  331. self:SetBackdropBorderColor(1, 1, 1, 1);
  332. self:SetupTextureCoordinates();
  333. end
  334. -- backwards compatibility API starts here
  335. function BackdropTemplateMixin:SetBackdrop(backdropInfo)
  336. if backdropInfo then
  337. if self:HasBackdropInfo(backdropInfo) then
  338. return;
  339. end
  340. if not backdropInfo.edgeFile and not backdropInfo.bgFile then
  341. self:ClearBackdrop();
  342. return;
  343. end
  344. self.backdropInfo = backdropInfo;
  345. self:ApplyBackdrop();
  346. else
  347. self:ClearBackdrop();
  348. end
  349. end
  350. function BackdropTemplateMixin:GetBackdrop()
  351. if self.backdropInfo then
  352. -- make a copy because it will be altered to match old API output
  353. local backdropInfo = CopyTable(self.backdropInfo);
  354. -- fill in defaults
  355. if not backdropInfo.bgFile then
  356. backdropInfo.bgFile = "";
  357. end
  358. if not backdropInfo.edgeFile then
  359. backdropInfo.edgeFile = "";
  360. end
  361. if backdropInfo.tile == nil then
  362. backdropInfo.tile = false;
  363. end
  364. if backdropInfo.tileSize == nil then
  365. backdropInfo.tileSize = 0;
  366. end
  367. if backdropInfo.tileEdge == nil then
  368. backdropInfo.tileEdge = true;
  369. end
  370. if not backdropInfo.edgeSize then
  371. backdropInfo.edgeSize = self:GetEdgeSize();
  372. end
  373. if not backdropInfo.insets then
  374. backdropInfo.insets = { };
  375. end
  376. if not backdropInfo.insets.left then
  377. backdropInfo.insets.left = 0;
  378. end
  379. if not backdropInfo.insets.right then
  380. backdropInfo.insets.right = 0;
  381. end
  382. if not backdropInfo.insets.top then
  383. backdropInfo.insets.top = 0;
  384. end
  385. if not backdropInfo.insets.bottom then
  386. backdropInfo.insets.bottom = 0;
  387. end
  388. return backdropInfo;
  389. end
  390. return nil;
  391. end
  392. function BackdropTemplateMixin:GetBackdropColor()
  393. if not self.backdropInfo then
  394. return;
  395. end
  396. if self.Center then
  397. return self.Center:GetVertexColor();
  398. end
  399. end
  400. function BackdropTemplateMixin:SetBackdropColor(r, g, b, a)
  401. if not self.backdropInfo then
  402. -- Ideally this would throw an error here but the old API just failed silently
  403. return;
  404. end
  405. if self.Center then
  406. self.Center:SetVertexColor(r, g, b, a or 1);
  407. end
  408. end
  409. function BackdropTemplateMixin:GetBackdropBorderColor()
  410. if not self.backdropInfo then
  411. return
  412. end
  413. -- return the vertex color of any valid region
  414. for pieceName in pairs(textureUVs) do
  415. local region = self[pieceName];
  416. if region and pieceName ~= "Center" then
  417. return region:GetVertexColor();
  418. end
  419. end
  420. end
  421. function BackdropTemplateMixin:SetBackdropBorderColor(r, g, b, a)
  422. if not self.backdropInfo then
  423. -- Ideally this would throw an error here but the old API just failed silently
  424. return;
  425. end
  426. for pieceName in pairs(textureUVs) do
  427. local region = self[pieceName];
  428. if region and pieceName ~= "Center" then
  429. region:SetVertexColor(r, g, b, a or 1);
  430. end
  431. end
  432. end