local p="\078\101\120\117\115\083\099\114\111\108\108\105\110\103\070\114\097\109\101"local u=.5 local L=10 local i=(require(script.Parent.Parent.Parent:WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107\080\114\111\106\101\099\116"))):GetContext(script)local o=i:GetResource("\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local F=i:GetResource("\066\097\115\101\046\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101")local t=i:GetResource("\080\108\117\103\105\110\046\078\101\120\117\115\083\101\116\116\105\110\103\115")local C=i:GetResource("\085\073\046\083\099\114\111\108\108\046\078\101\120\117\115\083\099\114\111\108\108\066\097\114")local j=(i:GetResource("\068\097\116\097\046\069\110\117\109\046\078\101\120\117\115\069\110\117\109\067\111\108\108\101\099\116\105\111\110")).GetBuiltInEnums()local M=F:Extend()M:SetClassName(p)i:SetContextResource(M)function M.__new(L,u)L:InitializeSuper("\083\099\114\111\108\108\105\110\103\070\114\097\109\101")if not u then u=j.NexusScrollTheme.Native end if j.NexusScrollTheme.Native:Equals(u)then L:__InitializeNativeScrollingFrame()elseif j.NexusScrollTheme.Qt5:Equals(u)then L:__InitializeQt5ScrollingFrame()end L.Name=p L.BackgroundColor3="\077\097\105\110\066\097\099\107\103\114\111\117\110\100"L.BorderColor3="\066\111\114\100\101\114"L.ScrollColor3="\083\099\114\111\108\108\066\097\114"L.ScrollBackgroundColor3="\083\099\114\111\108\108\066\097\114\066\097\099\107\103\114\111\117\110\100"L.ScrollArrowColor3="\084\105\116\108\101\098\097\114\084\101\120\116"L:__SetChangedOverride("\083\099\114\111\108\108\066\097\114\066\117\116\116\111\110\073\110\099\114\101\109\101\110\116",function() end)L.ScrollBarButtonIncrement=16 end function M.__InitializeNativeScrollingFrame(p)p:__SetChangedOverride("\083\099\114\111\108\108\067\111\108\111\114\051",function()p.ScrollBarImageColor3=p.ScrollColor3 end)p:__SetChangedOverride("\083\099\114\111\108\108\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051",function() end)p:__SetChangedOverride("\083\099\114\111\108\108\065\114\114\111\119\067\111\108\111\114\051",function() end)p.BottomImage="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\083\116\117\100\105\111\084\111\111\108\098\111\120\047\083\099\114\111\108\108\066\097\114\066\111\116\116\111\109\046\112\110\103"p.MidImage="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\083\116\117\100\105\111\084\111\111\108\098\111\120\047\083\099\114\111\108\108\066\097\114\077\105\100\100\108\101\046\112\110\103"p.TopImage="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\083\116\117\100\105\111\084\111\111\108\098\111\120\047\083\099\114\111\108\108\066\097\114\084\111\112\046\112\110\103"p.ScrollBarThickness=8 end function M.__InitializeQt5ScrollingFrame(p)local u=F.GetInstance("\070\114\097\109\101")u.Name="\083\099\114\111\108\108\066\097\114\065\100\111\114\110"u.BackgroundTransparency=1 u.Hidden=true local function L(L)(p:GetPropertyChangedSignal(L)):Connect(function()u[L]=p[L]end)end L("\083\105\122\101")L("\080\111\115\105\116\105\111\110")L("\082\111\116\097\116\105\111\110")L("\080\097\114\101\110\116")local i=C.new(j.NexusScrollTheme.Qt5,Enum.Axis.X)i.Name="\072\111\114\105\122\111\110\116\097\108\083\099\114\111\108\108\066\097\114"i.Parent=u local o=C.new(j.NexusScrollTheme.Qt5,Enum.Axis.Y)o.Name="\086\101\114\116\105\099\097\108\083\099\114\111\108\108\066\097\114"o.Parent=u;(p:GetPropertyChangedSignal("\090\073\110\100\101\120")):Connect(function()u.ZIndex=p.ZIndex+1 i.ZIndex=p.ZIndex+1 o.ZIndex=p.ZIndex+1 end)u.ZIndex=p.ZIndex+1 i.ZIndex=p.ZIndex+1 o.ZIndex=p.ZIndex+1 local function t()local u=p.Parent if not u then return Vector2.new(0,0)end local L=p.CanvasSize local i=u.AbsoluteSize return Vector2.new(L.X.Scale*i.X+L.X.Offset,L.Y.Scale*i.Y+L.Y.Offset)end local function M()local u=p.AbsoluteWindowSize local L=t()local F=p.CanvasPosition i.RelativePosition=F.X/(L.X-u.X)o.RelativePosition=F.Y/(L.Y-u.Y)end;(p:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(M);(p:GetPropertyChangedSignal("\067\097\110\118\097\115\083\105\122\101")):Connect(M);(p:GetPropertyChangedSignal("\067\097\110\118\097\115\080\111\115\105\116\105\111\110")):Connect(M)i.Button1Pressed:Connect(function()local u=p.CanvasPosition local L=p.ScrollBarButtonIncrement p.CanvasPosition=Vector2.new(math.max(0,u.X-L),u.Y)end)i.Button2Pressed:Connect(function()local u=p.CanvasPosition local L=p.ScrollBarButtonIncrement local i=p.AbsoluteWindowSize local o=t()p.CanvasPosition=Vector2.new(math.min(u.X+L,o.X-i.X),u.Y)end)o.Button1Pressed:Connect(function()local u=p.CanvasPosition local L=p.ScrollBarButtonIncrement p.CanvasPosition=Vector2.new(u.X,math.max(0,u.Y-L,0))end)o.Button2Pressed:Connect(function()local u=p.CanvasPosition local L=p.ScrollBarButtonIncrement local i=p.AbsoluteWindowSize local o=t()p.CanvasPosition=Vector2.new(u.X,math.min(u.Y+L,o.Y-i.Y))end)local function f()local u,L=p.AbsoluteSize,t()local F=p.ScrollBarThickness local C,j=L.X>u.X,L.Y>u.Y local M=p.BorderSizePixel i.Visible=C i.RelativeSize=L.X/u.X o.Visible=j o.RelativeSize=L.Y/u.Y if p.VerticalScrollBarPosition=="\076\101\102\116"or p.VerticalScrollBarPosition==Enum.VerticalScrollBarPosition.Left then i.AnchorPoint=Vector2.new(1,1)i.Position=UDim2.new(1,-M,1,0)o.AnchorPoint=Vector2.new(0,0)o.Position=UDim2.new(0,0,0,M)else i.AnchorPoint=Vector2.new(0,1)i.Position=UDim2.new(0,M,1,0)o.AnchorPoint=Vector2.new(1,0)o.Position=UDim2.new(1,0,0,M)end if C and not j then i.Size=UDim2.new(1,-(2*M),0,F)elseif not C and j then o.Size=UDim2.new(0,F,1,-(2*M))else i.Size=UDim2.new(1,-F-2*M,0,F)o.Size=UDim2.new(0,F,1,-F-2*M)end end;(p:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(f);(p:GetPropertyChangedSignal("\067\097\110\118\097\115\083\105\122\101")):Connect(f);(p:GetPropertyChangedSignal("\083\099\114\111\108\108\066\097\114\084\104\105\099\107\110\101\115\115")):Connect(f);(p:GetPropertyChangedSignal("\086\101\114\116\105\099\097\108\083\099\114\111\108\108\066\097\114\080\111\115\105\116\105\111\110")):Connect(f)p:__SetChangedOverride("\083\099\114\111\108\108\067\111\108\111\114\051",function()i.ScrollColor3=p.ScrollColor3 o.ScrollColor3=p.ScrollColor3 end)p:__SetChangedOverride("\083\099\114\111\108\108\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051",function()i.BackgroundColor3=p.ScrollBackgroundColor3 o.BackgroundColor3=p.ScrollBackgroundColor3 end)p:__SetChangedOverride("\083\099\114\111\108\108\065\114\114\111\119\067\111\108\111\114\051",function()i.ScrollArrowColor3=p.ScrollArrowColor3 o.ScrollArrowColor3=p.ScrollArrowColor3 end)p.BottomImage=""p.MidImage=""p.TopImage=""p.ScrollBarThickness=16 end return M
--[[
TheNexusAvenger

Frame that allows for scrolling. Can have one of multiple themes.
--]]

local CLASS_NAME = "NexusScrollingFrame"

local SCROLL_BUTTON_HOLD_TIME = 0.5
local SCROLL_BUTTON_HOLD_STEPS_PER_SECOND = 10



local NexusPluginFramework = require(script.Parent.Parent.Parent:WaitForChild("NexusPluginFrameworkProject")):GetContext(script)
local NexusObject = NexusPluginFramework:GetResource("NexusInstance.NexusObject")
local NexusWrappedInstance = NexusPluginFramework:GetResource("Base.NexusWrappedInstance")
local NexusSettings = NexusPluginFramework:GetResource("Plugin.NexusSettings")
local NexusScrollBar = NexusPluginFramework:GetResource("UI.Scroll.NexusScrollBar")
local NexusEnums = NexusPluginFramework:GetResource("Data.Enum.NexusEnumCollection").GetBuiltInEnums()

local NexusScrollingFrame = NexusWrappedInstance:Extend()
NexusScrollingFrame:SetClassName(CLASS_NAME)
NexusPluginFramework:SetContextResource(NexusScrollingFrame)



--[[
Creates a Nexus Scrolling Frame object.
--]]
function NexusScrollingFrame:__new(Theme)
	self:InitializeSuper("ScrollingFrame")
	
	--Modify the theme.
	if not Theme then
		Theme = NexusEnums.NexusScrollTheme.Native
	end
	
	--Initialize the super class.
	if NexusEnums.NexusScrollTheme.Native:Equals(Theme) then
		self:__InitializeNativeScrollingFrame()
	elseif NexusEnums.NexusScrollTheme.Qt5:Equals(Theme) then
		self:__InitializeQt5ScrollingFrame()
	end
	
	--Set the name.
	self.Name = CLASS_NAME
	
	--Set the colors.
	self.BackgroundColor3 = "MainBackground"
	self.BorderColor3 = "Border"
	self.ScrollColor3 = "ScrollBar"
	self.ScrollBackgroundColor3 = "ScrollBarBackground"
	self.ScrollArrowColor3 = "TitlebarText"
	self:__SetChangedOverride("ScrollBarButtonIncrement",function() end)
	self.ScrollBarButtonIncrement = 16
end

--[[
Initializes the scrolling frame as a native one.
--]]
function NexusScrollingFrame:__InitializeNativeScrollingFrame()
	--Set up the color change overrides.
	self:__SetChangedOverride("ScrollColor3",function()
		self.ScrollBarImageColor3 = self.ScrollColor3
	end)
	self:__SetChangedOverride("ScrollBackgroundColor3",function() end)
	self:__SetChangedOverride("ScrollArrowColor3",function() end)
	
	--Set the default properties.
	self.BottomImage = "rbxasset://textures/StudioToolbox/ScrollBarBottom.png"
	self.MidImage = "rbxasset://textures/StudioToolbox/ScrollBarMiddle.png"
	self.TopImage = "rbxasset://textures/StudioToolbox/ScrollBarTop.png"
	self.ScrollBarThickness = 8
end

--[[
Initializes the scrolling frame as a Qt5 one.
--]]
function NexusScrollingFrame:__InitializeQt5ScrollingFrame()
	--Create the adorn.
	local ScrollBarAdorn = NexusWrappedInstance.GetInstance("Frame")
	ScrollBarAdorn.Name = "ScrollBarAdorn"
	ScrollBarAdorn.BackgroundTransparency = 1
	ScrollBarAdorn.Hidden = true
	
	--[[
	Sets up changes to the scroll bar adorn from the frame.
	--]]
	local function MirrorChanges(PropertyName)
		self:GetPropertyChangedSignal(PropertyName):Connect(function()
			ScrollBarAdorn[PropertyName] = self[PropertyName]
		end)
	end
	MirrorChanges("Size")
	MirrorChanges("Position")
	MirrorChanges("Rotation")
	MirrorChanges("Parent")
	
	--Create the side scrollbars.
	local BottomScrollBar = NexusScrollBar.new(NexusEnums.NexusScrollTheme.Qt5,Enum.Axis.X)
	BottomScrollBar.Name = "HorizontalScrollBar"
	BottomScrollBar.Parent = ScrollBarAdorn
	local SideScrollBar = NexusScrollBar.new(NexusEnums.NexusScrollTheme.Qt5,Enum.Axis.Y)
	SideScrollBar.Name = "VerticalScrollBar"
	SideScrollBar.Parent = ScrollBarAdorn
	
	self:GetPropertyChangedSignal("ZIndex"):Connect(function()
		ScrollBarAdorn.ZIndex = self.ZIndex + 1
		BottomScrollBar.ZIndex = self.ZIndex + 1
		SideScrollBar.ZIndex = self.ZIndex + 1
	end)
	ScrollBarAdorn.ZIndex = self.ZIndex + 1
	BottomScrollBar.ZIndex = self.ZIndex + 1
	SideScrollBar.ZIndex = self.ZIndex + 1
	
	--Set up input for the scrollbars.
	--[[
	Returns the absolute size of the canvas.
	--]]
	local function GetAbsoluteCanvasSize()
		--Return 0,0 if there is no parent.
		local Parent = self.Parent
		if not Parent then
			return Vector2.new(0,0)
		end
		
		--Return the absolute size.
		local CanvasSize = self.CanvasSize
		local ParentAbsoluteSize = Parent.AbsoluteSize
		return Vector2.new((CanvasSize.X.Scale * ParentAbsoluteSize.X) + CanvasSize.X.Offset,(CanvasSize.Y.Scale * ParentAbsoluteSize.Y) + CanvasSize.Y.Offset)
	end
	
	--[[
	Updates the position of the scroll bar when the position changes.
	--]]
	local function UpdatePosition()
		local AbsoluteWindowSize = self.AbsoluteWindowSize
		local AbsoluteCanvasSize = GetAbsoluteCanvasSize()
		local ExistingCanvasPosition = self.CanvasPosition
		
		BottomScrollBar.RelativePosition = ExistingCanvasPosition.X / (AbsoluteCanvasSize.X - AbsoluteWindowSize.X)
		SideScrollBar.RelativePosition = ExistingCanvasPosition.Y / (AbsoluteCanvasSize.Y - AbsoluteWindowSize.Y)
	end
	self:GetPropertyChangedSignal("AbsoluteSize"):Connect(UpdatePosition)
	self:GetPropertyChangedSignal("CanvasSize"):Connect(UpdatePosition)
	self:GetPropertyChangedSignal("CanvasPosition"):Connect(UpdatePosition)
	
	--Set up button press events.
	BottomScrollBar.Button1Pressed:Connect(function()
		local ExistingCanvasPosition = self.CanvasPosition
		local ScrollBarButtonIncrement = self.ScrollBarButtonIncrement
		
		self.CanvasPosition = Vector2.new(math.max(0,ExistingCanvasPosition.X - ScrollBarButtonIncrement),ExistingCanvasPosition.Y)
	end)
	
	BottomScrollBar.Button2Pressed:Connect(function()
		local ExistingCanvasPosition = self.CanvasPosition
		local ScrollBarButtonIncrement = self.ScrollBarButtonIncrement
		local AbsoluteWindowSize = self.AbsoluteWindowSize
		local AbsoluteCanvasSize = GetAbsoluteCanvasSize()
		
		self.CanvasPosition = Vector2.new(math.min(ExistingCanvasPosition.X + ScrollBarButtonIncrement,AbsoluteCanvasSize.X - AbsoluteWindowSize.X),ExistingCanvasPosition.Y)
	end)
	
	SideScrollBar.Button1Pressed:Connect(function()
		local ExistingCanvasPosition = self.CanvasPosition
		local ScrollBarButtonIncrement = self.ScrollBarButtonIncrement
		
		self.CanvasPosition = Vector2.new(ExistingCanvasPosition.X,math.max(0,ExistingCanvasPosition.Y - ScrollBarButtonIncrement,0))
	end)
	
	SideScrollBar.Button2Pressed:Connect(function()
		local ExistingCanvasPosition = self.CanvasPosition
		local ScrollBarButtonIncrement = self.ScrollBarButtonIncrement
		local AbsoluteWindowSize = self.AbsoluteWindowSize
		local AbsoluteCanvasSize = GetAbsoluteCanvasSize()
		
		self.CanvasPosition = Vector2.new(ExistingCanvasPosition.X,math.min(ExistingCanvasPosition.Y + ScrollBarButtonIncrement,AbsoluteCanvasSize.Y - AbsoluteWindowSize.Y))
	end)
	
	--Set up resizing and enabling of scroll bars.
	local function Resize()
		local AbsoluteSize,CanvasAbsoluteSize = self.AbsoluteSize,GetAbsoluteCanvasSize()
		local ScrollBarThickness = self.ScrollBarThickness
		local ScrollBarXEnabled,ScrollBarYEnabled = CanvasAbsoluteSize.X > AbsoluteSize.X,CanvasAbsoluteSize.Y > AbsoluteSize.Y
		local BorderSizePixel = self.BorderSizePixel
		
		--Show or hide the scroll bars.
		BottomScrollBar.Visible = ScrollBarXEnabled
		BottomScrollBar.RelativeSize = CanvasAbsoluteSize.X/AbsoluteSize.X
		SideScrollBar.Visible = ScrollBarYEnabled
		SideScrollBar.RelativeSize = CanvasAbsoluteSize.Y/AbsoluteSize.Y
		
		--Move the vertical scroll bar.
		if self.VerticalScrollBarPosition == "Left" or self.VerticalScrollBarPosition == Enum.VerticalScrollBarPosition.Left then
			BottomScrollBar.AnchorPoint = Vector2.new(1,1)
			BottomScrollBar.Position = UDim2.new(1,-BorderSizePixel,1,0)
			SideScrollBar.AnchorPoint = Vector2.new(0,0)
			SideScrollBar.Position = UDim2.new(0,0,0,BorderSizePixel)
		else
			BottomScrollBar.AnchorPoint = Vector2.new(0,1)
			BottomScrollBar.Position = UDim2.new(0,BorderSizePixel,1,0)
			SideScrollBar.AnchorPoint = Vector2.new(1,0)
			SideScrollBar.Position = UDim2.new(1,0,0,BorderSizePixel)
		end
		
		--Resize the scroll bars.
		if ScrollBarXEnabled and not ScrollBarYEnabled then
			BottomScrollBar.Size = UDim2.new(1,-(2 * BorderSizePixel),0,ScrollBarThickness)
		elseif not ScrollBarXEnabled and ScrollBarYEnabled then
			SideScrollBar.Size = UDim2.new(0,ScrollBarThickness,1,-(2 * BorderSizePixel))
		else
			BottomScrollBar.Size = UDim2.new(1,-ScrollBarThickness - (2 * BorderSizePixel),0,ScrollBarThickness)
			SideScrollBar.Size = UDim2.new(0,ScrollBarThickness,1,-ScrollBarThickness - (2 * BorderSizePixel))
		end
	end
	self:GetPropertyChangedSignal("AbsoluteSize"):Connect(Resize)
	self:GetPropertyChangedSignal("CanvasSize"):Connect(Resize)
	self:GetPropertyChangedSignal("ScrollBarThickness"):Connect(Resize)
	self:GetPropertyChangedSignal("VerticalScrollBarPosition"):Connect(Resize)
	
	--Set up the color change overrides.
	self:__SetChangedOverride("ScrollColor3",function()
		BottomScrollBar.ScrollColor3 = self.ScrollColor3
		SideScrollBar.ScrollColor3 = self.ScrollColor3
	end)
	self:__SetChangedOverride("ScrollBackgroundColor3",function()
		BottomScrollBar.BackgroundColor3 = self.ScrollBackgroundColor3
		SideScrollBar.BackgroundColor3 = self.ScrollBackgroundColor3
	end)
	self:__SetChangedOverride("ScrollArrowColor3",function()
		BottomScrollBar.ScrollArrowColor3 = self.ScrollArrowColor3
		SideScrollBar.ScrollArrowColor3 = self.ScrollArrowColor3
	end)
	
	--Set the default properties.
	self.BottomImage = ""
	self.MidImage = ""
	self.TopImage = ""
	self.ScrollBarThickness = 16
end



return NexusScrollingFrame