Advertisement
Guest User

!Beautycase

a guest
Nov 2nd, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.92 KB | None | 0 0
  1. --[[
  2.    
  3.     How to use:
  4.          
  5.     ----------------------------------------------
  6.    
  7.     CreateBorder(myFrame, borderSize, r, g, b, uL1, uL2, uR1, uR2, bL1, bL2, bR1, bR2)
  8.        
  9.         myFrame         -> The name of your frame, It must be a frame not a texture/fontstring
  10.         borderSize      -> The size of the simple square Border. 10-12 looks amazing with the default beautycase texture
  11.         r, g, b         -> The colors of the Border. r = Red, g = Green, b = Blue
  12.         uL1, uL2        -> top left x, top left y
  13.         uR1, uR2        -> top right x, top right y
  14.         bL1, bL2        -> bottom left x, bottom left y
  15.         bR1, bR2        -> bottom right x, bottom right y
  16.    
  17.    
  18.     for example:
  19.            
  20.             local r, g, b = 1, 1, 0 -- for yellow
  21.             CreateBorder(myFrame, 12, r, g, b, 1, 1, 1, 1, 1, 1, 1, 1)
  22.        
  23.        
  24.         shorter method if the spacing between the frame is always the same
  25.        
  26.             CreateBorder(myFrame, 12, r, g, b, 1)
  27.            
  28.        
  29.         or for no spacing
  30.        
  31.             CreateBorder(myFrame, 12, r, g, b)
  32.    
  33.    
  34.     ----------------------------------------------
  35.    
  36.     If you want you recolor the border or shadow (for aggrowarning or similar) you can make this with this little trick
  37.    
  38.         ColorBorder(myFrame, r, g, b, alpha)
  39.         ColorBorderShadow(myFrame, r, g, b, alpha)
  40.        
  41.     ----------------------------------------------
  42.    
  43.     For changing the border or shadow texture
  44.    
  45.         SetBorderTexture(myFrame, texture.tga)
  46.         SetBorderShadowTexture(myFrame, texture.tga)
  47.      
  48.     ----------------------------------------------
  49.    
  50.     For all Border Infos
  51.    
  52.         local borderSize, texture, r, g, b, alpha = GetBorderInfo(myFrame)
  53.      
  54.     ----------------------------------------------
  55.    
  56.    
  57.    
  58.     ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  59.    
  60.    
  61.     NEW!
  62.    
  63.     myFrame:CreateBorder(borderSize)
  64.     myFrame:SetBorderSize(borderSize)
  65.    
  66.     myFrame:SetBorderPadding(number or [uL1, uL2, uR1, uR2, bL1, bL2, bR1, bR2])
  67.    
  68.     myFrame:SetBorderTexture(texture)
  69.     myFrame:SetBorderShadowTexture(texture)
  70.    
  71.     myFrame:SetBorderColor(r, g, b)
  72.     myFrame:SetBorderShadowColor(r, g, b)
  73.    
  74.     myFrame:HideBorder()
  75.     myFrame:ShowBorder()
  76.    
  77.     myFrame:GetBorder() - true if has a beautycase border, otherwise false
  78.    
  79.     local borderSize, texture, r, g, b, alpha = myFrame:GetBorderInfo()
  80.    
  81.    
  82.     ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  83.    
  84. --]]
  85.  
  86. local addonName = select(1, GetAddOnInfo('!Beautycase'))
  87. local formatName = '|cffFF0000'..addonName
  88.  
  89. local textureNormal = 'Interface\\AddOns\\!Beautycase\\media\\textureNormal'
  90. local textureShadow = 'Interface\\AddOns\\!Beautycase\\media\\textureShadow'
  91.  
  92. local function GetBorder(self)
  93.     if (self.beautyBorder) then
  94.         return true
  95.     else
  96.         return false
  97.     end
  98. end
  99.  
  100. function GetBorderInfo(self)
  101.     if (not self) then
  102.         print(formatName..' error:|r This frame does not exist!')
  103.     elseif (self.beautyBorder) then
  104.         local tex = self.beautyBorder[1]:GetTexture()
  105.         local size = self.beautyBorder[1]:GetSize()
  106.         local r, g, b, a = self.beautyBorder[1]:GetVertexColor()
  107.        
  108.         return size, tex, r, g, b, a
  109.     else
  110.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  111.     end
  112. end
  113.  
  114. local function SetBorderPadding(self, uL1, ...)
  115.     if (not self) then
  116.         print(formatName..' error:|r This frame does not exist!')
  117.         return
  118.     end
  119.    
  120.     if (not self:IsObjectType('Frame')) then
  121.         local frame  = 'frame'
  122.         print(formatName..' error:|r The entered object is not a '..frame..'!')
  123.         return
  124.     end
  125.    
  126.     local uL2, uR1, uR2, bL1, bL2, bR1, bR2 = ...
  127.     if (uL1) then
  128.         if (not uL2 and not uR1 and not uR2 and not bL1 and not bL2 and not bR1 and not bR2) then
  129.             uL2, uR1, uR2, bL1, bL2, bR1, bR2 = uL1, uL1, uL1, uL1, uL1, uL1, uL1
  130.         end
  131.     end
  132.    
  133.     local space
  134.     if (GetBorderInfo(self) >= 10) then
  135.         space = 3
  136.     else
  137.         space = GetBorderInfo(self)/3.5
  138.     end
  139.        
  140.     if (self.beautyBorder) then
  141.         self.beautyBorder[1]:SetPoint('TOPLEFT', self, -(uL1 or 0), uL2 or 0)
  142.         self.beautyShadow[1]:SetPoint('TOPLEFT', self, -(uL1 or 0)-space, (uL2 or 0)+space)
  143.        
  144.         self.beautyBorder[2]:SetPoint('TOPRIGHT', self, uR1 or 0, uR2 or 0)
  145.         self.beautyShadow[2]:SetPoint('TOPRIGHT', self, (uR1 or 0)+space, (uR2 or 0)+space)
  146.        
  147.         self.beautyBorder[3]:SetPoint('BOTTOMLEFT', self, -(bL1 or 0), -(bL2 or 0))
  148.         self.beautyShadow[3]:SetPoint('BOTTOMLEFT', self, -(bL1 or 0)-space, -(bL2 or 0)-space)
  149.        
  150.         self.beautyBorder[4]:SetPoint('BOTTOMRIGHT', self, bR1 or 0, -(bR2 or 0))
  151.         self.beautyShadow[4]:SetPoint('BOTTOMRIGHT', self, (bR1 or 0)+space, -(bR2 or 0)-space)
  152.     end
  153. end
  154.  
  155. function ColorBorder(self, ...)
  156.     local r, g, b, a = ...
  157.    
  158.     if (not self) then
  159.         print(formatName..' error:|r This frame does not exist!')
  160.     elseif (self.beautyBorder) then
  161.         for i = 1, 8 do
  162.             self.beautyBorder[i]:SetVertexColor(r, g, b, a or 1)
  163.         end
  164.     else
  165.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  166.     end
  167. end
  168.  
  169. function ColorBorderShadow(self, ...)
  170.     local r, g, b, a = ...
  171.    
  172.     if (not self) then
  173.         print(formatName..' error:|r This frame does not exist!')
  174.     elseif (self.beautyShadow) then
  175.         for i = 1, 8 do
  176.             self.beautyShadow[i]:SetVertexColor(r, g, b, a or 1)
  177.         end
  178.     else
  179.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  180.     end
  181. end
  182.  
  183. function SetBorderTexture(self, texture)
  184.     if (not self) then
  185.         print(formatName..' error:|r This frame does not exist!')
  186.     elseif (self.beautyBorder) then
  187.         for i = 1, 8 do
  188.             self.beautyBorder[i]:SetTexture(texture)
  189.         end
  190.     else
  191.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  192.     end
  193. end
  194.  
  195. function SetBorderShadowTexture(self, texture)
  196.     if (not self) then
  197.         print(formatName..' error:|r This frame does not exist!')
  198.     elseif (self.beautyShadow) then
  199.         for i = 1, 8 do
  200.             self.beautyShadow[i]:SetTexture(texture)
  201.         end
  202.     else
  203.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  204.     end
  205. end
  206.  
  207. local function SetBorderSize(self, size)
  208.     if (not self) then
  209.         print(formatName..' error:|r This frame does not exist!')
  210.     elseif (self.beautyShadow) then
  211.         for i = 1, 8 do
  212.             self.beautyBorder[i]:SetSize(size, size)
  213.             self.beautyShadow[i]:SetSize(size, size)
  214.         end
  215.     else
  216.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  217.     end
  218. end
  219.  
  220. local function HideBorder(self)
  221.     if (not self) then
  222.         print(formatName..' error:|r This frame does not exist!')
  223.     elseif (self.beautyShadow) then
  224.         for i = 1, 8 do
  225.             self.beautyBorder[i]:Hide()
  226.             self.beautyShadow[i]:Hide()
  227.         end
  228.     else
  229.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  230.     end
  231. end
  232.  
  233. local function ShowBorder(self)
  234.     if (not self) then
  235.         print(formatName..' error:|r This frame does not exist!')
  236.     elseif (self.beautyShadow) then
  237.         for i = 1, 8 do
  238.             self.beautyBorder[i]:Show()
  239.             self.beautyShadow[i]:Show()
  240.         end
  241.     else
  242.         print(formatName..' error:|r Invalid frame! This object has no '..addonName..' border')  
  243.     end
  244. end
  245.  
  246. local function ApplyBorder(self, borderSize, R, G, B, uL1, ...)
  247.     if (not self) then
  248.         print(formatName..' error:|r This frame does not exist!')
  249.         return
  250.     end
  251.    
  252.     if (not self:IsObjectType('Frame')) then
  253.         local frame  = 'frame'
  254.         print(formatName..' error:|r The entered object is not a '..frame..'!')
  255.         return
  256.     end
  257.    
  258.     if (self.HasBeautyBorder) then
  259.         return
  260.     end
  261.    
  262.     local uL2, uR1, uR2, bL1, bL2, bR1, bR2 = ...
  263.     if (uL1) then
  264.         if (not uL2 and not uR1 and not uR2 and not bL1 and not bL2 and not bR1 and not bR2) then
  265.             uL2, uR1, uR2, bL1, bL2, bR1, bR2 = uL1, uL1, uL1, uL1, uL1, uL1, uL1
  266.         end
  267.     end
  268.    
  269.     local space
  270.     if (borderSize >= 10) then
  271.         space = 3
  272.     else
  273.         space = borderSize/3.5
  274.     end
  275.        
  276.     if (not self.HasBeautyBorder) then
  277.    
  278.         self.beautyShadow = {}
  279.         for i = 1, 8 do
  280.             self.beautyShadow[i] = self:CreateTexture(nil, 'BORDER')
  281.             self.beautyShadow[i]:SetParent(self)
  282.             self.beautyShadow[i]:SetTexture(textureShadow)
  283.             self.beautyShadow[i]:SetSize(borderSize, borderSize)  
  284.             self.beautyShadow[i]:SetVertexColor(0, 0, 0, 1)
  285.         end
  286.        
  287.         self.beautyBorder = {}
  288.         for i = 1, 8 do
  289.             self.beautyBorder[i] = self:CreateTexture(nil, 'OVERLAY')
  290.             self.beautyBorder[i]:SetParent(self)
  291.             self.beautyBorder[i]:SetTexture(textureNormal)
  292.             self.beautyBorder[i]:SetSize(borderSize, borderSize)
  293.             self.beautyBorder[i]:SetVertexColor(R or 1, G or 1, B or 1)
  294.         end
  295.        
  296.         self.beautyBorder[1]:SetTexCoord(0, 1/3, 0, 1/3)
  297.         self.beautyBorder[1]:SetPoint('TOPLEFT', self, -(uL1 or 0), uL2 or 0)
  298.  
  299.         self.beautyBorder[2]:SetTexCoord(2/3, 1, 0, 1/3)
  300.         self.beautyBorder[2]:SetPoint('TOPRIGHT', self, uR1 or 0, uR2 or 0)
  301.  
  302.         self.beautyBorder[3]:SetTexCoord(0, 1/3, 2/3, 1)
  303.         self.beautyBorder[3]:SetPoint('BOTTOMLEFT', self, -(bL1 or 0), -(bL2 or 0))
  304.  
  305.         self.beautyBorder[4]:SetTexCoord(2/3, 1, 2/3, 1)
  306.         self.beautyBorder[4]:SetPoint('BOTTOMRIGHT', self, bR1 or 0, -(bR2 or 0))
  307.  
  308.         self.beautyBorder[5]:SetTexCoord(1/3, 2/3, 0, 1/3)
  309.         self.beautyBorder[5]:SetPoint('TOPLEFT', self.beautyBorder[1], 'TOPRIGHT')
  310.         self.beautyBorder[5]:SetPoint('TOPRIGHT', self.beautyBorder[2], 'TOPLEFT')
  311.  
  312.         self.beautyBorder[6]:SetTexCoord(1/3, 2/3, 2/3, 1)
  313.         self.beautyBorder[6]:SetPoint('BOTTOMLEFT', self.beautyBorder[3], 'BOTTOMRIGHT')
  314.         self.beautyBorder[6]:SetPoint('BOTTOMRIGHT', self.beautyBorder[4], 'BOTTOMLEFT')
  315.  
  316.         self.beautyBorder[7]:SetTexCoord(0, 1/3, 1/3, 2/3)
  317.         self.beautyBorder[7]:SetPoint('TOPLEFT', self.beautyBorder[1], 'BOTTOMLEFT')
  318.         self.beautyBorder[7]:SetPoint('BOTTOMLEFT', self.beautyBorder[3], 'TOPLEFT')
  319.  
  320.         self.beautyBorder[8]:SetTexCoord(2/3, 1, 1/3, 2/3)
  321.         self.beautyBorder[8]:SetPoint('TOPRIGHT', self.beautyBorder[2], 'BOTTOMRIGHT')
  322.         self.beautyBorder[8]:SetPoint('BOTTOMRIGHT', self.beautyBorder[4], 'TOPRIGHT')
  323.        
  324.         self.beautyShadow[1]:SetTexCoord(0, 1/3, 0, 1/3)
  325.         self.beautyShadow[1]:SetPoint('TOPLEFT', self, -(uL1 or 0)-space, (uL2 or 0)+space)
  326.  
  327.         self.beautyShadow[2]:SetTexCoord(2/3, 1, 0, 1/3)
  328.         self.beautyShadow[2]:SetPoint('TOPRIGHT', self, (uR1 or 0)+space, (uR2 or 0)+space)
  329.  
  330.         self.beautyShadow[3]:SetTexCoord(0, 1/3, 2/3, 1)
  331.         self.beautyShadow[3]:SetPoint('BOTTOMLEFT', self, -(bL1 or 0)-space, -(bL2 or 0)-space)
  332.  
  333.         self.beautyShadow[4]:SetTexCoord(2/3, 1, 2/3, 1)
  334.         self.beautyShadow[4]:SetPoint('BOTTOMRIGHT', self, (bR1 or 0)+space, -(bR2 or 0)-space)
  335.  
  336.         self.beautyShadow[5]:SetTexCoord(1/3, 2/3, 0, 1/3)
  337.         self.beautyShadow[5]:SetPoint('TOPLEFT', self.beautyShadow[1], 'TOPRIGHT')
  338.         self.beautyShadow[5]:SetPoint('TOPRIGHT', self.beautyShadow[2], 'TOPLEFT')
  339.  
  340.         self.beautyShadow[6]:SetTexCoord(1/3, 2/3, 2/3, 1)
  341.         self.beautyShadow[6]:SetPoint('BOTTOMLEFT', self.beautyShadow[3], 'BOTTOMRIGHT')
  342.         self.beautyShadow[6]:SetPoint('BOTTOMRIGHT', self.beautyShadow[4], 'BOTTOMLEFT')
  343.  
  344.         self.beautyShadow[7]:SetTexCoord(0, 1/3, 1/3, 2/3)
  345.         self.beautyShadow[7]:SetPoint('TOPLEFT', self.beautyShadow[1], 'BOTTOMLEFT')
  346.         self.beautyShadow[7]:SetPoint('BOTTOMLEFT', self.beautyShadow[3], 'TOPLEFT')
  347.  
  348.         self.beautyShadow[8]:SetTexCoord(2/3, 1, 1/3, 2/3)
  349.         self.beautyShadow[8]:SetPoint('TOPRIGHT', self.beautyShadow[2], 'BOTTOMRIGHT')
  350.         self.beautyShadow[8]:SetPoint('BOTTOMRIGHT', self.beautyShadow[4], 'TOPRIGHT')
  351.        
  352.         self.HasBeautyBorder = true
  353.     end
  354. end
  355.  
  356. function CreateBorder(self, borderSize, R, G, B, uL1, ...)
  357.     ApplyBorder(self, borderSize, R, G, B, uL1, ...)
  358. end
  359.  
  360. local function FuncCreateBorder(self, borderSize)
  361.     ApplyBorder(self, borderSize)
  362. end
  363.  
  364. local function addapi(object)
  365.     local mt = getmetatable(object).__index
  366.    
  367.     mt.CreateBorder = FuncCreateBorder
  368.     mt.SetBorderSize = SetBorderSize
  369.    
  370.     mt.SetBorderPadding = SetBorderPadding
  371.    
  372.     mt.SetBorderTexture = SetBorderTexture
  373.     mt.SetBorderShadowTexture = SetBorderShadowTexture
  374.    
  375.     mt.SetBorderColor = ColorBorder
  376.     mt.SetBorderShadowColor = ColorBorderShadow
  377.    
  378.     mt.HideBorder = HideBorder
  379.     mt.ShowBorder = ShowBorder
  380.    
  381.     mt.GetBorder = GetBorder
  382.     mt.GetBorderInfo = GetBorderInfo
  383. end
  384.  
  385.  
  386. local handled = {
  387.     ['Frame'] = true
  388. }
  389.  
  390. local object = CreateFrame('Frame')
  391. addapi(object)
  392. addapi(object:CreateTexture())
  393. addapi(object:CreateFontString())
  394.  
  395. object = EnumerateFrames()
  396.  
  397. while object do
  398.     if (not handled[object:GetObjectType()]) then
  399.         addapi(object)
  400.         handled[object:GetObjectType()] = true
  401.     end
  402.  
  403.     object = EnumerateFrames(object)
  404. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement