// グ
// 1文字ごとに色を割当てた
// HTMLコードを出力します
// 全角文字のみに対応しています


PAINT
{
	SetPal(9,bk_r,bk_g,bk_b) ;
	RBox(8,160,436,250,20,20,0,9) ;

	many = GetEditLength("ID_buf") / 2 ; // 文字列の文字数(全角)
	if(many <= 0){ return ; }

	r = (sp_r-st_r)/many ; // 1文字あたりの色の変化値
	g = (sp_g-st_g)/many ;
	b = (sp_b-st_b)/many ;

	cr = st_r ;
	cg = st_g ;
	cb = st_b ;

	SetFont("MS ゴシック",italic) ; // 斜体の設定(フォント名は固定している)

	x = 30 ; y = 180 ; p = 0 ;
	s = size * 2 + 3 ; // HTML上の文字サイズをグラフィック上に変換(近似値)
	loop(many){
		SetPal(8,cr,cg,cb) ;
		Box(x,y,x+s*2,y+6,8,8) ;

		AllSelectEdit("ID_sub") ;
		GetEditText("ID_buf",p,p+2,"ID_sub") ;
		Print(x,y+30,0,s,s*2,8,"ID_sub") ;

		x = x + s * 2 ;
		p = p + 2 ;
		cr = cr + r ;
		cg = cg + g ;
		cb = cb + b ;
	}
}


// 以下、各種コントロールを操作した場合の処理
ID_size {
	size = GetListPos("ID_size") + 1 ;
	call("PAINT") ;
}
ID_italic
{
	italic = (italic + 1) % 2 ;
	SetButtonCheck("ID_italic",italic) ; call("PAINT") ;
}
ID_st_r { st_r = GetScrollPos("ID_st_r") ; call("PAINT") ; }
ID_st_g { st_g = GetScrollPos("ID_st_g") ; call("PAINT") ; }
ID_st_b { st_b = GetScrollPos("ID_st_b") ; call("PAINT") ; }

ID_sp_r { sp_r = GetScrollPos("ID_sp_r") ; call("PAINT") ; }
ID_sp_g { sp_g = GetScrollPos("ID_sp_g") ; call("PAINT") ; }
ID_sp_b { sp_b = GetScrollPos("ID_sp_b") ; call("PAINT") ; }

ID_bk_r { bk_r = GetScrollPos("ID_bk_r") ; call("PAINT") ; }
ID_bk_g { bk_g = GetScrollPos("ID_bk_g") ; call("PAINT") ; }
ID_bk_b { bk_b = GetScrollPos("ID_bk_b") ; call("PAINT") ; }

// 初期化サブルーチン
INIT
{
	size = 3 ;   // HTMLでの文字サイズ
	italic = 0 ; // 斜体フラグ

	st_r = 255 ; // 始点の色レベル
	st_g = 64 ;
	st_b = 64 ;

	sp_r = 128 ; // 終点の色レベル
	sp_g = 255 ;
	sp_b = 64 ;

	bk_r = 64 ; // 背景の色レベル
	bk_g = 128 ;
	bk_b = 255 ;

	SetScrollRange("ID_st_r",255) ; SetScrollPos("ID_st_r",st_r) ;
	SetScrollRange("ID_st_g",255) ; SetScrollPos("ID_st_g",st_g) ;
	SetScrollRange("ID_st_b",255) ; SetScrollPos("ID_st_b",st_b) ;

	SetScrollRange("ID_sp_r",255) ; SetScrollPos("ID_sp_r",sp_r) ;
	SetScrollRange("ID_sp_g",255) ; SetScrollPos("ID_sp_g",sp_g) ;
	SetScrollRange("ID_sp_b",255) ; SetScrollPos("ID_sp_b",sp_b) ;

	SetScrollRange("ID_bk_r",255) ; SetScrollPos("ID_bk_r",bk_r) ;
	SetScrollRange("ID_bk_g",255) ; SetScrollPos("ID_bk_g",bk_g) ;
	SetScrollRange("ID_bk_b",255) ; SetScrollPos("ID_bk_b",bk_b) ;

	SetListText("ID_size","1") ;
	SetListText("ID_size","2") ;
	SetListText("ID_size","3") ;
	SetListText("ID_size","4") ;
	SetListText("ID_size","5") ;
	SetListPos("ID_size",size-1) ;
}
CREATE
{
	SetWinColor(16) ;
	SetWinSize(450,400) ;

	x = 8 ; y = 8 ;
	CreateControl(60,"文字列(全角)","ID",x,y,84,14) ;
	CreateControl(101,"グラデーション文字の作成","ID_buf",x+84,y-2,344,18) ;

	x = 8 ; y = 34 ;
	CreateControl(60,"文字サイズ","ID",x,y,60,16) ;
	CreateControl(33,"","ID_size",x+64,y-2,40,100) ;
	CreateControl(20,"斜体フォント","ID_italic",x+120,y,90,16) ;

	x = 8 ; y = 60 ; w = 128 ; h = 18 ;
	CreateControl(60,"始点色設定","ID",x,y,100,14) ; y = y + 18 ;
	CreateControl(70,"","ID_st_r",x,y,w,h) ; y = y + h + 2 ;
	CreateControl(70,"","ID_st_g",x,y,w,h) ; y = y + h + 2 ;
	CreateControl(70,"","ID_st_b",x,y,w,h) ; y = y + h + 2 ;

	x = 308 ; y = 60 ;
	CreateControl(60,"終点色設定","ID",x,y,100,14) ; y = y + 18 ;
	CreateControl(70,"","ID_sp_r",x,y,w,h) ; y = y + h + 2 ;
	CreateControl(70,"","ID_sp_g",x,y,w,h) ; y = y + h + 2 ;
	CreateControl(70,"","ID_sp_b",x,y,w,h) ; y = y + h + 2 ;

	x = 160 ; y = 60 ;
	CreateControl(60,"背景色設定","ID",x,y,100,14) ; y = y + 18 ;
	CreateControl(70,"","ID_bk_r",x,y,w,h) ; y = y + h + 2 ;
	CreateControl(70,"","ID_bk_g",x,y,w,h) ; y = y + h + 2 ;
	CreateControl(70,"","ID_bk_b",x,y,w,h) ; y = y + h + 2 ;

	x = 316 ; y = 270 ;
	CreateControl(20,"文字部分のみ作成","ID_type",x,y,120,16) ; y = y + 20 ;
	CreateControl(0,"HTMLコード作成","ID_go",x,y,120,20) ; y = y + 50 ;
	CreateControl(0,"← すべてコピー",    "ID_copy",x,y,120,20) ;
	CreateControl(100,"","ID_html",8,270,300,110) ;

	CreateControl(101,"","ID_sub",0,0,0,0) ;
}

// チェックボタン(文字部分のみ作成)
ID_type
{
	if(GetButtonCheck("ID_type") == 0){
		SetButtonCheck("ID_type",1) ; return ;
	}
	if(GetButtonCheck("ID_type") == 1){
		SetButtonCheck("ID_type",0) ; return ;
	}
}
// HTMLコード作成
ID_go
{
	n = GetEditLength("ID_buf") / 2 ;
	if(n <= 0){ return ; }

	AllSelectEdit("ID_html") ; ClearEdit("ID_html") ;

	if(GetButtonCheck("ID_type") == 0){
		SetEditText("ID_html","<HTML>") ;
		SetEditCodeRet("ID_html") ;
		SetEditText("ID_html","<HEAD>") ;
		SetEditCodeRet("ID_html") ;
		SetEditText("ID_html","<TITLE>グラデーションテスト</TITLE>") ;
		SetEditCodeRet("ID_html") ;
		SetEditText("ID_html","</HEAD>") ;
		SetEditCodeRet("ID_html") ;

		SetEditText("ID_html","<BODY BGCOLOR=") ;
		SetEditCode("ID_html",34) ;
		SetEditText("ID_html","#") ;
		if(bk_r < 16){ SetEditText("ID_html","0") ; }
		SetEditData16("ID_html",bk_r) ;
		if(bk_g < 16){ SetEditText("ID_html","0") ; }
		SetEditData16("ID_html",bk_g) ;
		if(bk_b < 16){ SetEditText("ID_html","0") ; }
		SetEditData16("ID_html",bk_b) ;
		SetEditCode("ID_html",34) ;
		SetEditText("ID_html",">") ;

		SetEditCodeRet("ID_html") ;
		SetEditText("ID_html","<BR>") ;
	}
	r = (sp_r-st_r)/n ;
	g = (sp_g-st_g)/n ;
	b = (sp_b-st_b)/n ;

	cr = st_r ;
	cg = st_g ;
	cb = st_b ;

	SetEditCodeRet("ID_html") ;
	if(italic == 1){ SetEditText("ID_html","<I>") ; }

	p = 0 ;
	loop(n){
		SetEditText("ID_html","<FONT FACE=") ;
		SetEditCode("ID_html",34) ;
		SetEditText("ID_html","MS ゴシック") ;
		SetEditCode("ID_html",34) ;
		SetEditText("ID_html"," SIZE=") ;
		SetEditCode("ID_html",34) ;
		SetEditData("ID_html",size,0) ;
		SetEditCode("ID_html",34) ;
		SetEditText("ID_html"," COLOR=") ;
		SetEditCode("ID_html",34) ;
		SetEditText("ID_html","#") ;
		if(cr < 16){ SetEditText("ID_html","0") ; }
		SetEditData16("ID_html",cr) ;
		if(cg < 16){ SetEditText("ID_html","0") ; }
		SetEditData16("ID_html",cg) ;
		if(cb < 16){ SetEditText("ID_html","0") ; }
		SetEditData16("ID_html",cb) ;
		SetEditCode("ID_html",34) ;
		SetEditText("ID_html",">") ;
		GetEditText("ID_buf",p,p+2,"ID_html") ;
		SetEditText("ID_html","</FONT>") ;

		p = p + 2 ;
		cr = cr + r ;
		cg = cg + g ;
		cb = cb + b ;
	}
	if(italic == 1){ SetEditText("ID_html","</I>") ; }
	SetEditText("ID_html","<BR>") ;
	SetEditCodeRet("ID_html") ;

	if(GetButtonCheck("ID_type") == 0){
		SetEditText("ID_html","<BR>") ;
		SetEditCodeRet("ID_html") ;
		SetEditText("ID_html","</BODY></HTML>") ;
		SetEditCodeRet("ID_html") ;
	}
	SetEditCursol("ID_html",0,0) ;
}
// すべてコピー
ID_copy
{
	if(GetEditLength("ID_html") <= 0){ return ; }

	AllSelectEdit("ID_html") ;
	ClipEdit("ID_html") ;
	SetEditCursol("ID_html",0,0) ;
	MessBox("コピーしました  ","すべてコピー",0,2) ;
}