/*************************************************************************
*	色指定用ダイアログ
*************************************************************************/


#define	DLG_XS	(8+18*16+8)

int		_csetDspFunc(char *dlg)
{
	int		*para;
	char	*evt;
	int		nowCol;
	int		evtNo;
	int		i, x, y;
	int		x0, y0, xs, ys;

	evtNo = 0;
	para = DLG_getPtr(dlg);
	evt = para[0];
	nowCol = para[1];
	x0 = DLG_getFr(dlg,0);
	y0 = DLG_getFr(dlg,1);
	xs = DLG_getFr(dlg,2);
	ys = DLG_getFr(dlg,3);

	MOS_moveArea( x0, y0, x0+xs-1, y0+ys-1 );

	DSP_boxfHol( x0+2, y0+2, x0+xs-2-1, y0+2+20-1, PSET, C_WHITE, C_HWHITE, C_HBLACK);
	DSP_str( x0+4, y0+4, C_MBLACK, C_WHITE, 16, "COLOR SELECT");
	EVT_set_mos( evt, evtNo++, i, MOSEVT_NOT|MOSEVT_QUICK, BTN_LEFT,
	                 x0+2, y0+2, x0+xs-2-1, y0+2+20-1, "DlgMvFunc", dlg );

	for ( i = 0; i < 16; ++i )
	{
		x = x0 + 8 + i * 18;
		y = y0 + 32;
		DSP_box (x  ,y  ,x+15  ,y+15  , PSET, C_MBLACK);
		DSP_box (x+1,y+1,x+15-1,y+15-1, PSET, C_HWHITE);
		DSP_boxf(x+2,y+2,x+15-2,y+15-2, PSET, i       );
		if ( i == nowCol )
		{	DSP_box (x-1,y-1,x+15-1,y+15-1, PSET, C_HRED );
		} else
		{	EVT_set_mos( evt, evtNo++, i, MOSEVT_NOT, BTN_LEFT,
			             x, y, x+15, y+15, NULL, NULL);
		}
	}

	/* 終了用イベント	*/
	EVT_set_mos( evt, evtNo++, 9999, MOSEVT_BTNOLY, BTN_RIGHT,
	             0, 0, 0, 0, NULL, NULL);
}

int		COLSET_dlg(int nowCol)
{
	int		ret;
	char	*dlg;
	char	*evt;
	char	*mosTk;
	int		para[2];

	if ( (evt = EVT_alloc(NULL,24)) == NULL )
		return (ERR);
	para[0] = evt;
	para[1] = nowCol;
	dlg = DLG_open( DLGPOS_MOS_SET_CENTER,DLGPOS_MOS_SET_CENTER,
	    DLG_XS,80, COLMIX(C_WHITE,C_HWHITE), "_csetDspFunc", para );
	if ( dlg == NULL )
	{
		EVT_free(evt);
		return (ERR);
	}
	mosTk = MOS_push();
	DLG_dsp(dlg);

	while ( 1 )
	{
		MOS_CON();
		ret = EVT_chk(evt,0);
		if ( (ret >= 0 && ret < 16) || ret == 9999 )
			break;
	}

	DLG_close(dlg);
	EVT_free(evt);
	MOS_pop(mosTk);
	if ( ret >= 0 && ret < 16 )
		return (ret);
	else
		return (ERR);
}

int		_csetDspFunc2(char *dlg)
{
	int		   *para;
	char	   *evt;
	int			nowCol;
	int			evtNo;
	int			i, j, flag, x, y;
	int			x0, y0, xs, ys;

	evtNo  = 0;
	para   = DLG_getPtr(dlg);
	evt    = para[0];
	nowCol = para[1];
	x0 = DLG_getFr(dlg,0);
	y0 = DLG_getFr(dlg,1);
	xs = DLG_getFr(dlg,2);
	ys = DLG_getFr(dlg,3);

	MOS_moveArea( x0, y0, x0+xs-1, y0+ys-1 );

	DSP_boxfHol( x0+2, y0+2, x0+xs-2-1, y0+2+20-1, PSET, C_WHITE, C_HWHITE, C_HBLACK);
	DSP_str( x0+4, y0+4, C_MBLACK, C_WHITE, 16, "COLOR SELECT");
	EVT_set_mos( evt, evtNo++, i, MOSEVT_NOT|MOSEVT_QUICK, BTN_LEFT,
	    x0+2, y0+2, x0+xs-2-1, y0+2+20-1, "DlgMvFunc", dlg);

	for ( j = 0; j < 2; ++ j )
	{
		y = y0 + j*20 + 32;
		DSP_egbStr( x0+4, y, C_MBLACK, COLMIX(C_WHITE,C_HWHITE), 16,"color %d", j+1);
		for ( i = 0; i < 16; ++i )
		{
			x = x0 + 8*8+ 8 + i * 18;
			DSP_box (x  ,y  ,x+15  ,y+15  , PSET, C_MBLACK);
			DSP_box (x+1,y+1,x+15-1,y+15-1, PSET, C_HWHITE);
			DSP_boxf(x+2,y+2,x+15-2,y+15-2, PSET, i       );
			flag = FALSE;
			if ( j == 0 )
			{
				if ( (nowCol & 15) == i )
					flag = TRUE;
			} else
			{
				if ( ((nowCol>>4) & 15) == i )
					flag = TRUE;
			}
			if ( flag )
			{
				DSP_box (x-1,y-1,x+15-1,y+15-1, PSET, C_HRED );
			} else
			{
				EVT_set_mos( evt, evtNo++, i + (j * 16), MOSEVT_NOT, BTN_LEFT,
				    x, y, x+15, y+15, NULL, NULL);
			}
		}
	}

	EVT_setSelBtn( evt, evtNo++, 9997, MOSEVT_BTN, BTN_LEFT,
	    x0+xs/2-48, y0+ys-28, 96, 24, NULL, NULL,
	    C_MBLACK, C_WHITE, C_HBLACK, "OK : [実行]" );
	/* 終了用イベント	*/
	EVT_set_mos( evt, evtNo++, 9999, MOSEVT_BTNOLY, BTN_RIGHT,
	    0, 0, 0, 0, NULL, NULL);
}

int		COLSET_dlg2(int nowCol)
{
	int			ret;
	char	   *dlg;
	char	   *evt;
	char	   *mosTk;
	int			para[2];

	if ( (evt = EVT_alloc(NULL,40)) == NULL )
		return (ERR);
	para[0] = evt;
	para[1] = nowCol;
	dlg = DLG_open( DLGPOS_MOS_SET_CENTER,DLGPOS_MOS_SET_CENTER,
	    DLG_XS+8*8,112, COLMIX(C_WHITE,C_HWHITE),
	    "_csetDspFunc2", para );
	if ( dlg == NULL )
	{
		EVT_free(evt);
		return (ERR);
	}
	mosTk = MOS_push();
	DLG_dsp(dlg);

	while ( 1 )
	{
		MOS_CON();
		ret = EVT_chk(evt,0);
		if ( ret == 9999 || ret == 9997 )
			break;
		else if ( ret >= 0 && ret < 16 )
		{
			nowCol = (nowCol & 0xF0) + ret;
			para[1] = nowCol;
			DLG_dsp(dlg);
		} else if ( ret >= 16 && ret < 32 )
		{
			nowCol = (nowCol & 0x0F) + ((ret-16)<<4);
			para[1] = nowCol;
			DLG_dsp(dlg);
		}
	}

	DLG_close(dlg);
	EVT_free(evt);
	MOS_pop(mosTk);
	if ( ret == 9999 )
		return (ERR);
	else
	{
		if ( ((nowCol>>4) & 15) == (nowCol & 15) )
			nowCol = nowCol & 15;
		else
			nowCol = nowCol | 0x1000;
		return (nowCol);
	}
}

#undef	DLG_XS
