<commit_before>﻿using System;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Nez.Systems;
using System.Runtime.CompilerServices;
#if !FNA
using Microsoft.Xna.Framework.Input.Touch;
#endif


namespace Nez
{
	public static class Input
	{
		public static Emitter<InputEventType,InputEvent> emitter;

		public static GamePadData[] gamePads;
		public const float DEFAULT_DEADZONE = 0.1f;

		/// <summary>
		/// set by the Scene and used to scale mouse input
		/// </summary>
		internal static Vector2 _resolutionScale;
		/// <summary>
		/// set by the Scene and used to scale input
		/// </summary>
		internal static Point _resolutionOffset;
		static KeyboardState _previousKbState;
		static KeyboardState _currentKbState;
		static MouseState _previousMouseState;
		static MouseState _currentMouseState;
		static internal FastList<VirtualInput> _virtualInputs = new FastList<VirtualInput>();
		static int _maxSupportedGamePads;

		public static TouchInput touch;


		public static int maxSupportedGamePads
		{
			get { return _maxSupportedGamePads; }
			set
			{
				_maxSupportedGamePads = Mathf.clamp( value, 1, 4 );
				gamePads = new GamePadData[_maxSupportedGamePads];
				for( var i = 0; i < _maxSupportedGamePads; i++ )
					gamePads[i] = new GamePadData( (PlayerIndex)i );
			}
		}


		static Input()
		{
			emitter = new Emitter<InputEventType,InputEvent>();
			touch = new TouchInput();

			_previousKbState = new KeyboardState();
			_currentKbState = Keyboard.GetState();

			_previousMouseState = new MouseState();
			_currentMouseState = Mouse.GetState();

			maxSupportedGamePads = 1;
		}


		public static void update()
		{
			touch.update();

			_previousKbState = _currentKbState;
			_currentKbState = Keyboard.GetState();

			_previousMouseState = _currentMouseState;
			_currentMouseState = Mouse.GetState();

			for( var i = 0; i < _maxSupportedGamePads; i++ )
				gamePads[i].update();

			for( var i = 0; i < _virtualInputs.length; i++ )
				_virtualInputs.buffer[i].update();
		}

		/// <summary>
		/// this takes into account the SceneResolutionPolicy and returns the value scaled to the RenderTargets coordinates
		/// </summary>
		/// <value>The scaled position.</value>
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 scaledPosition(Vector2 position)
		{
			var scaledPos = new Vector2(position.X - _resolutionOffset.X, position.Y - _resolutionOffset.Y);
			return scaledPos * _resolutionScale;
		}

		#region Keyboard

		public static KeyboardState previousKeyboardState { get { return _previousKbState; } }

		public static KeyboardState currentKeyboardState { get { return _currentKbState; } }


		/// <summary>
		/// only true if down this frame
		/// </summary>
		/// <returns><c>true</c>, if key pressed was gotten, <c>false</c> otherwise.</returns>
		public static bool isKeyPressed( Keys key )
		{
			return _currentKbState.IsKeyDown( key ) && !_previousKbState.IsKeyDown( key );
		}


		/// <summary>
		/// true the entire time the key is down
		/// </summary>
		/// <returns><c>true</c>, if key down was gotten, <c>false</c> otherwise.</returns>
		public static bool isKeyDown( Keys key )
		{
			return _currentKbState.IsKeyDown( key );
		}
<commit_msg>Add convenience Point  scaledPosition method<commit_after>﻿using System;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Nez.Systems;
using System.Runtime.CompilerServices;
#if !FNA
using Microsoft.Xna.Framework.Input.Touch;
#endif


namespace Nez
{
	public static class Input
	{
		public static Emitter<InputEventType,InputEvent> emitter;

		public static GamePadData[] gamePads;
		public const float DEFAULT_DEADZONE = 0.1f;

		/// <summary>
		/// set by the Scene and used to scale mouse input
		/// </summary>
		internal static Vector2 _resolutionScale;
		/// <summary>
		/// set by the Scene and used to scale input
		/// </summary>
		internal static Point _resolutionOffset;
		static KeyboardState _previousKbState;
		static KeyboardState _currentKbState;
		static MouseState _previousMouseState;
		static MouseState _currentMouseState;
		static internal FastList<VirtualInput> _virtualInputs = new FastList<VirtualInput>();
		static int _maxSupportedGamePads;

		public static TouchInput touch;


		public static int maxSupportedGamePads
		{
			get { return _maxSupportedGamePads; }
			set
			{
				_maxSupportedGamePads = Mathf.clamp( value, 1, 4 );
				gamePads = new GamePadData[_maxSupportedGamePads];
				for( var i = 0; i < _maxSupportedGamePads; i++ )
					gamePads[i] = new GamePadData( (PlayerIndex)i );
			}
		}


		static Input()
		{
			emitter = new Emitter<InputEventType,InputEvent>();
			touch = new TouchInput();

			_previousKbState = new KeyboardState();
			_currentKbState = Keyboard.GetState();

			_previousMouseState = new MouseState();
			_currentMouseState = Mouse.GetState();

			maxSupportedGamePads = 1;
		}


		public static void update()
		{
			touch.update();

			_previousKbState = _currentKbState;
			_currentKbState = Keyboard.GetState();

			_previousMouseState = _currentMouseState;
			_currentMouseState = Mouse.GetState();

			for( var i = 0; i < _maxSupportedGamePads; i++ )
				gamePads[i].update();

			for( var i = 0; i < _virtualInputs.length; i++ )
				_virtualInputs.buffer[i].update();
		}

		/// <summary>
		/// this takes into account the SceneResolutionPolicy and returns the value scaled to the RenderTargets coordinates
		/// </summary>
		/// <value>The scaled position.</value>
		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 scaledPosition(Vector2 position)
		{
			var scaledPos = new Vector2(position.X - _resolutionOffset.X, position.Y - _resolutionOffset.Y);
			return scaledPos * _resolutionScale;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static Vector2 scaledPosition(Point position)
		{
			return scaledPosition(new Vector2(position.X, position.Y));
		}

		#region Keyboard

		public static KeyboardState previousKeyboardState { get { return _previousKbState; } }

		public static KeyboardState currentKeyboardState { get { return _currentKbState; } }


		/// <summary>
		/// only true if down this frame
		/// </summary>
		/// <returns><c>true</c>, if key pressed was gotten, <c>false</c> otherwise.</returns>
		public static bool isKeyPressed( Keys key )
		{
			return _currentKbState.IsKeyDown( key ) && !_previousKbState.IsKeyDown( key );
		}


		/// <summary>
		/// true the entire time the key is down
		/// </summary>
		/// <returns><c>true</c>, if key down was gotten, <c>false</c> otherwise.</returns>
		public static bool isKeyDown( Keys key )
		{
			return _currentKbState.IsKeyDown( key );
		}

{'fraction_non_alphanumeric': 0.10693684366218015, 'fraction_numerical': 0.003845584972637184, 'mean_word_length': 3.8403722261989977, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '211957', 'n_tokens_mistral': 2393, 'n_tokens_neox': 2064, 'n_words': 562}