--Constructor and destructor

function touch_button:New(parent_frame, pos, size)
	--Initialize meta reference
	local self = setmetatable({}, {__index = touch_button})

	--Create button
	self.button = Instance.new("ImageButton")
	self.button.Name = "Button"
	self.button.BackgroundTransparency = 1
	self.button.ImageTransparency = 1
	self.button.ImageColor3 = released_col
	self.button.Active = false
	self.button.Size = size
	self.button.Position = pos
	self.button.Parent = parent_frame

	--Initialize state
	self.pressed = false
	self.move_touch_input = nil
	self.enabled = false

	--Input connections
	self.input_connections = {
		self.button.InputBegan:Connect(function(input)
			--Make sure input is a valid state
			if self.enabled == false or self.move_touch_input ~= nil or input.UserInputType ~= Enum.UserInputType.Touch or input.UserInputState ~= Enum.UserInputState.Begin then
				return
			end

			--Start holding button
			self.move_touch_input = input
			self.button.ImageColor3 = pressed_col
			self.pressed = true
		end),
		uis.TouchEnded:Connect(function(input, processed)
			if input == self.move_touch_input then
				OnInputEnded(self)
			end
		end),
		gui_service.MenuOpened:Connect(function()
			if self.move_touch_input ~= nil then
				OnInputEnded(self)
			end
		end),
	}

	return self
end

function touch_button:Destroy()
	--Disconnect connections
	if self.input_connections ~= nil then
		for _,v in pairs(self.input_connections) do
			v:Disconnect()
		end
		self.input_connections = nil
	end

	--Destroy button
	if self.button ~= nil then
		self.button:Destroy()
		self.button = nil
	end
end
