/* This file contains empty template routines that
 * the IDCMP handler will call uppon. Fill out these
 * routines with your code or use them as a reference
 * to create your program.
 */

int
SetTable()
{
	table[0] = (1l<<16) + index;
	table[1] = red<<24  | 0x00FFFFFF;
	table[2] = green<<24| 0x00FFFFFF;
	table[3] = blue<<24 | 0x00FFFFFF;
	table[4] = NULL;

//	SetRGB32(&Scr->ViewPort, index, table[1], table[2], table[3]);
	LoadRGB32(&Scr->ViewPort, table);
	return(0);
}

int BlueSliderGClicked( struct IntuiMessage *m )
{
	blue = m->Code;
	SetTable();
	return(TRUE);
}

int GreenSliderGClicked( struct IntuiMessage *m )
{
	green = m->Code;
	SetTable();
	return(TRUE);
}

int RedSliderGClicked( struct IntuiMessage *m )
{
	red = m->Code;
	SetTable();
	return(TRUE);
}

int UseGClicked( struct IntuiMessage *m )
{
	/* routine when gadget "_Use" is clicked. */

     return(FALSE);
}

int ResetGClicked( struct IntuiMessage *m )
{
	/* routine when gadget "r_Eset" is clicked. */

	ResetPalette();
	return(TRUE);
}

int CancelGClicked( struct IntuiMessage *m )
{
	/* routine when gadget "_Cancel" is clicked. */

	ResetPalette();
	return(FALSE);
}

int
PaletteGClicked( struct IntuiMessage *m )
{
	index = m->Code;
	GetRGB32(Scr->ViewPort.ColorMap, index, 1, &table[1]);
	red   = table[1]>>24;
	green = table[2]>>24;
	blue  = table[3]>>24;
	SetDrMd(PReqWnd->RPort, JAM2);
	SetAPen(PReqWnd->RPort, index);
	RectFill(PReqWnd->RPort, PReqWnd->BorderLeft+9, PReqWnd->BorderTop+29,
                              PReqWnd->BorderLeft+41, PReqWnd->BorderTop+61);
     GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL,
                       GTSL_Level, red, TAG_END);
     GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL,
                       GTSL_Level, green, TAG_END);
     GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL,
                       GTSL_Level, blue, TAG_END);
	return(TRUE);
}

int PReqCloseWindow( void )
{
	/* routine for "IDCMP_CLOSEWINDOW". */

	ResetPalette();
	return(FALSE);
}

