local w=game:GetService("\082\117\110\083\101\114\118\105\099\101")local z={}function z.PointInBounds(w,z,g)local H=w.AbsolutePosition.Y local C=w.AbsolutePosition.Y+w.AbsoluteSize.Y local x=w.AbsolutePosition.X local Q=w.AbsolutePosition.X+w.AbsoluteSize.X if g>H and(g<C and(z>x and z<Q))then return true else return false end end function z.MouseOver(w,g)return z.PointInBounds(g,w.X,w.Y)end local function g(z)local g=0 local H=-1 local function C(C)local x=g+1 g=x H=tick()return function()H=tick()if z()or g~=x then w:UnbindFromRenderStep(C)if g==x then H=-1 end end end end local function x()return tick()-H end local function Q()return H==-1 or x()>.1 end local function h()local g="\084\119\101\101\110\084\114\097\110\115\112\097\114\101\110\099\121\079\110\071\117\105\115"..(tostring(z)..tick())w:BindToRenderStep(g,2000,C(g))end return function()if Q()then h()end end end local function H(w)local z={}local function H(w,z,g)local H={}local C={}for z,g in pairs(z)do if w[z]~=g then H[z]=w[z]C[z]=g end end return{StartTime=tick(),Duration=g;StartProperties=H;NewProperties=C}end local C=g(function()local g=tick()local H=true for C,x in next,z do if C:IsDescendantOf(game)then local Q=g-x.StartTime if Q>x.Duration then w(C,1,x.StartProperties,x.NewProperties)z[C]=nil else w(C,Q/x.Duration,x.StartProperties,x.NewProperties)H=false end else z[C]=nil end end return H end)return function(g,x,Q)if Q<=0 then w(g,1,x,x)else z[g]=H(g,x,Q)C()end end,function(w)z[w]=nil end end local C,x=H(function(w,z,g,H)for H,C in next,H do local x=g[H]w[H]=x+(C-x)*z end end)z.TweenTransparency=C z.StopTransparencyTween=x local Q,h do local function w(w,z,g)return w+(z-w)*g end local function z(z,g,H)return Color3.new(w(z.r,g.r,H),w(z.g,g.g,H),w(z.b,g.b,H))end Q,h=H(function(w,g,H,C)for C,x in next,C do local Q=H[C]w[C]=z(Q,x,g)end end)end z.TweenColor3=Q z.StopColor3Tween=h local function V(w,z,g)g=g or"\070\114\097\109\101"local H=Instance.new(g)H.Archivable=false H.BackgroundColor3=w.BackgroundColor3 H.BorderSizePixel=0 H.Name="\084\111\112\076\101\102\116"H.Position=UDim2.new(0,0,0,0)H.Size=UDim2.new(0,z,0,z)H.BackgroundTransparency=1 H.ZIndex=w.ZIndex H.Parent=w local C=Instance.new(g)C.Archivable=false C.BackgroundColor3=w.BackgroundColor3 C.BorderSizePixel=0 C.Name="\066\111\116\116\111\109\076\101\102\116"C.Position=UDim2.new(0,0,1,-z)C.Size=UDim2.new(0,z,0,z)C.BackgroundTransparency=1 C.ZIndex=w.ZIndex C.Parent=w local x=Instance.new(g)x.Archivable=false x.BackgroundColor3=w.BackgroundColor3 x.BorderSizePixel=0 x.Name="\084\111\112\082\105\103\104\116"x.Position=UDim2.new(1,-z,0,0)x.Size=UDim2.new(0,z,0,z)x.BackgroundTransparency=1 x.ZIndex=w.ZIndex x.Parent=w local Q=Instance.new(g)Q.Archivable=false Q.BackgroundColor3=w.BackgroundColor3 Q.BorderSizePixel=0 Q.Name="\066\111\116\116\111\109\082\105\103\104\116"Q.Position=UDim2.new(1,-z,1,-z)Q.Size=UDim2.new(0,z,0,z)Q.BackgroundTransparency=1 Q.ZIndex=w.ZIndex Q.Parent=w local h=Instance.new(g)h.Archivable=false h.BackgroundColor3=w.BackgroundColor3 h.BorderSizePixel=0 h.Name="\077\105\100\100\108\101"h.Position=UDim2.new(0,z,0,0)h.Size=UDim2.new(1,-z*2,1,0)h.BackgroundTransparency=1 h.ZIndex=w.ZIndex h.Parent=w local V=Instance.new(g)V.Archivable=false V.BackgroundColor3=w.BackgroundColor3 V.BorderSizePixel=0 V.Name="\077\105\100\100\108\101\076\101\102\116"V.Position=UDim2.new(0,0,0,z)V.Size=UDim2.new(0,z,1,-z*2)V.BackgroundTransparency=1 V.ZIndex=w.ZIndex V.Parent=w local q=Instance.new(g)q.Archivable=false q.BackgroundColor3=w.BackgroundColor3 q.BorderSizePixel=0 q.Name="\077\105\100\100\108\101\082\105\103\104\116"q.Position=UDim2.new(1,-z,0,z)q.Size=UDim2.new(0,z,1,-z*2)q.BackgroundTransparency=1 q.ZIndex=w.ZIndex q.Parent=w return H,x,C,Q,h,V,q end z.AddTexturedWindowTemplate=V local function q(w,z,g,H,C,x)x=x or{}C=C or"\073\109\097\103\101\076\097\098\101\108"local Q,h,q,N,f,S,P=V(w,H,C)f.Size=UDim2.new(1,-H*2,1,-H*2)f.Position=UDim2.new(0,H,0,H)local i=Instance.new(C)i.Archivable=false i.BackgroundColor3=w.BackgroundColor3 i.BorderSizePixel=0 i.Name="\077\105\100\100\108\101\084\111\112"i.Position=UDim2.new(0,H,0,0)i.Size=UDim2.new(1,-H*2,0,H)i.BackgroundTransparency=1 i.ZIndex=w.ZIndex i.Parent=w local Y=Instance.new(C)Y.Archivable=false Y.BackgroundColor3=w.BackgroundColor3 Y.BorderSizePixel=0 Y.Name="\077\105\100\100\108\101\066\111\116\116\111\109"Y.Position=UDim2.new(0,H,1,-H)Y.Size=UDim2.new(1,-H*2,0,H)Y.BackgroundTransparency=1 Y.ZIndex=w.ZIndex Y.Parent=w for w,H in pairs({Q,h;q,N;f;S;P;i,Y})do for w,z in pairs(x)do H[w]=z end H.Image=z H.ImageRectSize=Vector2.new(g.X/3,g.Y/3)end h.ImageRectOffset=Vector2.new(g.X*.66666666666667,0)P.ImageRectOffset=Vector2.new(g.X*.66666666666667,g.Y/3)N.ImageRectOffset=Vector2.new(g.X*.66666666666667,g.Y*.66666666666667)S.ImageRectOffset=Vector2.new(0,g.Y/3)q.ImageRectOffset=Vector2.new(0,g.Y*.66666666666667)f.ImageRectOffset=Vector2.new(g.X/3,g.Y/3)i.ImageRectOffset=Vector2.new(g.Y/3,0)Y.ImageRectOffset=Vector2.new(g.Y/3,g.Y*.66666666666667)return Q,h,q,N,f,S,P,i,Y end z.AddNinePatch=q local function N(w,z,g)g=g or Color3.new(1,1,1)return q(w,"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\054\054\056\056\052\049\050",Vector2.new(150,150),z,"\073\109\097\103\101\076\097\098\101\108",{ImageColor3=g})end z.BackWithRoundedRectangle=N return z
--- A group of utility functions to be used to help create visual effectcs with ROBLOX GUIs
-- @classmod qGui

local RunService = game:GetService("RunService")

local lib = {}

function lib.PointInBounds(Frame, X, Y)
	local TopBound = Frame.AbsolutePosition.Y
	local BottomBound = Frame.AbsolutePosition.Y + Frame.AbsoluteSize.Y
	local LeftBound = Frame.AbsolutePosition.X
	local RightBound = Frame.AbsolutePosition.X + Frame.AbsoluteSize.X

	if Y > TopBound and Y < BottomBound and X > LeftBound and X < RightBound then
		return true
	else
		return false
	end
end

function lib.MouseOver(Mouse, Frame)
	return lib.PointInBounds(Frame, Mouse.X, Mouse.Y)
end

-- @param UpdateFunction()
-- @return ShouldStop, if true, will stop updating
-- @return StartUpdate()
local function CreateYieldedUpdate(UpdateFunction)
	local AnimationId = 0
	local LastUpdatePoint = -1 -- If it's -1, no active thread.

	--- Increments the AnimationId and returns a new UpdateFunction
	-- to be bound into RenderStep
	local function GetNewUpdateFunction(RenderStepKey)

		local LocalAnimationId = AnimationId + 1
		AnimationId = LocalAnimationId

		-- Note that we're now updating.
		LastUpdatePoint = tick()

		--- Intended to be called each RenderStep. Will unbind itself if the UpdateFunction fails
		-- or a new update function is generated
		return function()
			LastUpdatePoint = tick()

			if UpdateFunction() or (AnimationId ~= LocalAnimationId) then
				RunService:UnbindFromRenderStep(RenderStepKey)

				if AnimationId == LocalAnimationId then
					LastUpdatePoint = -1
				end
			end
		end
	end

	--- Calculates the time since the last update function was called
	-- Used to determine if a new update function should be generated, since clients tend to
	-- kill threads when local scripts are GCed
	local function TimeSinceUpdate()

		return tick() - LastUpdatePoint
	end

	local function ShouldStartUpdate()
		return LastUpdatePoint == -1 -- In this case, we have no active threads
			or TimeSinceUpdate() > 0.1 -- In this case, our presumed active thread is dead.
	end

	--- Starts an update thread, potentialy removing the old one.
	local function StartNewThread()
		local RenderStepKey = "TweenTransparencyOnGuis" .. tostring(UpdateFunction) .. tick()
		RunService:BindToRenderStep(RenderStepKey, 2000, GetNewUpdateFunction(RenderStepKey))
	end

	--- Starts the tween
	return function()
		if ShouldStartUpdate() then
			StartNewThread()
		end
	end
end

--- Creates a tweener that only runs when it's updating with a set properties system.
-- @param function `SetProperties`
	-- SetProperties(Gui, Percent, StartProperties, NewProperties)
		-- @param Gui The Gui to set properties on
		-- @param Percent Number [0, 1] of properties to set
		-- @param StartProperties The properties we started with
		-- @param NewProperties The properties we ended with
-- @return
local function MakePropertyTweener(SetProperties)
	local GuiMap = {} -- [Gui] = TweenData

	local function GetTweenData(Gui, NewProperties, Duration)
		-- Returns new tween data for the GUI in question

		local StartProperties = {}
		local EndProperties = {}

		-- Copy data into the table
		for Index, Value in pairs(NewProperties) do
			if Gui[Index] ~= Value then
				StartProperties[Index] = Gui[Index]
				EndProperties[Index] = Value
			end
		end

		return {
			StartTime       = tick();
			Duration        = Duration;
			StartProperties = StartProperties;
			NewProperties   = EndProperties;
		}
	end

	local StartRenderStepUpdater = CreateYieldedUpdate(function()
		-- Update function that will be called each second

		local tick = tick()
		local ShouldStop = true

		for Gui, TweenState in next, GuiMap do
			if Gui:IsDescendantOf(game) then
				local TimeElapsed = tick - TweenState.StartTime

				if TimeElapsed > TweenState.Duration then -- Then we end it.
					SetProperties(Gui, 1, TweenState.StartProperties, TweenState.NewProperties)
					GuiMap[Gui] = nil
				else
					SetProperties(Gui, TimeElapsed/TweenState.Duration, TweenState.StartProperties, TweenState.NewProperties)
					ShouldStop = false
				end
			else
				GuiMap[Gui] = nil
			end
		end

		return ShouldStop
	end)

	--- A tweening function to begin tweening on a Gui element
	-- @param Gui The GUI to tween the Transparency's upon
	-- @param NewProperties The properties to be changed. It will take the current
	--                      properties and tween to the new ones. This table should be
	--                      setup so {Index = NewValue} that is, for example,
	--                      {TextTransparency = 1}.
	-- @param Duration The amount of time to spend transitioning.
	return function(Gui, NewProperties, Duration)

		if Duration <= 0 then
			SetProperties(Gui, 1, NewProperties, NewProperties)
		else
			GuiMap[Gui] = GetTweenData(Gui, NewProperties, Duration)
			StartRenderStepUpdater()
		end

	-- A tweening function to manually terminate tweening on a Gui element
	-- @param Gui The GUI to stop tweening
	end, function(Gui)
		GuiMap[Gui] = nil
	end
end

-- TweenTransparency(Gui, NewProperties, Time)
--- Tween's the Transparency values in a GUI,
-- @param Gui The GUI to tween the Transparency's upon
-- @param NewProperties The properties to be changed. It will take the current
--                      properties and tween to the new ones. This table should be
--                      setup so {Index = NewValue} that is, for example,
--                      {TextTransparency = 1}.
-- @param Time The amount of time to spend transitioning.
local TweenTransparency, StopTransparencyTween = MakePropertyTweener(function(Gui, Percent, StartProperties, NewProperties)
	for Index, EndValue in next, NewProperties do
		local StartProperty = StartProperties[Index]
		Gui[Index] = StartProperty + (EndValue - StartProperty) * Percent
	end
end)

lib.TweenTransparency = TweenTransparency
lib.StopTransparencyTween = StopTransparencyTween


--- TweenColor3(Gui, NewProperties, Time)
--- Tween's the Color3 values in a GUI,
-- @param Gui The GUI to tween the Color3's upon
-- @param NewProperties The properties to be changed. It will take the current
--                      properties and tween to the new ones. This table should be
--                      setup so {Index = NewValue} that is, for example,
--                      {BackgroundColor3 = Color3.new(1, 1, 1)}.
-- @param Duration The amount of time to spend transitioning.
local TweenColor3, StopColor3Tween do
	local function LerpNumber(ValueOne, ValueTwo, Alpha)
		return ValueOne + ((ValueTwo - ValueOne) * Alpha)
	end

	local function LerpColor3(ColorOne, ColorTwo, Alpha)
		return Color3.new(LerpNumber(ColorOne.r, ColorTwo.r, Alpha), LerpNumber(ColorOne.g, ColorTwo.g, Alpha), LerpNumber(ColorOne.b, ColorTwo.b, Alpha))
	end

	TweenColor3, StopColor3Tween = MakePropertyTweener(function(Gui, Percent, StartProperties, NewProperties)
		for Index, EndValue in next, NewProperties do
			local StartProperty = StartProperties[Index]
			Gui[Index] = LerpColor3(StartProperty, EndValue, Percent)
		end
	end)
end

lib.TweenColor3 = TweenColor3
lib.StopColor3Tween = StopColor3Tween

--- Makes a 'Textured' window...  9Scale thingy?
local function AddTexturedWindowTemplate(Frame, Radius, Type)
	Type = Type or 'Frame'

	local TopLeft = Instance.new(Type)
	TopLeft.Archivable = false
	TopLeft.BackgroundColor3 = Frame.BackgroundColor3
	TopLeft.BorderSizePixel = 0
	TopLeft.Name = "TopLeft"
	TopLeft.Position = UDim2.new(0, 0, 0, 0)
	TopLeft.Size = UDim2.new(0, Radius, 0, Radius)
	TopLeft.BackgroundTransparency = 1
	TopLeft.ZIndex = Frame.ZIndex
	TopLeft.Parent = Frame

	local BottomLeft = Instance.new(Type)
	BottomLeft.Archivable = false
	BottomLeft.BackgroundColor3 = Frame.BackgroundColor3
	BottomLeft.BorderSizePixel = 0
	BottomLeft.Name = "BottomLeft"
	BottomLeft.Position = UDim2.new(0, 0, 1, -Radius)
	BottomLeft.Size = UDim2.new(0, Radius, 0, Radius)
	BottomLeft.BackgroundTransparency = 1
	BottomLeft.ZIndex = Frame.ZIndex
	BottomLeft.Parent = Frame

	local TopRight = Instance.new(Type)
	TopRight.Archivable = false
	TopRight.BackgroundColor3 = Frame.BackgroundColor3
	TopRight.BorderSizePixel = 0
	TopRight.Name = "TopRight"
	TopRight.Position = UDim2.new(1, -Radius, 0, 0)
	TopRight.Size = UDim2.new(0, Radius, 0, Radius)
	TopRight.BackgroundTransparency = 1
	TopRight.ZIndex = Frame.ZIndex
	TopRight.Parent = Frame

	local BottomRight = Instance.new(Type)
	BottomRight.Archivable = false
	BottomRight.BackgroundColor3 = Frame.BackgroundColor3
	BottomRight.BorderSizePixel = 0
	BottomRight.Name = "BottomRight"
	BottomRight.Position = UDim2.new(1, -Radius, 1, -Radius)
	BottomRight.Size = UDim2.new(0, Radius, 0, Radius)
	BottomRight.BackgroundTransparency = 1
	BottomRight.ZIndex = Frame.ZIndex
	BottomRight.Parent = Frame

	local Middle = Instance.new(Type)
	Middle.Archivable = false
	Middle.BackgroundColor3 = Frame.BackgroundColor3
	Middle.BorderSizePixel = 0
	Middle.Name = "Middle"
	Middle.Position = UDim2.new(0, Radius, 0, 0)
	Middle.Size = UDim2.new(1, -Radius*2, 1, 0)
	Middle.BackgroundTransparency = 1
	Middle.ZIndex = Frame.ZIndex
	Middle.Parent = Frame

	local MiddleLeft = Instance.new(Type)
	MiddleLeft.Archivable = false
	MiddleLeft.BackgroundColor3 = Frame.BackgroundColor3
	MiddleLeft.BorderSizePixel = 0
	MiddleLeft.Name = "MiddleLeft"
	MiddleLeft.Position = UDim2.new(0, 0, 0, Radius)
	MiddleLeft.Size = UDim2.new(0, Radius, 1, -Radius*2)
	MiddleLeft.BackgroundTransparency = 1
	MiddleLeft.ZIndex = Frame.ZIndex
	MiddleLeft.Parent = Frame

	local MiddleRight = Instance.new(Type)
	MiddleRight.Archivable = false
	MiddleRight.BackgroundColor3 = Frame.BackgroundColor3
	MiddleRight.BorderSizePixel = 0
	MiddleRight.Name = "MiddleRight"
	MiddleRight.Position = UDim2.new(1, -Radius, 0, Radius)
	MiddleRight.Size = UDim2.new(0, Radius, 1, -Radius*2)
	MiddleRight.BackgroundTransparency = 1
	MiddleRight.ZIndex = Frame.ZIndex
	MiddleRight.Parent = Frame

	return TopLeft, TopRight, BottomLeft, BottomRight, Middle, MiddleLeft, MiddleRight
end
lib.AddTexturedWindowTemplate = AddTexturedWindowTemplate

--- Makes a NinePatch in the frame, with the image.
-- @param Frame The frame to texturize
-- @param Radius the radius you want the image to be at
-- @param Type The type (Class) that the frame should be, either an ImageLabel or an ImageButton
-- @param Image The URL of the image in question
-- @param ImageSize The size of the image overall, suggested to be 99/divisible by 3. Vector2 value.
local function AddNinePatch(Frame, Image, ImageSize, Radius, Type, Properties)
	Properties = Properties or {}
	Type = Type or "ImageLabel"
	local TopLeft, TopRight, BottomLeft, BottomRight, Middle, MiddleLeft, MiddleRight = AddTexturedWindowTemplate(Frame, Radius, Type)

	Middle.Size = UDim2.new(1, -Radius*2, 1, -Radius*2) -- Fix middle...
	Middle.Position = UDim2.new(0, Radius, 0, Radius)

	local MiddleTop = Instance.new(Type)
	MiddleTop.Archivable = false
	MiddleTop.BackgroundColor3 = Frame.BackgroundColor3
	MiddleTop.BorderSizePixel = 0
	MiddleTop.Name = "MiddleTop"
	MiddleTop.Position = UDim2.new(0, Radius, 0, 0)
	MiddleTop.Size = UDim2.new(1, -Radius*2, 0, Radius)
	MiddleTop.BackgroundTransparency = 1
	MiddleTop.ZIndex = Frame.ZIndex
	MiddleTop.Parent = Frame

	local MiddleBottom = Instance.new(Type)
	MiddleBottom.Archivable = false
	MiddleBottom.BackgroundColor3 = Frame.BackgroundColor3
	MiddleBottom.BorderSizePixel = 0
	MiddleBottom.Name = "MiddleBottom"
	MiddleBottom.Position = UDim2.new(0, Radius, 1, -Radius)
	MiddleBottom.Size = UDim2.new(1, -Radius*2, 0, Radius)
	MiddleBottom.BackgroundTransparency = 1
	MiddleBottom.ZIndex = Frame.ZIndex
	MiddleBottom.Parent = Frame

	for _, Item in pairs({TopLeft, TopRight, BottomLeft, BottomRight, Middle, MiddleLeft, MiddleRight, MiddleTop, MiddleBottom}) do
		for Property, Value in pairs(Properties) do
			Item[Property] = Value
		end
		Item.Image = Image
		Item.ImageRectSize = Vector2.new(ImageSize.X/3, ImageSize.Y/3)
	end

	TopRight.ImageRectOffset = Vector2.new(ImageSize.X * (2/3), 0)
	MiddleRight.ImageRectOffset = Vector2.new(ImageSize.X * (2/3), ImageSize.Y/3)
	BottomRight.ImageRectOffset = Vector2.new(ImageSize.X * (2/3), ImageSize.Y * (2/3))

	--TopLeft.ImageRectOffset = Vector2.new(0, 0)
	MiddleLeft.ImageRectOffset = Vector2.new(0, ImageSize.Y/3)
	BottomLeft.ImageRectOffset = Vector2.new(0, ImageSize.Y * (2/3))

	Middle.ImageRectOffset = Vector2.new(ImageSize.X/3, ImageSize.Y/3)
	MiddleTop.ImageRectOffset = Vector2.new(ImageSize.Y/3, 0)
	MiddleBottom.ImageRectOffset = Vector2.new(ImageSize.Y/3, ImageSize.Y * (2/3))

	return TopLeft, TopRight, BottomLeft, BottomRight, Middle, MiddleLeft, MiddleRight, MiddleTop, MiddleBottom
end
lib.AddNinePatch = AddNinePatch

local function BackWithRoundedRectangle(Frame, Radius, Color)
	Color = Color or Color3.new(1, 1, 1);

	return AddNinePatch(Frame, "rbxassetid://176688412", Vector2.new(150, 150), Radius, "ImageLabel", {
		ImageColor3 = Color;
	})
end
lib.BackWithRoundedRectangle = BackWithRoundedRectangle

return lib