Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GMR.EditScrollBoxes = {}
- function GMR.CreateEditScrollBox(name, x, y, parent, width, height, point, rel_point, tooltip)
- if not GMR.EditScrollBoxes[name] then
- local frame = CreateFrame("EditBox", name.."EditScrollBox", parent)
- frame:SetFontObject("ChatFontNormal")
- frame:SetWidth(width)
- frame:SetHeight(height)
- frame:ClearAllPoints()
- frame:SetPoint(point, invizible_button, rel_point, x, -y)
- frame:SetAutoFocus(false)
- frame:SetMaxLetters(500)
- frame:SetMultiLine(true)
- frame:EnableMouse()
- --getglobal(name.."EditScrollBox".."Left"):SetHeight(height)
- --getglobal(name.."EditScrollBox".."Right"):SetHeight(height)
- --getglobal(name.."EditScrollBox".."Middle"):SetHeight(height)
- frame:SetScript("OnTextChanged",
- function()
- if ( not scrollFrame ) then
- scrollFrame = this:GetParent()
- end
- scrollFrame:UpdateScrollChildRect()
- end
- )
- frame:SetScript("OnCursorChanged",
- function()
- this.cursorOffset = arg2
- this.cursorHeight = arg4
- end
- )
- frame:SetScript("OnUpdate",
- function()
- if ( this.cursorOffset ) then
- if ( not scrollFrame ) then
- scrollFrame = this:GetParent();
- end
- local height = scrollFrame:GetHeight();
- local range = scrollFrame:GetVerticalScrollRange();
- local scroll = scrollFrame:GetVerticalScroll();
- local slider = GMR.ScrollBars[name.."V"]
- local size = height + range;
- local cursorOffset = -this.cursorOffset;
- while ( cursorOffset < scroll ) do
- scroll = (scroll - (height / 2));
- if ( scroll < 0 ) then
- scroll = 0;
- end
- scrollFrame:SetVerticalScroll(scroll);
- end
- while ( (cursorOffset + this.cursorHeight) > (scroll + height) and scroll < range ) do
- scroll = (scroll + (height / 2));
- if ( scroll > range ) then
- scroll = range;
- end
- scrollFrame:SetVerticalScroll(scroll)
- end
- local new_max = this:GetHeight()-scrollFrame:GetHeight()
- slider:SetMinMaxValues(0, max(0, new_max))
- slider:SetValue(scrollFrame:GetVerticalScroll())
- this.cursorOffset = nil;
- end
- end
- )
- frame:SetScript("OnEscapePressed",
- function()
- this:ClearFocus()
- end
- )
- frame:SetScript("OnEditFocusLost",
- function()
- this:HighlightText(0, 0)
- end
- )
- frame:SetScript("OnEditFocusGained",
- function()
- this:HighlightText()
- end
- )
- local scrf = GMR.CreateScrollFrame(name, parent, frame, width, height, rel_point, point, x, y)
- local invizible_button = CreateFrame("Button", name.."EditScrollBoxButton", scrf)
- invizible_button:SetAllPoints(scrf)
- invizible_button:SetScript("OnClick",
- function()
- frame:SetFocus()
- end
- )
- if tooltip then
- invizible_button:SetScript("OnEnter",
- function()
- GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
- if type(tooltip) == "table" then
- for i = 1, getn(tooltip) do
- GameTooltip:AddLine(tooltip[i]);
- end
- else
- GameTooltip:AddLine(tooltip);
- end
- GameTooltip:Show();
- end
- )
- invizible_button:SetScript("OnLeave",
- function()
- GameTooltip:Hide();
- end
- )
- end
- GMR.EditScrollBoxes[name] = scrf
- end
- return GMR.EditScrollBoxes[name]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement