require 'scripts/gui/gui.lua'

local classic_gamepad = set{CLASSIC_GAMEPAD_1, CLASSIC_GAMEPAD_2, CLASSIC_GAMEPAD_3, CLASSIC_GAMEPAD_4}
local urcc_gamepad = set{URCC_GAMEPAD_1, URCC_GAMEPAD_2, URCC_GAMEPAD_3, URCC_GAMEPAD_4}

--------------------------------------------------------------------------------
-- GUI inputs constants
--------------------------------------------------------------------------------
GUI.AXIS_THRESHOLD = math.cos(math.pi / 4) -- 0.707
GUI.AXIS_THRESHOLD_LOW = 0.1
GUI.TOUCH_THRESHOLD = 0.2
GUI.KEY_THRESHOLD = 0.1

GUI.REPEAT_DELAY = 0.5
GUI.REPEAT_RATE = 0.1

GUI.REPEAT_TIME = 0.2

GUI.currentTime = 0
GUI.startPressedTime = 0
GUI.state = 0
GUI.devicePressed = 0
GUI.controlPressed = 0

--------------------------------------------------------------------------------
-- isControlPressed
--! @brief Returns whether a specified control on a specified device has been pressed on the previous frame
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isControlPressed(device, control, threshold)
	return (threshold >= 0 and Input_getState(device, control) >= threshold and Input_getStateDelta(device, control) > threshold) or (threshold < 0 and Input_getState(device, control) <= threshold and Input_getStateDelta(device, control) < threshold)
end

--------------------------------------------------------------------------------
-- isControlReleased
--! @brief Returns whether a specified control on a specified device has been released on the previous frame
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isControlReleased(device, control, threshold)
	return (threshold >= 0 and Input_getState(device, control) >= threshold and Input_getStateDelta(device, control) < -threshold) or (threshold < 0 and Input_getState(device, control) <= threshold and Input_getStateDelta(device, control) > -threshold)
end

--------------------------------------------------------------------------------
-- isControlDown
--! @brief Returns whether a specified control on a specified device has a down state
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isControlDown(device, control, threshold)
	return (threshold >= 0 and Input_getState(device, control) > threshold) or (threshold < 0 and Input_getState(device, control) < threshold)
end

--------------------------------------------------------------------------------
-- isControlUp
--! @brief Returns whether a specified control on a specified device has a up state
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isControlUp(device, control, threshold)
	return (threshold >= 0 and Input_getState(device, control) <= threshold) or (threshold < 0 and Input_getState(device, control) >= threshold)
end

--------------------------------------------------------------------------------
-- wasControlDown
--! @brief Returns whether a specified control on a specified device had a down state on the previous frame
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:wasControlDown(device, control, threshold)
	return (threshold >= 0 and Input_getPreviousState(device, control) > threshold) or (threshold < 0 and Input_getPreviousState(device, control) < threshold)
end

--------------------------------------------------------------------------------
-- wasControlUp
--! @brief Returns whether a specified control on a specified device had a up state on the previous frame
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:wasControlUp(device, control, threshold)
	return (threshold >= 0 and Input_getPreviousState(device, control) <= threshold) or (threshold < 0 and Input_getPreviousState(device, control) >= threshold)
end

--------------------------------------------------------------------------------
-- isControlPressedRepeat
--! @brief Returns whether a specified control on a specified device has been pressed on the previous frame or if it entered a repeat state
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isControlPressedRepeat(device, control, threshold)
	-- local pressed = GUI:isControlPressed(device, control, threshold)
	local down = GUI:isControlDown(device, control, threshold)
	local wasDown = GUI:wasControlDown(device, control, threshold)
	if GUI.state == 0 then
		if down and not wasDown then
			GUI.threshold = threshold
			GUI.controlPressed = control
			GUI.devicePressed = device
			GUI.state = 1


			GUI.startPressedTime = GUI.currentTime

		--	GUI:debugPrint("state 0 : pressed")

			return true
		end
	end

	if GUI.state ~= 0 and GUI.devicePressed == device and GUI.controlPressed == control and GUI.threshold == threshold then
		if GUI.state == 1 then
			if (not down) and (not wasDown) then
			--	GUI:debugPrint("state 1 : not down")
				GUI.state = 0
			elseif GUI.currentTime - GUI.startPressedTime > GUI.REPEAT_DELAY then
				GUI.state = 2
				GUI.startPressedTime = GUI.currentTime

				return true
			end
		elseif GUI.state == 2 then
			if (not down) and (not wasDown) then
			--	GUI:debugPrint("state 2 : not down")
				GUI.state = 0
			elseif GUI.currentTime - GUI.startPressedTime > GUI.REPEAT_RATE then
				GUI.startPressedTime = GUI.currentTime
				return true
			end
		end
	end

	return false

end

--------------------------------------------------------------------------------
-- isKeyPressed
--! @brief Returns whether the specified key has been pressed during the last frame
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isKeyPressed(device, control)
	return GUI:isControlPressed(device, control, GUI.KEY_THRESHOLD)
end

--------------------------------------------------------------------------------
-- isKeyPressedRepeat
--! @brief Returns whether the specified key has been pressed during the last frame or if is in repeat mode
--! @param device device id
--! @param control control id
--! @param threshold threshold value
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isKeyPressedRepeat(device, control)
	return GUI:isControlPressedRepeat(device, control, GUI.KEY_THRESHOLD)
end

--------------------------------------------------------------------------------
-- isTouched
--! @brief Returns whether the touch device has a touched state
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isTouched()
	return GUI:isControlDown(TOUCH_DEVICE, TOUCH_TOUCHED, GUI.TOUCH_THRESHOLD)
end

--------------------------------------------------------------------------------
-- wasTouched
--! @brief Returns whether the touch device has a touched state
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:wasTouched()
	return GUI:wasControlDown(TOUCH_DEVICE, TOUCH_TOUCHED, GUI.TOUCH_THRESHOLD)
end


--------------------------------------------------------------------------------
-- isLeftDown
--! @brief Returns whether the left key is in a down state
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isLeftDown(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlDown(PAD_DEVICE, GAMEPAD_PAD_LEFT, GUI.KEY_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_AXIS_X, -GUI.AXIS_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_RAXIS_X, -GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlDown(device, CLASSIC_GAMEPAD_PAD_LEFT, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_LEFT_X, -GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_RIGHT_X, -GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlDown(device, URCC_GAMEPAD_PAD_LEFT, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_LEFT_X, -GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_RIGHT_X, -GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isLeftPressed
--! @brief Returns whether the left key has been pressed (can be repeated)
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isLeftPressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_PAD_LEFT, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_AXIS_X, -GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_RAXIS_X, -GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_PAD_LEFT, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_LEFT_X, -GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_RIGHT_X, -GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlPressedRepeat(device, URCC_GAMEPAD_PAD_LEFT, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_LEFT_X, -GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_RIGHT_X, -GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isRightDown
--! @brief Returns whether the right key is in a down state
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isRightDown(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlDown(PAD_DEVICE, GAMEPAD_PAD_RIGHT, GUI.KEY_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_AXIS_X, GUI.AXIS_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_RAXIS_X, GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlDown(device, CLASSIC_GAMEPAD_PAD_RIGHT, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_LEFT_X, GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_RIGHT_X, GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlDown(device, URCC_GAMEPAD_PAD_RIGHT, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_LEFT_X, GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_RIGHT_X, GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isRightPressed
--! @brief Returns whether the right key has been pressed (can be repeated)
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isRightPressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_PAD_RIGHT, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_AXIS_X, GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_RAXIS_X, GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_PAD_RIGHT, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_LEFT_X, GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_RIGHT_X, GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlPressedRepeat(device, URCC_GAMEPAD_PAD_RIGHT, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_LEFT_X, GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_RIGHT_X, GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isUpDown
--! @brief Returns whether the up key is in a down state
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isUpDown(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlDown(PAD_DEVICE, GAMEPAD_PAD_UP, GUI.KEY_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_AXIS_Y, -GUI.AXIS_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_RAXIS_Y, -GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlDown(device, CLASSIC_GAMEPAD_PAD_UP, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_LEFT_Y, GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_RIGHT_Y, GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlDown(device, URCC_GAMEPAD_PAD_UP, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_LEFT_Y, GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_RIGHT_Y, GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isUpPressed
--! @brief Returns whether the up key has been pressed (can be repeated)
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isUpPressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_PAD_UP, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_AXIS_Y, -GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_RAXIS_Y, -GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_PAD_UP, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_LEFT_Y, GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_RIGHT_Y, GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlPressedRepeat(device, URCC_GAMEPAD_PAD_UP, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_LEFT_Y, GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_RIGHT_Y, GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isDownDown
--! @brief Returns whether the down key is in a down state
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isDownDown(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlDown(PAD_DEVICE, GAMEPAD_PAD_DOWN, GUI.KEY_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_AXIS_Y, GUI.AXIS_THRESHOLD) or GUI:isControlDown(PAD_DEVICE, GAMEPAD_RAXIS_Y, GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlDown(device, CLASSIC_GAMEPAD_PAD_DOWN, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_LEFT_Y, -GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, CLASSIC_GAMEPAD_AXIS_RIGHT_Y, -GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlDown(device, URCC_GAMEPAD_PAD_DOWN, GUI.KEY_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_LEFT_Y, -GUI.AXIS_THRESHOLD) or GUI:isControlDown(device, URCC_GAMEPAD_AXIS_RIGHT_Y, -GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isDownPressed
--! @brief Returns whether the down key has been pressed (can be repeated)
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isDownPressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_PAD_DOWN, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_AXIS_Y, GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(PAD_DEVICE, GAMEPAD_RAXIS_Y, GUI.AXIS_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_PAD_DOWN, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_LEFT_Y, -GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, CLASSIC_GAMEPAD_AXIS_RIGHT_Y, -GUI.AXIS_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlPressedRepeat(device, URCC_GAMEPAD_PAD_DOWN, GUI.KEY_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_LEFT_Y, -GUI.AXIS_THRESHOLD) or GUI:isControlPressedRepeat(device, URCC_GAMEPAD_AXIS_RIGHT_Y, -GUI.AXIS_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isValidateDown
--! @brief Returns whether the validate key is in a down state
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isValidateDown(device)
	if not device or device == PAD_DEVICE then
		return not GUI:isTouched() and GUI:isControlDown(PAD_DEVICE, GAMEPAD_A, GUI.KEY_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isControlDown(device, CLASSIC_GAMEPAD_A, GUI.KEY_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlDown(device, URCC_GAMEPAD_A, GUI.KEY_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isValidatePressed
--! @brief Returns whether the validate key has been pressed during the last frame
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isValidatePressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_A, GUI.KEY_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isKeyPressed(device, CLASSIC_GAMEPAD_A, GUI.KEY_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isKeyPressed(device, URCC_GAMEPAD_A, GUI.KEY_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isValidateReleased
--! @brief Returns whether the cancel key has been released during the last frame
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isValidateReleased(device)
	if not device or device == PAD_DEVICE then
		return GUI:isControlReleased(PAD_DEVICE, GAMEPAD_A, GUI.KEY_THRESHOLD)

	elseif classic_gamepad[device] then
		return GUI:isControlReleased(device, CLASSIC_GAMEPAD_A, GUI.KEY_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isControlReleased(device, URCC_GAMEPAD_A, GUI.KEY_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isCancelPressed
--! @brief Returns whether the cancel key has been pressed during the last frame
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isCancelPressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_B, GUI.KEY_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isKeyPressed(device, CLASSIC_GAMEPAD_B, GUI.KEY_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isKeyPressed(device, URCC_GAMEPAD_B, GUI.KEY_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isLeftZPressed
-- @brief Returns whether the left z key has been pressed during the last frame
-- @return boolean value
--------------------------------------------------------------------------------
function GUI:isLeftZPressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_LEFT_ZTRIGGER, GUI.KEY_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isKeyPressed(device, CLASSIC_GAMEPAD_ZL, GUI.KEY_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isKeyPressed(device, URCC_GAMEPAD_ZL, GUI.KEY_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isSelectPressed
-- @brief Returns whether the select key has been pressed during the last frame
-- @return boolean value
--------------------------------------------------------------------------------
function GUI:isSelectPressed(device)
	if not device or device == PAD_DEVICE then
		return GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_SELECT, GUI.KEY_THRESHOLD)
	elseif classic_gamepad[device] then
		return GUI:isKeyPressed(device, CLASSIC_GAMEPAD_MINUS, GUI.KEY_THRESHOLD)
	elseif urcc_gamepad[device] then
		return GUI:isKeyPressed(device, URCC_GAMEPAD_MINUS, GUI.KEY_THRESHOLD)
	end
end

--------------------------------------------------------------------------------
-- isAnythingPressed
--! @brief Returns whether any key has been pressed during the last frame
--! @return boolean value
--------------------------------------------------------------------------------
function GUI:isAnythingPressed()
	return GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_PAD_UP, GUI.KEY_THRESHOLD) or
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_PAD_LEFT, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_PAD_DOWN, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_PAD_RIGHT, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_A, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_B, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_X, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_Y, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_LEFT_TRIGGER, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_RIGHT_TRIGGER, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_START, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_SELECT, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_LEFT_ZTRIGGER, GUI.KEY_THRESHOLD) or 
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_RIGHT_ZTRIGGER, GUI.KEY_THRESHOLD) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_AXIS_X, -GUI.AXIS_THRESHOLD_LOW) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_AXIS_X, GUI.AXIS_THRESHOLD_LOW) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_AXIS_Y, GUI.AXIS_THRESHOLD_LOW) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_AXIS_Y, -GUI.AXIS_THRESHOLD_LOW) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_RAXIS_X, -GUI.AXIS_THRESHOLD_LOW) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_RAXIS_X, GUI.AXIS_THRESHOLD_LOW) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_RAXIS_Y, GUI.AXIS_THRESHOLD_LOW) or 
	GUI:isControlPressed(PAD_DEVICE, GAMEPAD_RAXIS_Y, -GUI.AXIS_THRESHOLD_LOW) or  
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_LEFT_STICK, GUI.KEY_THRESHOLD) or  
	GUI:isKeyPressed(PAD_DEVICE, GAMEPAD_RIGHT_STICK, GUI.KEY_THRESHOLD) or 
	GUI:isTouched()
end


