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

#include <vcl.h>
#include <math.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int array[17];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
void compute(void)
{
for(int i=0;i<4;i++)                 //start
        {
        array[i]=0;
        }
array[14]=1;                        //stop
array[15]=0;
array[16]=0;
int offset=0;
switch(StrToInt(Form1->Edit3->Text)/10)
        {
        case 0:
                array[offset+4]=0;
                array[offset+6]=0;
                array[offset+8]=1;
                array[offset+10]=1;
                array[offset+12]=0;
                break;
        case 1:
                array[offset+4]=1;
                array[offset+6]=0;
                array[offset+8]=0;
                array[offset+10]=0;
                array[offset+12]=1;
                break;
        case 2:
                array[offset+4]=0;
                array[offset+6]=1;
                array[offset+8]=0;
                array[offset+10]=0;
                array[offset+12]=1;
                break;
        case 3:
                array[offset+4]=1;
                array[offset+6]=1;
                array[offset+8]=0;
                array[offset+10]=0;
                array[offset+12]=0;
                break;
        case 4:
                array[offset+4]=0;
                array[offset+6]=0;
                array[offset+8]=1;
                array[offset+10]=0;
                array[offset+12]=1;
                break;
        case 5:
                array[offset+4]=1;
                array[offset+6]=0;
                array[offset+8]=1;
                array[offset+10]=0;
                array[offset+12]=0;
                break;
        case 6:
                array[offset+4]=0;
                array[offset+6]=1;
                array[offset+8]=1;
                array[offset+10]=0;
                array[offset+12]=0;
                break;
        case 7:
                array[offset+4]=0;
                array[offset+6]=0;
                array[offset+8]=0;
                array[offset+10]=1;
                array[offset+12]=1;
                break;
        case 8:
                array[offset+4]=1;
                array[offset+6]=0;
                array[offset+8]=0;
                array[offset+10]=1;
                array[offset+12]=0;
                break;
        case 9:
                array[offset+4]=0;
                array[offset+6]=1;
                array[offset+8]=0;
                array[offset+10]=1;
                array[offset+12]=0;
                break;
        }
offset=1;
switch(StrToInt(Form1->Edit3->Text)%10)
        {
        case 0:
                array[offset+4]=0;
                array[offset+6]=0;
                array[offset+8]=1;
                array[offset+10]=1;
                array[offset+12]=0;
                break;
        case 1:
                array[offset+4]=1;
                array[offset+6]=0;
                array[offset+8]=0;
                array[offset+10]=0;
                array[offset+12]=1;
                break;
        case 2:
                array[offset+4]=0;
                array[offset+6]=1;
                array[offset+8]=0;
                array[offset+10]=0;
                array[offset+12]=1;
                break;
        case 3:
                array[offset+4]=1;
                array[offset+6]=1;
                array[offset+8]=0;
                array[offset+10]=0;
                array[offset+12]=0;
                break;
        case 4:
                array[offset+4]=0;
                array[offset+6]=0;
                array[offset+8]=1;
                array[offset+10]=0;
                array[offset+12]=1;
                break;
        case 5:
                array[offset+4]=1;
                array[offset+6]=0;
                array[offset+8]=1;
                array[offset+10]=0;
                array[offset+12]=0;
                break;
        case 6:
                array[offset+4]=0;
                array[offset+6]=1;
                array[offset+8]=1;
                array[offset+10]=0;
                array[offset+12]=0;
                break;
        case 7:
                array[offset+4]=0;
                array[offset+6]=0;
                array[offset+8]=0;
                array[offset+10]=1;
                array[offset+12]=1;
                break;
        case 8:
                array[offset+4]=1;
                array[offset+6]=0;
                array[offset+8]=0;
                array[offset+10]=1;
                array[offset+12]=0;
                break;
        case 9:
                array[offset+4]=0;
                array[offset+6]=1;
                array[offset+8]=0;
                array[offset+10]=1;
                array[offset+12]=0;
                break;
        }

}


void redraw(void)
{
Form1->Image1->Picture=NULL;
Form1->Edit1->Text=Form1->TrackBar3->Position*(12+floor((StrToInt(Form1->ComboBox1->Text)+5)/10)*5);


compute();
int cX=0;      //kurzor
int cY=(Form1->Image1->Height-Form1->TrackBar2->Position)/2;
//Form1->Image1->Canvas->Pen

for(int i=0;i<17;i++)
        {
        if(i%2)
                {
                if(Form1->CheckBox2->Checked)
                        {
                        Form1->Image1->Canvas->Pen->Color=0xFFFFFF;
                        }
                else
                        {
                        Form1->Image1->Canvas->Pen->Color=0;
                        }
                }
        else
                {
                if(Form1->CheckBox2->Checked)
                        {
                        Form1->Image1->Canvas->Pen->Color=0;
                        }
                else
                        {
                        Form1->Image1->Canvas->Pen->Color=0xFFFFFF;
                        }

                }
        if(array[i])
                {
                Form1->Image1->Canvas->Rectangle(cX,cY,cX+Form1->TrackBar3->Position*StrToInt(Form1->ComboBox1->Text)/10,cY+Form1->TrackBar2->Position);
                cX=cX+Form1->TrackBar3->Position*StrToInt(Form1->ComboBox1->Text)/10;
                }
        else
                {
                Form1->Image1->Canvas->Rectangle(cX,cY,cX+Form1->TrackBar3->Position,cY+Form1->TrackBar2->Position);
                cX=cX+Form1->TrackBar3->Position;
                }
        }


}


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

void __fastcall TForm1::Button1Click(TObject *Sender)
{
//Image1->Canvas->Ellipse(5,5,20,20);
char name[50]="";
strcat(name,"Krizovatka_");
strcat(name,Edit3->Text.c_str());
strcat(name,".bmp");
Image1->Picture->SaveToFile(name);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
if(Edit1->Text>0 && Edit1->Text<999)
        {
        Image1->Width=StrToInt(Edit1->Text);
        redraw();
        }
else
        {
        ShowMessage("Spatne zadany rozmer");
        Edit1->Text=320;
        }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit2Change(TObject *Sender)
{
if(Edit2->Text>0 && Edit2->Text<999)
        {
        Image1->Height=StrToInt(Edit2->Text);
        redraw();
        }
else
        {
        ShowMessage("Spatne zadany rozmer");
        Edit2->Text=240;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit3Change(TObject *Sender)
{
if(!Edit3->Text.IsEmpty())
        {
        redraw();
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrackBar2Change(TObject *Sender)
{
Edit2->Text=TrackBar2->Position+20;
redraw();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrackBar3Change(TObject *Sender)
{
redraw();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
redraw();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
redraw();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
Edit1->Text=TrackBar3->Position*(12+floor((StrToInt(ComboBox1->Text)+5)/10)*5);
redraw();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox2Click(TObject *Sender)
{
redraw();
}
//---------------------------------------------------------------------------

