//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit3.h"
#include <fstream.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
struct Koord{
int x;
int y;
};
const int K=100;
Koord mast[K];
Koord mass[K];
int i=0,maxx,maxy,j,v,v1,k,step=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Image1->Canvas->Brush->Color=clWhite;
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
Edit1->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(v==1){ // рисование многоугольника
if(Shift.Contains(ssLeft)){
mast.x=X;
mast.y=Y;
Image1->Canvas->Brush->Color=clRed;
Image1->Canvas->Ellipse(X-3,Y-3,X+3,Y+3);
i++;}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
StatusBar1->SimpleText="x="+IntToStr(X)+" y="+IntToStr(Y);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N2Click(TObject *Sender)
{
// раздел меню Файл | Открыть
i=0;
if(OpenDialog1->Execute()){
ifstream fin(OpenDialog1->FileName.c_str());
if(!fin){ShowMessage("ERROR!Can't open the file!");}
char s;
int k=0;
while(!fin.eof()){
fin.get(s);
if(s=='\n') k++;}
k=k-1;
Koord *m=new Koord[k];
fin.close();
ifstream fin2(OpenDialog1->FileName.c_str());
if(!fin2){ShowMessage("ERROR!Can't open the file!");}
for(int j=0;j<k;j++){
fin2>>m[j].x>>m[j].y;
}
fin2.close();
for(int j=0;j<k;j++){
Image1->Canvas->Brush->Color=clRed;
Image1->Canvas->Ellipse(m[j].x-3,m[j].y-3,m[j].x+3,m[j].y+3);
i++;
}
for(int j=0;j<i-1;j++){
Image1->Canvas->Pen->Color=(ColorDialog1->Color);
Image1->Canvas->MoveTo(m[j].x,m[j].y);
Image1->Canvas->LineTo(m[j+1].x,m[j+1].y);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N3Click(TObject *Sender)
{
// раздел меню Файл | Сохранить
if(SaveDialog1->Execute()){
ofstream fout(SaveDialog1->FileName.c_str());
if(!fout){ShowMessage("ERROR!");}
for(int j=0;j<i;j++){
fout<<mast[j].x<<" "<<mast[j].y<<"\n";
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Click(TObject *Sender)
{
// раздел меню Файл | Выход
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N7Click(TObject *Sender)
{
// раздел меню Файл | Очистить всё
Image1->Canvas->Brush->Color=clWhite;
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
j=0;i=0;v1=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N9Click(TObject *Sender)
{
// раздел меню Инструменты | Выбор цвета
ColorDialog1->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N10Click(TObject *Sender)
{
// раздел меню О программе
Form3->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N13Click(TObject *Sender)
{
// раздел меню Инструменты | Многоугольник
v=1;
Image1->Canvas->Brush->Color=clWhite;
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N11Click(TObject *Sender)
{
// раздел меню Инструменты | Сдвиг
Image1->Canvas->Brush->Color=clWhite;
Image1->Canvas->FillRect(Rect(0,0,Image1->Width,Image1->Height));
step=0;
step=step+StrToInt(Edit1->Text);
//if(!isdigit(k)){ShowMessage("Введите шаг!");}
//if(Shift.Contains(ssLeft)){
//mast.x=X;
//mast.y=Y;
for(int j=0;j<i;j++){
Image1->Canvas->Brush->Color=clRed;
Image1->Canvas->Ellipse(mast[j].x-3+step,mast[j].y-3,mast[j].x+3+step,mast[j].y+3);
}
if(i>0){
for(int j=0;j<i-1;j++){
Image1->Canvas->Pen->Color=(ColorDialog1->Color);
Image1->Canvas->MoveTo(mast[j].x+step,mast[j].y);
Image1->Canvas->LineTo(mast[j+1].x+step,mast[j+1].y);
}
}
Image1->Canvas->MoveTo(mast[i-1].x+step,mast[i-1].y);
Image1->Canvas->LineTo(mast[0].x+step,mast[0].y);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N12Click(TObject *Sender)
{
// раздел меню Инструменты | Симметричное отображение
int delta=50+step;
Image1->Canvas->Pen->Color=clRed;
Image1->Canvas->Pen->Width=1;
maxx=mast[0].x;
maxy=mast[0].y;
for(int j=0;j<i;j++){
if(mast[j].x>maxx){maxx=mast[j].x;
maxy=mast[j].y;} }
Image1->Canvas->MoveTo(maxx+delta,maxy);
Image1->Canvas->LineTo(maxx+delta,Image1->Height);
Image1->Canvas->MoveTo(maxx+delta,maxy);
Image1->Canvas->LineTo(maxx+delta,0);
//Image1->Canvas->MoveTo(maxx+2*delta,maxy);
//Image1->Canvas->Brush->Color=clRed;
//Image1->Canvas->Ellipse(maxx-3+2*delta,maxy-3,maxx+3+2*delta,maxy+3);
if(i>0){
for(int j=0;j<i;j++){
int dx=abs(maxx-mast[j].x)+delta;
mass[j].x=mast[j].x+2*dx;
mass[j].y=mast[j].y;
Image1->Canvas->Ellipse(mast[j].x-3+2*dx,mast[j].y-3,mast[j].x+3+2*dx,mast[j].y+3);
Image1->Canvas->Brush->Color=clRed;
Image1->Canvas->Pen->Color=(ColorDialog1->Color);
if(j==0){
Image1->Canvas->MoveTo(mass[j].x,mass[j].y); }
else{
Image1->Canvas->LineTo(mass[j].x,mass[j].y);
Image1->Canvas->MoveTo(mass[j].x,mass[j].y);}
}
}
Image1->Canvas->LineTo(mass[0].x,mass[0].y);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(i>0){
for(int j=0;j<i-1;j++){
Image1->Canvas->Pen->Color=(ColorDialog1->Color);
Image1->Canvas->MoveTo(mast[j].x,mast[j].y);
Image1->Canvas->LineTo(mast[j+1].x,mast[j+1].y);
}}
Image1->Canvas->LineTo(mast[0].x,mast[0].y); }
//---------------------------------------------------------------------------