Advertisement
Shuraken007

scrollbox

Dec 9th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. GMR.EditScrollBoxes = {}
  2. function GMR.CreateEditScrollBox(name, x, y, parent, width, height, point, rel_point, tooltip)
  3.     if not GMR.EditScrollBoxes[name] then
  4.         local frame = CreateFrame("EditBox", name.."EditScrollBox", parent)
  5.         frame:SetFontObject("ChatFontNormal")
  6.         frame:SetWidth(width)
  7.         frame:SetHeight(height)
  8.         frame:ClearAllPoints()
  9.         frame:SetPoint(point, invizible_button, rel_point, x, -y)
  10.         frame:SetAutoFocus(false)
  11.         frame:SetMaxLetters(500)
  12.         frame:SetMultiLine(true)
  13.         frame:EnableMouse()
  14.         --getglobal(name.."EditScrollBox".."Left"):SetHeight(height)
  15.         --getglobal(name.."EditScrollBox".."Right"):SetHeight(height)
  16.         --getglobal(name.."EditScrollBox".."Middle"):SetHeight(height)
  17.         frame:SetScript("OnTextChanged",
  18.             function()
  19.                 if ( not scrollFrame ) then
  20.                     scrollFrame = this:GetParent()
  21.                 end
  22.                 scrollFrame:UpdateScrollChildRect()
  23.             end
  24.         )
  25.         frame:SetScript("OnCursorChanged",
  26.             function()
  27.                 this.cursorOffset = arg2
  28.                 this.cursorHeight = arg4
  29.             end
  30.         )
  31.         frame:SetScript("OnUpdate",
  32.             function()
  33.                 if ( this.cursorOffset ) then
  34.                     if ( not scrollFrame ) then
  35.                         scrollFrame = this:GetParent();
  36.                     end
  37.                     local height = scrollFrame:GetHeight();
  38.                     local range = scrollFrame:GetVerticalScrollRange();
  39.                     local scroll = scrollFrame:GetVerticalScroll();
  40.                     local slider = GMR.ScrollBars[name.."V"]
  41.                     local size = height + range;
  42.                     local cursorOffset = -this.cursorOffset;
  43.                     while ( cursorOffset < scroll ) do
  44.                         scroll = (scroll - (height / 2));
  45.                         if ( scroll < 0 ) then
  46.                             scroll = 0;
  47.                         end
  48.                         scrollFrame:SetVerticalScroll(scroll);
  49.                     end
  50.                     while ( (cursorOffset + this.cursorHeight) > (scroll + height) and scroll < range ) do
  51.                         scroll = (scroll + (height / 2));
  52.                         if ( scroll > range ) then
  53.                             scroll = range;
  54.                         end
  55.                         scrollFrame:SetVerticalScroll(scroll)
  56.                     end
  57.                     local new_max = this:GetHeight()-scrollFrame:GetHeight()
  58.                     slider:SetMinMaxValues(0, max(0, new_max))
  59.                     slider:SetValue(scrollFrame:GetVerticalScroll())
  60.                     this.cursorOffset = nil;
  61.                 end
  62.             end
  63.         )
  64.         frame:SetScript("OnEscapePressed",
  65.             function()
  66.                 this:ClearFocus()
  67.             end
  68.         )
  69.         frame:SetScript("OnEditFocusLost",
  70.             function()
  71.                 this:HighlightText(0, 0)
  72.             end
  73.         )
  74.         frame:SetScript("OnEditFocusGained",
  75.             function()
  76.                 this:HighlightText()
  77.             end
  78.         )
  79.         local scrf = GMR.CreateScrollFrame(name, parent, frame, width, height, rel_point, point, x, y)
  80.  
  81.         local invizible_button = CreateFrame("Button", name.."EditScrollBoxButton", scrf)
  82.         invizible_button:SetAllPoints(scrf)
  83.         invizible_button:SetScript("OnClick",
  84.             function()
  85.                 frame:SetFocus()
  86.             end
  87.         )
  88.         if tooltip then
  89.             invizible_button:SetScript("OnEnter",
  90.                 function()
  91.                     GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
  92.                     if type(tooltip) == "table" then
  93.                         for i = 1, getn(tooltip) do
  94.                             GameTooltip:AddLine(tooltip[i]);
  95.                         end
  96.                     else
  97.                         GameTooltip:AddLine(tooltip);
  98.                     end
  99.                     GameTooltip:Show();
  100.                 end
  101.             )
  102.             invizible_button:SetScript("OnLeave",
  103.                 function()
  104.                     GameTooltip:Hide();
  105.                 end
  106.             )
  107.         end
  108.  
  109.  
  110.         GMR.EditScrollBoxes[name] = scrf
  111.     end
  112.     return GMR.EditScrollBoxes[name]
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement