Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function ScrollFrame_OnLoad(self)
- local Slider = self.Slider
- local Up = Slider.Up
- local Down = Slider.Down
- Up:Disable()
- Down:Disable()
- Slider:SetMinMaxValues(0, 0)
- Slider:SetValue(0)
- self.offset = 0
- if (self.scrollBarHideable) then
- Slider:Hide()
- Up:Hide()
- Down:Hide()
- else
- Up:Disable()
- Down:Disable()
- Up:Show()
- Down:Show()
- end
- if (self.noScrollThumb) then
- Slider.ThumbTexture:Hide()
- end
- end
- local function ScrollFrame_OnScrollRangeChanged(self, xrange, yrange)
- local Slider = self.Slider
- local Up = Slider.Up
- local Down = Slider.Down
- local ThumbTexture = Slider.ThumbTexture
- if (not yrange) then
- yrange = self:GetVerticalScrollRange()
- end
- local value = Slider:GetValue()
- if (value > yrange) then
- value = yrange
- end
- Slider:SetMinMaxValues(0, yrange)
- Slider:SetValue(value)
- if (math.floor(yrange) == 0) then
- if (self.SliderHideable) then
- Slider:Hide()
- Down:Hide()
- Up:Hide()
- ThumbTexture:Hide()
- else
- Down:Disable()
- Up:Disable()
- Down:Show()
- Up:Show()
- if (not self.noScrollThumb) then
- ThumbTexture:Show()
- end
- end
- else
- Down:Show()
- Up:Show()
- Slider:Show()
- if (not self.noScrollThumb) then
- ThumbTexture:Show()
- end
- if (yrange - value > 0.005) then
- Down:Enable()
- else
- Down:Disable()
- end
- end
- end
- local function ScrollFrame_OnVerticalScroll(self, offset)
- local Slider = self.Slider
- local Up = Slider.Up
- local Down = Slider.Down
- Slider:SetValue(offset)
- local minval, maxval = Slider:GetMinMaxValues()
- if (offset == 0) then
- Up:Disable()
- else
- Up:Enable()
- end
- if ((Slider:GetValue() - maxval) == 0) then
- Down:Disable()
- else
- Down:Enable()
- end
- end
- function ScrollFrame_OnMouseWheel(self, value) -- self, delta
- local Slider = self.Slider
- local scrollStep = Slider.scrollStep or Slider:GetHeight() / 2
- if (value > 0) then
- Slider:SetValue(Slider:GetValue() - scrollStep)
- else
- Slider:SetValue(Slider:GetValue() + scrollStep)
- end
- end
- function GOBuilder:CreateFrame2(name, width, height, movable, minimize, close, parent)
- local h = 16
- local Frame = CreateFrame("Frame", name, parent)
- Frame:SetToplevel(true)
- Frame:SetClampedToScreen(true)
- -- Enable dragging
- if (movable) then
- Frame:SetMovable(movable)
- Frame:EnableMouse(true)
- Frame:RegisterForDrag("LeftButton")
- Frame:SetScript("OnDragStart", Frame.StartMoving)
- Frame:SetScript("OnHide", Frame.StopMovingOrSizing)
- Frame:SetScript("OnDragStop", Frame.StopMovingOrSizing)
- end
- Frame.texture = Frame:CreateTexture()
- Frame.texture:SetAllPoints(Frame)
- Frame.texture:SetTexture(0.1, 0.1, 0.1, 0.9)
- local maxheight = 200
- Frame:SetSize(width, h)
- local ScrollFrame = CreateFrame("ScrollFrame", name and name.."_ScrollFrame" or nil, Frame)
- ScrollFrame:SetPoint("TOP", Frame, "BOTTOM", 0, 0)
- -- ScrollFrame:SetPoint("BOTTOMRIGHT", Frame, "BOTTOMRIGHT", 0, 0)
- ScrollFrame:SetSize(width, math.min(height+h, maxheight))
- ScrollFrame:EnableMouse(true)
- ScrollFrame:EnableMouseWheel(true)
- ScrollFrame.texture = ScrollFrame:CreateTexture()
- ScrollFrame.texture:SetAllPoints(ScrollFrame)
- -- ScrollFrame.texture:SetTexture(1, 1, 1, 0.9)
- ScrollFrame.scrollBarHideable = true
- local FauxFrame = CreateFrame("Frame", name and name.."_FauxFrame" or nil, Frame)
- FauxFrame:SetAllPoints(ScrollFrame)
- Frame.FauxFrame = FauxFrame
- local Slider = CreateFrame("Slider", ScrollFrame:GetName() and ScrollFrame:GetName().."_ScrollBar", ScrollFrame)
- Slider:EnableMouse(true)
- Slider:SetOrientation('VERTICAL')
- Slider:SetWidth(10)
- local buttonscale = Slider:GetWidth()
- Slider:SetPoint("TOPRIGHT", ScrollFrame, "TOPRIGHT", 0, -buttonscale)
- Slider:SetPoint("BOTTOMRIGHT", ScrollFrame, "BOTTOMRIGHT", 0, buttonscale)
- Slider.texture = Slider:CreateTexture()
- Slider.texture:SetTexture(0.1, 0.1, 0.1, 0.9)
- Slider.texture:SetAllPoints(Slider)
- Slider.ThumbTexture = Slider:CreateTexture(Slider:GetName() and Slider:GetName().."_ThumbTexture")
- Slider.ThumbTexture:SetTexture(0, 0.45, 0.78, 1) -- :SetTexture(0, 0, 0, 0.5)
- Slider:SetThumbTexture(Slider.ThumbTexture)
- Slider:SetScript("OnValueChanged", function(self, value) self:GetParent():SetVerticalScroll(value) end)
- Slider.scrollStep = 25 -- (height-h)
- ScrollFrame.Slider = Slider
- local Up = GOBuilder:CreateButton(Slider:GetName() and Slider:GetName().."_ScrollUpButton", Slider)
- Up:SetSize(buttonscale, buttonscale)
- --Up:SetText("UP")
- Up:SetPoint("BOTTOM", Slider, "TOP", 0, 0)
- local function OnUpClick(self)
- local parent = self:GetParent()
- local scrollStep = parent.scrollStep or (parent:GetHeight() / 2)
- parent:SetValue(parent:GetValue() - scrollStep)
- end
- Up:SetScript("OnClick", OnUpClick)
- Slider.Up = Up
- local Down = GOBuilder:CreateButton(Slider:GetName() and Slider:GetName().."ScrollDownButton", Slider)
- Down:SetSize(buttonscale, buttonscale)
- --Down:SetText("Down")
- Down:SetPoint("TOP", Slider, "BOTTOM", 0, 0)
- local function OnDownClick(self)
- local parent = self:GetParent()
- local scrollStep = parent.scrollStep or (parent:GetHeight() / 2)
- parent:SetValue(parent:GetValue() + scrollStep)
- end
- Down:SetScript("OnClick", OnDownClick)
- Slider.Down = Down
- ScrollFrame:SetScript("OnLoad", ScrollFrame_OnLoad)
- ScrollFrame:SetScript("OnScrollRangeChanged", ScrollFrame_OnScrollRangeChanged)
- ScrollFrame:SetScript("OnVerticalScroll", ScrollFrame_OnVerticalScroll)
- ScrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel)
- Frame.ScrollFrame = ScrollFrame
- local ScrollChild = CreateFrame("Frame", name and name.."_ScrollChild" or nil, ScrollFrame)
- if (height > ScrollFrame:GetHeight()) then
- ScrollChild:SetSize(width-Slider:GetWidth(), height)
- else
- ScrollChild:SetSize(width, height)
- end
- ScrollChild:EnableMouse(true)
- local testButton = GOBuilder:CreateButton(nil, ScrollChild)
- testButton:SetSize(25, 50)
- testButton:SetText("X")
- testButton:SetPoint("CENTER", ScrollChild, "CENTER", 0, 0)
- ScrollChild.texture = ScrollChild:CreateTexture()
- ScrollChild.texture:SetAllPoints(ScrollChild)
- ScrollChild.texture:SetTexture(0, 0, 0, 0.3)
- ScrollFrame.ScrollChild = ScrollChild
- ScrollFrame:SetScrollChild(ScrollChild)
- local Close = CreateFrame("Button", name and name.."_Close" or nil, Frame)
- Close:SetSize(h, h)
- Close:EnableMouse(true)
- Close:SetPoint("TOPRIGHT", Frame, "TOPRIGHT", 0, 0)
- local CloseFont = Close:CreateFontString()
- CloseFont:SetTextColor(1, 1, 1, 1)
- CloseFont:SetFont("Fonts\\ARIALN.TTF", 10)
- Close:SetFontString(CloseFont)
- Close:SetText("X")
- Close:SetScript("OnClick", function(self) Frame:Hide() end)
- Frame.Close = Close
- if (not close) then
- Close:Hide()
- end
- local function OnMinimize(self, button)
- if (Frame.Minimize:IsVisible()) then
- if (ScrollFrame:IsShown()) then
- ScrollFrame:Hide()
- FauxFrame:SetPoint("BOTTOM", Frame, "BOTTOM")
- else
- ScrollFrame:Show()
- FauxFrame:SetPoint("BOTTOM", ScrollFrame, "BOTTOM")
- end
- end
- end
- local Minimize = CreateFrame("Button", name and name.."_Minimize" or nil, Frame)
- Minimize:SetSize(h, h)
- Minimize:EnableMouse(true)
- Minimize:SetPoint("RIGHT", Close, "LEFT", 0, 0)
- local MinimizeFont = Minimize:CreateFontString()
- MinimizeFont:SetTextColor(1, 1, 1, 1)
- MinimizeFont:SetFont("Fonts\\ARIALN.TTF", 10)
- Minimize:SetFontString(MinimizeFont)
- Minimize:SetText("_")
- Minimize:SetScript("OnClick", OnMinimize)
- Frame.Minimize = Minimize
- if (not minimize) then
- Minimize:Hide()
- end
- local Label = CreateFrame("Button", name and name.."_Label" or nil, Frame)
- Label:SetHeight(h)
- Label:SetPoint("TOPRIGHT", Minimize, "TOPLEFT", 0, 0)
- Label:SetPoint("TOPLEFT", Frame, "TOPLEFT", 0, 0)
- Label:SetPushedTextOffset(0, 0)
- Label:EnableMouse(true)
- if (movable) then
- Label:RegisterForDrag("LeftButton")
- Label:SetScript("OnDragStart", function(self) Frame:StartMoving() end)
- Label:SetScript("OnHide", function(self) Frame:StopMovingOrSizing() end)
- Label:SetScript("OnDragStop", function(self) Frame:StopMovingOrSizing() end)
- end
- local LabelFont = Label:CreateFontString()
- LabelFont:SetTextColor(1, 1, 1, 1)
- LabelFont:SetFont("Fonts\\ARIALN.TTF", 10)
- Label:SetFontString(LabelFont)
- Label:SetText(name or "")
- Label:SetScript("OnDoubleClick", OnMinimize)
- Frame.Label = Label
- ScrollFrame_OnLoad(ScrollFrame)
- return Frame
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement