//
// Asura_Key_Combination.cpp
//
// Created by Kevin Lea - 05/10/2001 16:30:16
// 
// Copyright (C) 2001 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"
#include "Interface/Asura_Key_Combination.h"

#include "Core/Asura_UserInput.h"
#include "Debugging/Asura_Assert.h"

Asura_Key_Combination::Asura_Key_Combination(int key,int modifiers_to_press/* = 0*/,int modifiers_to_check/* = ASURA_MODIFIER_KEY_ALL*/)
{
	Asura_Assert((modifiers_to_press & modifiers_to_check) == modifiers_to_press,"Silly combination of flags");
	
	Key = key;
	ModifiersToPress = modifiers_to_press;
	ModifiersToCheck = modifiers_to_check;
}

bool Asura_Key_Combination::KeyPressed()
{
	return(Asura_UserInput::KeyPressed(Key) && CorrectModifiersPressed());
}

bool Asura_Key_Combination::DebouncedKeyPressed()
{
	return(Asura_UserInput::DebouncedKeyPressed(Key) && CorrectModifiersPressed());

}

bool Asura_Key_Combination::CorrectModifiersPressed()
{
	//check each modifier key to see if its in the desired state
	if(ModifiersToCheck & ASURA_MODIFIER_KEY_SHIFT)
	{
		if(ModifiersToPress & ASURA_MODIFIER_KEY_SHIFT)
		{
			if(!Asura_UserInput::KeyPressed(ASURA_KEYID_SHIFT)) return false;
		}
		else
		{
			if(Asura_UserInput::KeyPressed(ASURA_KEYID_SHIFT)) return false;
		}
	}
	if(ModifiersToCheck & ASURA_MODIFIER_KEY_CTRL)
	{
		if(ModifiersToPress & ASURA_MODIFIER_KEY_CTRL)
		{
			if(!Asura_UserInput::KeyPressed(ASURA_KEYID_CTRL)) return false;
		}
		else
		{
			if(Asura_UserInput::KeyPressed(ASURA_KEYID_CTRL)) return false;
		}
	}
	return true;
}
