#include "ToolsCPA.h"
#include "INO.h"
#include "specif\DS_TouchPanel.h"


//For Stylet Rotation
unsigned long ulSavedTime_R, ulSavedTime_L;
unsigned char i_IDX_R, i_IDX_L ;
unsigned char TAB_IDxNextSector_L[4],TAB_IDxNextSector_R[4];

//For Stylet Grattage
MTH3D_tdstVector g_stStyletPos ;
unsigned long g_ulTimeAction, g_ulTimeInactif;


#define TP_WITH_LEFTBUTTON
#ifdef TP_WITH_LEFTBUTTON

#define TP_PRESSED			INO_fn_wLeftMouseButtonDown
#define TP_JUST_PRESSED		INO_fn_wLeftMouseButtonJustDown
#define TP_JUST_RELEASED	INO_fn_wLeftMouseButtonJustUp
#define TP_RELEASED()		C_MouseTrue

#else

#define TP_PRESSED			INO_fn_wRightMouseButtonDown
#define TP_JUST_PRESSED		INO_fn_wRightMouseButtonJustDown
#define TP_JUST_RELEASED	INO_fn_wRightMouseButtonJustUp
#define TP_RELEASED()		C_MouseTrue

#endif







//================================================================//
BOOL DS_bTPGetPosition(int *X,int *Y)
{
	if(INO_fn_wGetMousePosition(X, Y)==C_wMouseTrue)
		return TRUE;
	else
		return FALSE;
}

//================================================================//
BOOL  DS_bTPPressed()
{
	return (TP_PRESSED()==C_wMouseTrue);
}

//================================================================//

BOOL  DS_bTPJustPressed()
{
	return (TP_JUST_PRESSED()==C_wMouseTrue);
}

//================================================================//

BOOL  DS_bTPReleased()
{
	return (TP_JUST_RELEASED()==C_wMouseTrue);
}

//================================================================//

BOOL  DS_bTPJustReleased()
{
	return (TP_JUST_RELEASED()==C_wMouseTrue);
}

//================================================================//
void fn_InitStyletRotationDATA(MTH3D_tdstVector stCentre, MTH3D_tdstVector stStyletPos, BOOL b_Right)
{
	if( b_Right )
	{
		ulSavedTime_R = g_stEngineStructure.stEngineTimer.ulCurrentTimerCount;	
		i_IDX_R = 0;
		if ( stStyletPos.xX > stCentre.xX)
		{			
			if ( stStyletPos.xY < stCentre.xY)
			{	
				TAB_IDxNextSector_R[0] = 2; 
				TAB_IDxNextSector_R[1] = 3;
				TAB_IDxNextSector_R[2] = 4;
				TAB_IDxNextSector_R[3] = 1;
			}
			else
			{
				TAB_IDxNextSector_R[0] = 3; 
				TAB_IDxNextSector_R[1] = 4;
				TAB_IDxNextSector_R[2] = 1;
				TAB_IDxNextSector_R[3] = 2;		
			}
		}
		else
		{
			if ( stStyletPos.xY > stCentre.xY)
			{			
				TAB_IDxNextSector_R[0] = 4; 
				TAB_IDxNextSector_R[1] = 1;
				TAB_IDxNextSector_R[2] = 2;
				TAB_IDxNextSector_R[3] = 3;
			}
			else
			{
				TAB_IDxNextSector_R[0] = 1; 
				TAB_IDxNextSector_R[1] = 2;
				TAB_IDxNextSector_R[2] = 3;
				TAB_IDxNextSector_R[3] = 4;	
			}
		}
	}
	else
	{
		ulSavedTime_L = g_stEngineStructure.stEngineTimer.ulCurrentTimerCount;	
		i_IDX_L = 0;
		if ( stStyletPos.xX > stCentre.xX)
		{			
			if ( stStyletPos.xY < stCentre.xY)
			{	
				TAB_IDxNextSector_L[0] = 4;
				TAB_IDxNextSector_L[1] = 3;
				TAB_IDxNextSector_L[2] = 2;
				TAB_IDxNextSector_L[3] = 1;	
			}
			else
			{
				TAB_IDxNextSector_L[0] = 1; 
				TAB_IDxNextSector_L[1] = 4;
				TAB_IDxNextSector_L[2] = 3;
				TAB_IDxNextSector_L[3] = 2;		
			}
		}
		else
		{
			if ( stStyletPos.xY > stCentre.xY)
			{			
				TAB_IDxNextSector_L[0] = 2; 
				TAB_IDxNextSector_L[1] = 1;
				TAB_IDxNextSector_L[2] = 4;
				TAB_IDxNextSector_L[3] = 3;
			}
			else
			{
				TAB_IDxNextSector_L[0] = 3;
				TAB_IDxNextSector_L[1] = 2;
				TAB_IDxNextSector_L[2] = 1;
				TAB_IDxNextSector_L[3] = 4;	
			}
		}
	}
}
int fni_GetStyletCurrentSector(MTH3D_tdstVector stCentre, MTH3D_tdstVector stStyletPos)
{
	if ( stStyletPos.xX > stCentre.xX)
	{			
		if ( stStyletPos.xY < stCentre.xY)	
			return 1;		
		else	
			return 2;			
	}
	else
	{
		if ( stStyletPos.xY > stCentre.xY)
			return 3;
		else
			return 4;
	}
}
//================================================================//



