Advertisement
Guest User

Gui Helpers

a guest
May 5th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. function Warning(msg, func)
  2.     local delpnl = vgui.Create("DFrame")
  3.     delpnl:SetSize(150, 100)
  4.     delpnl:SetPos( (ScrW()/2) - 75, (ScrH()/2) - 50 )
  5.     delpnl:SetTitle(msg)
  6.     local yesbtn = vgui.Create("DButton", delpnl)
  7.     yesbtn:SetText("Yes")
  8.     yesbtn:SetSize(50, 25)
  9.     yesbtn:SetPos(25, 50)
  10.     yesbtn.DoClick = function(btn)
  11.         func()
  12.         delpnl:Close()
  13.     end
  14.     local nobtn = vgui.Create("DButton", delpnl)
  15.     nobtn:SetText("No")
  16.     nobtn:SetSize(50, 25)
  17.     nobtn:SetPos(75, 50)
  18.     nobtn.DoClick = function(btn)
  19.         delpnl:Close()
  20.     end
  21.     delpnl:MakePopup()
  22.     delpnl:ShowCloseButton( true )
  23.     delpnl:SetVisible( true )
  24. end
  25.  
  26. gui.OSOpenURL=gui.OpenURL
  27.  
  28.  
  29. local white = surface.GetTextureID("vgui/white")
  30.  
  31. function surface.DrawLineEx(x1,y1, x2,y2, w, skip_tex)
  32.     w = w or 1
  33.     if not skip_tex then surface.SetTexture(white) end
  34.    
  35.     local dx,dy = x1-x2, y1-y2
  36.     local ang = math.atan2(dx, dy)
  37.     local dst = math.sqrt((dx * dx) + (dy * dy))
  38.    
  39.     x1 = x1 - dx * 0.5
  40.     y1 = y1 - dy * 0.5
  41.    
  42.     surface.DrawTexturedRectRotated(x1, y1, w, dst, math.deg(ang))
  43. end
  44.  
  45. function surface.DrawCircleEx(x, y, rad, color, res, ...)
  46.     res = res or 16
  47.        
  48.     surface.SetDrawColor(color)
  49.    
  50.     local spacing = (res/rad) - 0.1
  51.    
  52.     for i = 0, res do
  53.         local i1 = ((i+0) / res) * math.pi * 2
  54.         local i2 = ((i+1 + spacing) / res) * math.pi * 2
  55.        
  56.         surface.DrawLineEx(
  57.             x + math.sin(i1) * rad,
  58.             y + math.cos(i1) * rad,
  59.            
  60.             x + math.sin(i2) * rad,
  61.             y + math.cos(i2) * rad,
  62.             ...
  63.         )
  64.     end
  65. end
  66.    
  67. do
  68.     local fonts = {}
  69.  
  70.     local function create_fonts(font, size, weight, blursize)
  71.         local main = "pretty_text_" .. size .. weight
  72.         local blur = "pretty_text_blur_" .. size .. weight
  73.            
  74.         surface.CreateFont(
  75.             main,
  76.             {
  77.                 font = font,
  78.                 size = size,
  79.                 weight = weight,
  80.                 antialias   = true,
  81.                 additive    = true,
  82.             }
  83.         )
  84.        
  85.         surface.CreateFont(
  86.             blur,
  87.             {
  88.                 font = font,
  89.                 size = size,
  90.                 weight = weight,
  91.                 antialias   = true,
  92.                 blursize = blursize,
  93.             }
  94.         )
  95.        
  96.         return
  97.         {
  98.             main = main,
  99.             blur = blur,
  100.         }
  101.     end
  102.  
  103.     def_color1 = Color(255, 255, 255, 255)
  104.     def_color2 = Color(0, 0, 0, 255)
  105.    
  106.     local surface_SetFont = surface.SetFont
  107.     local surface_SetTextColor = surface.SetTextColor
  108.     local surface_SetTextPos = surface.SetTextPos
  109.     local surface_DrawText = surface.DrawText
  110.  
  111.     function surface.DrawPrettyText(text, x, y, font, size, weight, blursize, color1, color2, x_align, y_align)
  112.         font = font or "Arial"
  113.         size = size or 14
  114.         weight = weight or 0
  115.         blursize = blursize or 1
  116.         color1 = color1 or def_color1
  117.         color2 = color2 or def_color2
  118.        
  119.         if not fonts[font] then fonts[font] = {} end
  120.         if not fonts[font][size] then fonts[font][size] = {} end
  121.         if not fonts[font][size][weight] then fonts[font][size][weight] = {} end
  122.         if not fonts[font][size][weight][blursize] then fonts[font][size][weight][blursize] = create_fonts(font, size, weight, blursize) end
  123.        
  124.         if x_align then
  125.             local w = surface.GetPrettyTextSize(text, font, size, weight, blursize)
  126.             x = x + (w * x_align)
  127.         end
  128.        
  129.         if y_align then
  130.             local _, h = surface.GetPrettyTextSize(text, font, size, weight, blursize)
  131.             y = y + (h * y_align)
  132.         end
  133.        
  134.         surface_SetFont(fonts[font][size][weight][blursize].blur)
  135.         surface_SetTextColor(color2)
  136.        
  137.         for i = 1, 5 do
  138.             surface_SetTextPos(x, y) -- this resets for some reason after drawing
  139.             surface_DrawText(text)
  140.         end
  141.  
  142.         surface_SetFont(fonts[font][size][weight][blursize].main)
  143.         surface_SetTextColor(color1)
  144.         surface_SetTextPos(x, y)
  145.         surface_DrawText(text)
  146.     end
  147.    
  148.     function surface.GetPrettyTextSize(text, font, size, weight, blursize)
  149.         font = font or "Arial"
  150.         size = size or 14
  151.         weight = weight or 0
  152.         blursize = blursize or 1
  153.    
  154.         if not fonts[font] then fonts[font] = {} end
  155.         if not fonts[font][size] then fonts[font][size] = {} end
  156.         if not fonts[font][size][weight] then fonts[font][size][weight] = {} end
  157.         if not fonts[font][size][weight][blursize] then fonts[font][size][weight][blursize] = create_fonts(font, size, weight, blursize) end
  158.        
  159.         surface.SetFont(fonts[font][size][weight][blursize].blur)
  160.         return surface.GetTextSize(text)
  161.     end
  162. end
  163.  
  164. local Panel=FindMetaTable"Panel"
  165. local CutX,CutY
  166. CutX = function (x,yes,rev)
  167.    
  168.     if rev then
  169.         render.SetScissorRect(x,0,ScrW(),ScrH(),yes)
  170.     else
  171.         render.SetScissorRect(0,0,x,ScrH(),yes)
  172.     end
  173.    
  174.    
  175. end
  176.  
  177. CutY = function (y,yes,rev)
  178.    
  179.     if rev then
  180.         render.SetScissorRect(0,y,ScrW(),ScrH(),yes)
  181.     else
  182.         render.SetScissorRect(0,0,ScrW(),y,yes)
  183.     end
  184.    
  185. end
  186.  
  187. render.CutX=CutX
  188. render.CutY=CutY
  189.  
  190. function Panel:CutX(pos,yes,rev)
  191.     local x,y=self:LocalToScreen(pos,0)
  192.     render.CutX(x,yes,rev)
  193. end
  194.  
  195. function Panel:CutY(pos,yes,rev)
  196.     local x,y=self:LocalToScreen(0,pos)
  197.     render.CutY(y,yes,rev)
  198. end
  199.  
  200. blur = Material("pp/blurscreen")
  201. function DrawBlur(panel, amount) --Panel blur function
  202.     local x, y = panel:LocalToScreen(0, 0)
  203.     local scrW, scrH = ScrW(), ScrH()
  204.     surface.SetDrawColor(255, 255, 255)
  205.     surface.SetMaterial(blur)
  206.     for i = 1, 6 do
  207.         blur:SetFloat("$blur", (i / 3) * (amount or 6))
  208.         blur:Recompute()
  209.         render.UpdateScreenEffectTexture()
  210.         surface.DrawTexturedRect(x * -1, y * -1, scrW, scrH)
  211.     end
  212. end
  213.  
  214. function drawRectOutline( x, y, w, h, color )
  215.     surface.SetDrawColor( color )
  216.     surface.DrawOutlinedRect( x, y, w, h )
  217. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement