/////////////////////////////////////////////////////////////////////////////
// Auto_brakes.c
// 
/////////////////////////////////////////////////////////////////////////////
//
signed int Auto_brakes = 0;
int flag ;
MODULE_VAR PANEL_AUTOBRAKE_SWITCH_var = {PANEL_AUTOBRAKE_SWITCH};
MODULE_VAR AIRSPEED_var = {AIRSPEED};

//	Set up gauge header
char Auto_brakes_gauge_name[]	= GAUGE_NAME;
extern PELEMENT_HEADER	Auto_brakes_list;
extern MOUSERECT      	Auto_brakes_mouse_rect[];

GAUGE_HEADER_FS700(GAUGE_W, Auto_brakes_gauge_name, &Auto_brakes_list, \
						Auto_brakes_mouse_rect, 0, 0, 0, 0);


/*---------------------------------------------------------------------------
---- Functions that ilustrate status of Keys --------------------------------
---------------------------------------------------------------------------*/
FLOAT64 FSAPI	Auto_brakes_icon_cb( PELEMENT_ICON pelement )
{
	lookup_var (&PANEL_AUTOBRAKE_SWITCH_var);
	if (PANEL_AUTOBRAKE_SWITCH_var.var_value.e == 1 ) { // Off
		Auto_brakes = 0;
	}
	else if (PANEL_AUTOBRAKE_SWITCH_var.var_value.e == 2 ) { //Low
		Auto_brakes = 1;
	}
	else if (PANEL_AUTOBRAKE_SWITCH_var.var_value.e == 3 ) { // High
		Auto_brakes = 2;
	}
	else { // Other
		 if (PANEL_AUTOBRAKE_SWITCH_var.var_value.e == 0 ) { // RTO
			trigger_key_event (KEY_INC_AUTOBRAKE_CONTROL,1);
			Auto_brakes = 0;
		 }
		 else if (PANEL_AUTOBRAKE_SWITCH_var.var_value.e == 4 ) { // High +
			trigger_key_event (KEY_DEC_AUTOBRAKE_CONTROL,1);
			Auto_brakes = 3;
		 }	
		 else if (PANEL_AUTOBRAKE_SWITCH_var.var_value.e == 5 ) { // High ++ = Forsage
			Auto_brakes = 3;
		 }
	}
	return Auto_brakes;
}

/*---------------------------------------------------------------------------
------------ Make ICONS macroses     ----------------------------------------
---------------------------------------------------------------------------*/

MAKE_ICON
(		
	Auto_brakes_icon,
	BMP_Auto_brakes_1,
	NULL,
	NULL,
	IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
	0,
	0,0,

	MODULE_VAR_NONE, Auto_brakes_icon_cb,

	ICON_SWITCH_TYPE_SET_CUR_ICON,
	3,
	0,
	0
)

PELEMENT_HEADER		Auto_brakes_icon_list[] =
{
	&Auto_brakes_icon.header,
	NULL
};
/////////////////////////////////////////////////////////////////////////////
MAKE_STATIC
(
	Auto_brakes_background,
	BMP_Auto_brakes_BG,
	&Auto_brakes_icon_list,
	NULL,
	IMAGE_USE_TRANSPARENCY,
	0,
	0,0
)

PELEMENT_HEADER		Auto_brakes_list= &Auto_brakes_background.header;

/*---------------------------------------------------------------------------
---------------- Call back mouse functions ----------------------------------
---------------------------------------------------------------------------*/

BOOL FSAPI Auto_brakes_inc_mouse_cb( PPIXPOINT relative_point, FLAGS32 mouse_flags )
{	
	lookup_var (&PANEL_AUTOBRAKE_SWITCH_var);
	if ( PANEL_AUTOBRAKE_SWITCH_var.var_value.e < 3) { 
		trigger_key_event (KEY_INC_AUTOBRAKE_CONTROL,1);
	}
	return TRUE;
}

BOOL FSAPI Auto_brakes_dec_mouse_cb( PPIXPOINT relative_point, FLAGS32 mouse_flags )
{	
	lookup_var (&PANEL_AUTOBRAKE_SWITCH_var);
	if ( PANEL_AUTOBRAKE_SWITCH_var.var_value.e > 0) {
		trigger_key_event (KEY_DEC_AUTOBRAKE_CONTROL,1);
	}
	return TRUE;
}
/////////////////////////////////////////////////////////////////////////////

MOUSE_BEGIN( Auto_brakes_mouse_rect, HELP_NONE, 0, 0 )
	MOUSE_CHILD_FUNCT( 35,0,30,30, CURSOR_UPARROW, MOUSE_LEFTSINGLE, Auto_brakes_inc_mouse_cb )
	MOUSE_CHILD_FUNCT( 0,40,30,30, CURSOR_DOWNARROW, MOUSE_LEFTSINGLE, Auto_brakes_dec_mouse_cb )
MOUSE_END

/////////////////////////////////////////////////////////////////////////////


#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W
