/*class Gc_Shop_BindInputs {
	private uint				buttons;
	private uint				old_buttons;
	private uint				pressed_buttons;
	private uint				released_buttons;
	
	void 
}*/

/*	kd:
	Contains everything necessary to move the cursor clamped into the screen,
	as well as key presses.
	
	Cursor coordinates are stored from 0 to 100k. This makes good use of float
	precision already, but you have to be careful about screen coordinate
	conversions and such. */

class Gcs_Inputs {
	uint    m_bt, m_old_bt, m_press, m_release;
	double  m_yaw, m_pitch;
	double  m_old_cursor_x, m_old_cursor_y;
	double  m_real_cursor_x, m_real_cursor_y;
	double  m_move_scale;
	bool    m_inverted;
	int		m_screen_width;
	int		m_screen_height;
	double  m_aspect;
	// Cvar    m_invert_cursor_y;
	
	void Init (PlayerInfo user) {
		m_bt         = 0;
		m_old_bt     = 0;
		m_press      = 0;
		m_release    = 0;
		m_yaw        = 0;
		m_pitch      = 0;
		
		m_screen_width	= Screen.GetWidth();
		m_screen_height	= Screen.GetHeight();
		m_aspect		= Screen.GetAspectRatio();
		
		m_real_cursor_x   = 0.5 * m_screen_width;
		m_real_cursor_y   = 0.5 * m_screen_height;
		m_old_cursor_x    = m_real_cursor_x;
		m_old_cursor_y    = m_real_cursor_y;
	}
	
	// For input stuff.
	play void UpdateInput (PlayerInfo user) {
		// Imagine a world in which data gets written over if a flag is set,
		// but the package still claims these are the "buttons". Very funny.
		m_bt		= user.original_cmd.buttons;
		m_old_bt	= user.original_oldbuttons;		// why did they do that?
		
		m_press		= m_bt     & (~m_old_bt);
		m_release	= m_old_bt & (~m_bt);
	}
	
	void OutdateCursor () {
		m_old_cursor_x = m_real_cursor_x;
		m_old_cursor_y = m_real_cursor_y;
	}
	
	ui void UpdateCursor (int dx, int dy) {
		double hor = 0.35 * dx;
		double ver = 0.35 * dy * 4;
		
		m_real_cursor_x = clamp(m_real_cursor_x + hor, 0, m_screen_width);
		m_real_cursor_y = clamp(m_real_cursor_y - ver, 0, m_screen_height);
	}
	
	void ProjectToCircle (vector2 center = (0.5, 0.5), double radius = 0.5) {
		// center	*= samples;
		// radius	*= samples;
		
		vector2 diff = (m_real_cursor_x, m_real_cursor_y) - center;
		
		if(diff == (0, 0)) {
			m_real_cursor_x	= 0;
			m_real_cursor_y	= radius;
		}
		
		else {
			vector2 diff_u	= diff.unit();
			m_real_cursor_x	= diff_u.x;
			m_real_cursor_y	= diff_u.y;
		}
	}
	
	void RestrictIntoCircle (vector2 center = (0.5, 0.5), double radius = 0.5) {
		// center	*= samples;
		// radius	*= samples;
		
		vector2 diff = (m_real_cursor_x, m_real_cursor_y) - center;
		
		if(diff == (0, 0)) {
			m_real_cursor_x = center.x;
			m_real_cursor_y = center.y;
		}
		
		else {
			let len			= diff.length();
			let scale_len	= min(len, radius);
			vector2 diff_u	= diff.unit();
			
			m_real_cursor_x = center.x + scale_len * diff_u.x;
			m_real_cursor_y = center.y + scale_len * diff_u.y;
		}
	}
	
	// It looks neater.
	bool Pressed (uint key) const {
		return m_press & key;
	}
	
	bool Released (uint key) const {
		return m_release & key;
	}
	
	bool Held (uint key) const {
		return m_bt & key;
	}
	
	// Interpolated draw coordinates.
	ui double, double CursorDrawCoord (double t) const {
		let x = t * m_real_cursor_x + (1 - t) * m_old_cursor_x;
		let y = t * m_real_cursor_y + (1 - t) * m_old_cursor_y;
		return	x, y;
	}
	
	// Normal cursor position.
	double, double CursorNormalPos () const {
		return
			m_real_cursor_x / m_screen_width,
			m_real_cursor_y / m_screen_height;
	}
	
	double, double CursorPos () const {
		return
			m_real_cursor_x,
			m_real_cursor_y;
	}
	
	vector2 CursorPos2 () const {
		return (m_real_cursor_x, m_real_cursor_y);
	}
}