//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::DodajClick(TObject *Sender) { Image1->Height =300; Image1->Width =300; Image2->Height =300; Image2->Width =300; Image1->Canvas->MoveTo((Image1->Width/2),0); Image1->Canvas->LineTo((Image1->Width/2),(Image1->Height)); Image1->Canvas->MoveTo(0,(Image1->Height/2)); Image1->Canvas->LineTo((Image1->Width),(Image1->Height/2)); TPoint points[4]; int x1 = StrToInt(X1->Text)+150; int y1 = -StrToInt(Y1->Text)+150; int x2 = StrToInt(X2->Text)+150; int y2 = -StrToInt(Y2->Text)+150; int x3 = StrToInt(X3->Text)+150; int y3 = -StrToInt(Y3->Text)+150; int x4 = StrToInt(X4->Text)+150; int y4 = -StrToInt(Y4->Text)+150; points[0].x = x1; points[1].x = x2; points[2].x = x3; points[3].x = x4; points[0].y = y1; points[1].y = y2; points[2].y = y3; points[3].y = y4; int x_min = points[0].x; int x_max = points[0].x; int y_min = points[0].y; int y_max = points[0].y; for(int i = 0; i < 4; i++){ x_min = x_min > points[i].x ? points[i].x : x_min; x_max = x_max < points[i].x ? points[i].x : x_max; y_min = y_min > points[i].y ? points[i].y : y_min; y_max = y_max < points[i].y ? points[i].y : y_max; } for(int i =0 ; i < 4; i++) { int x = points[i].x; int y = points[i].y; int r = 1; Image1->Canvas->Pixels[x][y]=clBlack; } float sx = (Image2->Width - 0.0f ) / ( x_max - x_min ); float sy = (Image2->Height - 0.0f ) / ( y_max - y_min ); sx = sx < sy ? sx : sy; sy = sx < sy ? sx : sy; for(int i =0 ; i < 4; i++) { int x = (points[i].x - x_min) * sx; int y = (points[i].y - y_min) * sy; int r = 3; int rx = r * sx; int ry = r * sy; Image2->Canvas->Ellipse(x - rx, y - ry, x + rx, y + ry); } } //---------------------------------------------------------------------------