Advertisement
Rochet2

scrollframe

Mar 25th, 2016
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.55 KB | None | 0 0
  1. local function ScrollFrame_OnLoad(self)
  2.     local Slider = self.Slider
  3.     local Up = Slider.Up
  4.     local Down = Slider.Down
  5.    
  6.     Up:Disable()
  7.     Down:Disable()
  8.     Slider:SetMinMaxValues(0, 0)
  9.     Slider:SetValue(0)
  10.     self.offset = 0
  11.    
  12.     if (self.scrollBarHideable) then
  13.         Slider:Hide()
  14.         Up:Hide()
  15.         Down:Hide()
  16.     else
  17.         Up:Disable()
  18.         Down:Disable()
  19.         Up:Show()
  20.         Down:Show()
  21.     end
  22.    
  23.     if (self.noScrollThumb) then
  24.         Slider.ThumbTexture:Hide()
  25.     end
  26. end
  27.  
  28. local function ScrollFrame_OnScrollRangeChanged(self, xrange, yrange)
  29.     local Slider = self.Slider
  30.     local Up = Slider.Up
  31.     local Down = Slider.Down
  32.     local ThumbTexture = Slider.ThumbTexture
  33.    
  34.     if (not yrange) then
  35.         yrange = self:GetVerticalScrollRange()
  36.     end
  37.    
  38.     local value = Slider:GetValue()
  39.     if (value > yrange) then
  40.         value = yrange
  41.     end
  42.    
  43.     Slider:SetMinMaxValues(0, yrange)
  44.     Slider:SetValue(value)
  45.    
  46.     if (math.floor(yrange) == 0) then
  47.         if (self.SliderHideable) then
  48.             Slider:Hide()
  49.             Down:Hide()
  50.             Up:Hide()
  51.             ThumbTexture:Hide()
  52.         else
  53.             Down:Disable()
  54.             Up:Disable()
  55.             Down:Show()
  56.             Up:Show()
  57.             if (not self.noScrollThumb) then
  58.                 ThumbTexture:Show()
  59.             end
  60.         end
  61.     else
  62.         Down:Show()
  63.         Up:Show()
  64.         Slider:Show()
  65.        
  66.         if (not self.noScrollThumb) then
  67.             ThumbTexture:Show()
  68.         end
  69.        
  70.         if (yrange - value > 0.005) then
  71.             Down:Enable()
  72.         else
  73.             Down:Disable()
  74.         end
  75.     end
  76. end
  77.  
  78. local function ScrollFrame_OnVerticalScroll(self, offset)
  79.     local Slider = self.Slider
  80.     local Up = Slider.Up
  81.     local Down = Slider.Down
  82.    
  83.     Slider:SetValue(offset)
  84.    
  85.     local minval, maxval = Slider:GetMinMaxValues()
  86.     if (offset == 0) then
  87.         Up:Disable()
  88.     else
  89.         Up:Enable()
  90.     end
  91.    
  92.     if ((Slider:GetValue() - maxval) == 0) then
  93.         Down:Disable()
  94.     else
  95.         Down:Enable()
  96.     end
  97. end
  98.  
  99. function ScrollFrame_OnMouseWheel(self, value) -- self, delta
  100.     local Slider = self.Slider
  101.     local scrollStep = Slider.scrollStep or Slider:GetHeight() / 2
  102.    
  103.     if (value > 0) then
  104.         Slider:SetValue(Slider:GetValue() - scrollStep)
  105.     else
  106.         Slider:SetValue(Slider:GetValue() + scrollStep)
  107.     end
  108. end
  109.            
  110. function GOBuilder:CreateFrame2(name, width, height, movable, minimize, close, parent)
  111.     local h = 16
  112.    
  113.     local Frame = CreateFrame("Frame", name, parent)
  114.     Frame:SetToplevel(true)
  115.     Frame:SetClampedToScreen(true)
  116.     -- Enable dragging
  117.     if (movable) then
  118.         Frame:SetMovable(movable)
  119.         Frame:EnableMouse(true)
  120.         Frame:RegisterForDrag("LeftButton")
  121.         Frame:SetScript("OnDragStart", Frame.StartMoving)
  122.         Frame:SetScript("OnHide", Frame.StopMovingOrSizing)
  123.         Frame:SetScript("OnDragStop", Frame.StopMovingOrSizing)
  124.     end
  125.    
  126.     Frame.texture = Frame:CreateTexture()
  127.     Frame.texture:SetAllPoints(Frame)
  128.     Frame.texture:SetTexture(0.1, 0.1, 0.1, 0.9)
  129.    
  130.     local maxheight = 200
  131.     Frame:SetSize(width, h)
  132.  
  133.     local ScrollFrame = CreateFrame("ScrollFrame", name and name.."_ScrollFrame" or nil, Frame)
  134.     ScrollFrame:SetPoint("TOP", Frame, "BOTTOM", 0, 0)
  135.     -- ScrollFrame:SetPoint("BOTTOMRIGHT", Frame, "BOTTOMRIGHT", 0, 0)
  136.     ScrollFrame:SetSize(width, math.min(height+h, maxheight))
  137.     ScrollFrame:EnableMouse(true)
  138.     ScrollFrame:EnableMouseWheel(true)
  139.    
  140.     ScrollFrame.texture = ScrollFrame:CreateTexture()
  141.     ScrollFrame.texture:SetAllPoints(ScrollFrame)
  142.     -- ScrollFrame.texture:SetTexture(1, 1, 1, 0.9)
  143.     ScrollFrame.scrollBarHideable = true
  144.    
  145.     local FauxFrame = CreateFrame("Frame", name and name.."_FauxFrame" or nil, Frame)
  146.     FauxFrame:SetAllPoints(ScrollFrame)
  147.     Frame.FauxFrame = FauxFrame
  148.    
  149.     local Slider = CreateFrame("Slider", ScrollFrame:GetName() and ScrollFrame:GetName().."_ScrollBar", ScrollFrame)
  150.     Slider:EnableMouse(true)
  151.     Slider:SetOrientation('VERTICAL')
  152.     Slider:SetWidth(10)
  153.    
  154.     local buttonscale = Slider:GetWidth()
  155.    
  156.     Slider:SetPoint("TOPRIGHT", ScrollFrame, "TOPRIGHT", 0, -buttonscale)
  157.     Slider:SetPoint("BOTTOMRIGHT", ScrollFrame, "BOTTOMRIGHT", 0, buttonscale)
  158.    
  159.     Slider.texture = Slider:CreateTexture()
  160.     Slider.texture:SetTexture(0.1, 0.1, 0.1, 0.9)
  161.     Slider.texture:SetAllPoints(Slider)
  162.    
  163.     Slider.ThumbTexture = Slider:CreateTexture(Slider:GetName() and Slider:GetName().."_ThumbTexture")
  164.     Slider.ThumbTexture:SetTexture(0, 0.45, 0.78, 1) -- :SetTexture(0, 0, 0, 0.5)
  165.     Slider:SetThumbTexture(Slider.ThumbTexture)
  166.     Slider:SetScript("OnValueChanged", function(self, value) self:GetParent():SetVerticalScroll(value) end)
  167.     Slider.scrollStep = 25 -- (height-h)
  168.    
  169.     ScrollFrame.Slider = Slider
  170.    
  171.     local Up = GOBuilder:CreateButton(Slider:GetName() and Slider:GetName().."_ScrollUpButton", Slider)
  172.     Up:SetSize(buttonscale, buttonscale)
  173.    
  174.     --Up:SetText("UP")
  175.     Up:SetPoint("BOTTOM", Slider, "TOP", 0, 0)
  176.    
  177.     local function OnUpClick(self)
  178.         local parent = self:GetParent()
  179.         local scrollStep = parent.scrollStep or (parent:GetHeight() / 2)
  180.         parent:SetValue(parent:GetValue() - scrollStep)
  181.     end
  182.     Up:SetScript("OnClick", OnUpClick)
  183.    
  184.     Slider.Up = Up
  185.    
  186.     local Down = GOBuilder:CreateButton(Slider:GetName() and Slider:GetName().."ScrollDownButton", Slider)
  187.     Down:SetSize(buttonscale, buttonscale)
  188.    
  189.     --Down:SetText("Down")
  190.     Down:SetPoint("TOP", Slider, "BOTTOM", 0, 0)
  191.    
  192.     local function OnDownClick(self)
  193.         local parent = self:GetParent()
  194.         local scrollStep = parent.scrollStep or (parent:GetHeight() / 2)
  195.         parent:SetValue(parent:GetValue() + scrollStep)
  196.     end
  197.     Down:SetScript("OnClick", OnDownClick)
  198.    
  199.     Slider.Down = Down
  200.  
  201.     ScrollFrame:SetScript("OnLoad", ScrollFrame_OnLoad)
  202.     ScrollFrame:SetScript("OnScrollRangeChanged", ScrollFrame_OnScrollRangeChanged)
  203.     ScrollFrame:SetScript("OnVerticalScroll", ScrollFrame_OnVerticalScroll)
  204.     ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel)
  205.  
  206.     Frame.ScrollFrame = ScrollFrame
  207.    
  208.     local ScrollChild = CreateFrame("Frame", name and name.."_ScrollChild" or nil, ScrollFrame)
  209.     if (height > ScrollFrame:GetHeight()) then
  210.         ScrollChild:SetSize(width-Slider:GetWidth(), height)
  211.     else
  212.         ScrollChild:SetSize(width, height)
  213.     end
  214.     ScrollChild:EnableMouse(true)
  215.    
  216.     local testButton = GOBuilder:CreateButton(nil, ScrollChild)
  217.     testButton:SetSize(25, 50)
  218.    
  219.     testButton:SetText("X")
  220.     testButton:SetPoint("CENTER", ScrollChild, "CENTER", 0, 0)
  221.    
  222.     ScrollChild.texture = ScrollChild:CreateTexture()
  223.     ScrollChild.texture:SetAllPoints(ScrollChild)
  224.     ScrollChild.texture:SetTexture(0, 0, 0, 0.3)
  225.    
  226.     ScrollFrame.ScrollChild = ScrollChild
  227.     ScrollFrame:SetScrollChild(ScrollChild)
  228.    
  229.     local Close = CreateFrame("Button", name and name.."_Close" or nil, Frame)
  230.     Close:SetSize(h, h)
  231.     Close:EnableMouse(true)
  232.     Close:SetPoint("TOPRIGHT", Frame, "TOPRIGHT", 0, 0)
  233.  
  234.     local CloseFont = Close:CreateFontString()
  235.     CloseFont:SetTextColor(1, 1, 1, 1)
  236.     CloseFont:SetFont("Fonts\\ARIALN.TTF", 10)
  237.     Close:SetFontString(CloseFont)
  238.    
  239.     Close:SetText("X")
  240.     Close:SetScript("OnClick", function(self) Frame:Hide() end)
  241.    
  242.     Frame.Close = Close
  243.    
  244.     if (not close) then
  245.         Close:Hide()
  246.     end
  247.    
  248.     local function OnMinimize(self, button)
  249.         if (Frame.Minimize:IsVisible()) then
  250.             if (ScrollFrame:IsShown()) then
  251.                 ScrollFrame:Hide()
  252.                 FauxFrame:SetPoint("BOTTOM", Frame, "BOTTOM")
  253.             else
  254.                 ScrollFrame:Show()
  255.                 FauxFrame:SetPoint("BOTTOM", ScrollFrame, "BOTTOM")
  256.             end
  257.         end
  258.     end
  259.    
  260.     local Minimize = CreateFrame("Button", name and name.."_Minimize" or nil, Frame)
  261.     Minimize:SetSize(h, h)
  262.     Minimize:EnableMouse(true)
  263.     Minimize:SetPoint("RIGHT", Close, "LEFT", 0, 0)
  264.  
  265.     local MinimizeFont = Minimize:CreateFontString()
  266.     MinimizeFont:SetTextColor(1, 1, 1, 1)
  267.     MinimizeFont:SetFont("Fonts\\ARIALN.TTF", 10)
  268.     Minimize:SetFontString(MinimizeFont)
  269.    
  270.     Minimize:SetText("_")
  271.     Minimize:SetScript("OnClick", OnMinimize)
  272.    
  273.     Frame.Minimize = Minimize
  274.    
  275.     if (not minimize) then
  276.         Minimize:Hide()
  277.     end
  278.    
  279.     local Label = CreateFrame("Button", name and name.."_Label" or nil, Frame)
  280.     Label:SetHeight(h)
  281.     Label:SetPoint("TOPRIGHT", Minimize, "TOPLEFT", 0, 0)
  282.     Label:SetPoint("TOPLEFT", Frame, "TOPLEFT", 0, 0)
  283.     Label:SetPushedTextOffset(0, 0)
  284.     Label:EnableMouse(true)
  285.     if (movable) then
  286.         Label:RegisterForDrag("LeftButton")
  287.         Label:SetScript("OnDragStart", function(self) Frame:StartMoving() end)
  288.         Label:SetScript("OnHide", function(self) Frame:StopMovingOrSizing() end)
  289.         Label:SetScript("OnDragStop", function(self) Frame:StopMovingOrSizing() end)
  290.     end
  291.  
  292.     local LabelFont = Label:CreateFontString()
  293.     LabelFont:SetTextColor(1, 1, 1, 1)
  294.     LabelFont:SetFont("Fonts\\ARIALN.TTF", 10)
  295.     Label:SetFontString(LabelFont)
  296.    
  297.     Label:SetText(name or "")
  298.     Label:SetScript("OnDoubleClick", OnMinimize)
  299.    
  300.     Frame.Label = Label
  301.    
  302.     ScrollFrame_OnLoad(ScrollFrame)
  303.    
  304.     return Frame
  305. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement