//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner),FKolor1(clYellow),FKolor2(clFuchsia)
{
}
//---------------------------------------------------------------------------

TColor TForm1::ObliczKolor(int i)
{
	int H=ClientHeight;

	byte Red1=GetRValue(FKolor1);
	byte Green1=GetGValue(FKolor1);
	byte Blue1=GetBValue(FKolor1);
	byte Red2=GetRValue(FKolor2);
	byte Green2=GetGValue(FKolor2);
	byte Blue2=GetBValue(FKolor2);

	if (i<0 || i>H) return clNone;
	return (TColor)RGB(
	  Red1+i*(Red2-Red1)/H,
	  Green1+i*(Green2-Green1)/H,
	  Blue1+i*(Blue2-Blue1)/H);
}

//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
	for(int i=0;i<ClientHeight;i++)
	{
		Canvas->Pen->Color=ObliczKolor(i);
		Canvas->MoveTo(0,i);
		Canvas->LineTo(ClientWidth,i);
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	/*TColor* pKolor;
	if (Sender==Button1) pKolor=&FKolor1; else pKolor=&FKolor2;
	ColorDialog1->Color=*pKolor;
	if (ColorDialog1->Execute()) *pKolor=ColorDialog1->Color;
	Refresh();*/

	bool warunek=Sender==Button1;
	ColorDialog1->Color=warunek?FKolor1:FKolor2;
	if (ColorDialog1->Execute()) (warunek?FKolor1:FKolor2)=ColorDialog1->Color;
	Refresh();
}
//---------------------------------------------------------------------------
