我
我不是专家
Unregistered / Unconfirmed
GUEST, unregistred user!
class YObjects
{
public:
YObject *head,*tail;
YObjects(){head=tail=NULL;}
~YObjects(){DeleteAll();}
void Add(YObject *obj);
void Delete(YObject *obj);
void Delete(int index);
void DeleteAll();
void UnSelectAll();
void SelectAll();
void MoveToBottom(YObject *obj);
void MoveToFront(YObject *obj){};
void Draw();
void Save(String path);
YObject *WhoIsIt(int x,int y);
virtual void LeftPressed(int X,int Y);
virtual void MouseMoved(int X,int Y);
virtual void LeftReleased(int X,int Y);
};
///////////
class YObject
{
protected:
int sx,sy;
public:
static bool needredraw;
static int originx,originy;
int X,Y;
bool selected,pressed;
enum YWHICHBOX which;
TCanvas *canvas;
YObject *next,*prior;
YObject(){X=Y=0;next=prior=NULL;canvas=NULL;selected=false;pressed=false;}
virtual void Draw();
virtual String Save();
virtual void DrawFocus(){};
virtual bool IsMe(int x,int y){return false;}
virtual enum YWHICHBOX InWhichBox(int x,int y);
virtual void MoveTo(int x,int y);
virtual void Move(int dx,int dy);
static bool IsInBox(int x,int y,int left,int top,int width,int height);
virtual void LeftPressed(int X,int Y){};
virtual void MouseMoved(int X,int Y){};
virtual void LeftReleased(int X,int Y){};
};
bool YObject::needredraw=false;
int YObject:riginx=0;
int YObject:: originy=0;
void YObject::MoveTo(int x,int y)
{
X=x;Y=y;
}
void YObject::Move(int dx,int dy)
{
X+=dx;Y+=dy;
}
String YObject::Save()
{
return "NULL";
}
enum YWHICHBOX YObject::InWhichBox(int x,int y)
{
return EXTE;
}
bool YObject::IsInBox(int x,int y,int left,int top,int width,int height)
{
return x>=left && x<=left+width && y>=top && y<=top+height;
}
void YObject:raw()
{
if(canvas==NULL) return;
if(selected) DrawFocus();
//canvas->TextOutA(X,Y,"obj"
}
class YLineublic YObject
{
public:
int EX,EY;
YLine(){EX=EY=10;}
void Draw();
String Save();
void DrawFocus();
void Move(int dx,int dy);
void MoveTo(int x,int y);
bool IsMe(int x,int y);
enum YWHICHBOX InWhichBox(int x,int y);
virtual void LeftPressed(int X,int Y);
virtual void MouseMoved(int X,int Y);
virtual void LeftReleased(int X,int Y);
};
String YLine::Save()
{
String str;
str="L|"+IntToStr(X)+"|";
str=str+IntToStr(Y)+"|";
str=str+IntToStr(EX)+"|";
str=str+IntToStr(EY);
return str;
}
void YLine:raw()
{
if(canvas==NULL) return;
YObject:raw();
canvas->MoveTo(X,Y);
canvas->LineTo(EX,EY);
}
void YLine:rawFocus()
{
int d=RECTLETW,w,h;
if(canvas==NULL) return;
canvas->Rectangle(X-d,Y-d,X+d,Y+d);
w=(EX-X)/2;h=(EY-Y)/2;
canvas->Rectangle(X+w-d,Y+h-d,X+w+d,Y+h+d);
canvas->Rectangle(EX-d,EY-d,EX+d,EY+d);
}
enum YWHICHBOX YLine::InWhichBox(int x,int y)
{
int d=RECTLETW,w,h;
w=(EX-X);h=(EY-Y);
if(IsInBox(x,y,X-d,Y-d,2*d,2*d)) return LT;
if(IsInBox(x,y,X+w/2-d,Y+h/2-d,2*d,2*d)) return MT;
if(IsInBox(x,y,X+w-d,Y+h-d,2*d,2*d)) return RB;
return EXTE;
}
void YLine::LeftPressed(int X,int Y)
{
pressed=true;
sx=X;sy=Y;
if(!selected){
if(IsMe(X,Y)) selected=true;
}
if(selected){
which=InWhichBox(X,Y);
if(which==EXTE) selected=false;
}
}
void YLine::MouseMoved(int x,int y)
{
if(!pressed) return;
if(selected){
switch(which)
{
case LT:
X+=x-sx;Y+=y-sy;
sx=x;sy=y;
needredraw=true;
break;
case MT:
X+=x-sx;Y+=y-sy;
EX+=x-sx;EY+=y-sy;
sx=x;sy=y;
needredraw=true;
break;
case RB:
EX+=x-sx;EY+=y-sy;
sx=x;sy=y;
needredraw=true;
break;
}
}
}
void YLine::LeftReleased(int X,int Y)
{
pressed=false;
}
void YLine::Move(int dx,int dy)
{
X+=dx;Y+=dy;
EX+=dx;EY+=dy;
}
void YLine::MoveTo(int x,int y)
{
int dx,dy;
dx=x-X;dy=y-Y;
Move(dx,dy);
}
bool YLine::IsMe(int x,int y)
{
int d=RECTLETW;
if(x>=X-d && x<=X+d && y>=Y-d && y<=Y+d) return true;
if(x>=EX-d && x<=EX+d && y>=EY-d && y<=EY+d) return true;
return false;
}
class YRectangleublic YObject
{
public:
int width,height;
YRectangle(){width=10;height=10;}
void Draw();
void DrawFocus();
String Save();
enum YWHICHBOX InWhichBox(int x,int y);
bool IsMe(int x,int y){return (x>=X && x<=X+width && y>=Y && y<=Y+height);}
virtual void LeftPressed(int X,int Y);
virtual void MouseMoved(int X,int Y);
virtual void LeftReleased(int X,int Y);
};
class YEllipseublic YRectangle
{
public:
void Draw();
};
void YRectangle:raw()
{
if(canvas==NULL) return;
YObject:raw();
canvas->Rectangle(X+originx,Y+originy,X+originx+width,Y+originy+height);
}
String YRectangle::Save()
{
String str;
str="R|"+IntToStr(X)+"|";
str=str+IntToStr(Y)+"|";
str=str+IntToStr(width)+"|";
str=str+IntToStr(height);
return str;
}
void YRectangle:rawFocus()
{
int d=RECTLETW;
int w=width,h=height;
int x=X+originx,y=Y+originy;
if(canvas==NULL) return;
canvas->Rectangle(x-d,y-d,x+d,y+d);
canvas->Rectangle(x+w/2-d,y-d,x+w/2+d,y+d);
canvas->Rectangle(x+w-d,y-d,x+w+d,y+d);
canvas->Rectangle(x+w-d,y+h/2-d,x+w+d,y+h/2+d);
canvas->Rectangle(x+w-d,y+h-d,x+w+d,y+h+d);
canvas->Rectangle(x+w/2-d,y+h-d,x+w/2+d,y+h+d);
canvas->Rectangle(x-d,y+h-d,x+d,y+h+d);
canvas->Rectangle(x-d,y+h/2-d,x+d,y+h/2+d);
}
enum YWHICHBOX YRectangle::InWhichBox(int x,int y)
{
int d=RECTLETW;
int w=width,h=height;
if(IsInBox(x,y,X-d,Y-d,2*d,2*d)) return LT;
if(IsInBox(x,y,X+w/2-d,Y-d,2*d,2*d)) return MT;
if(IsInBox(x,y,X+w-d,Y-d,2*d,2*d)) return RT;
if(IsInBox(x,y,X+w-d,Y+h/2-d,2*d,2*d)) return RM;
if(IsInBox(x,y,X+w-d,Y+h-d,2*d,2*d)) return RB;
if(IsInBox(x,y,X+w/2-d,Y+h-d,2*d,2*d)) return MB;
if(IsInBox(x,y,X-d,Y+h-d,2*d,2*d)) return LB;
if(IsInBox(x,y,X-d,Y+h/2-d,2*d,2*d)) return LM;
if(IsInBox(x,y,X,Y,w,h)) return INNER;
return EXTE;
}
void YRectangle::LeftPressed(int X,int Y)
{
pressed=true;
sx=X;sy=Y;
if(!selected){
if(IsMe(X,Y)) selected=true;
}
if(selected){
which=InWhichBox(X,Y);
if(which==EXTE) selected=false;
}
}
void YRectangle::MouseMoved(int x,int y)
{
if(!pressed) return;
if(selected){
int dx,dy;
dx=x-sx;dy=y-sy;
switch(which)
{
case LT:
width-=dx;height-=dy;
X=x;Y=y;
sx=x;sy=y;
needredraw=true;
break;
case MT:
height-=dy;Y=y;
sx=x;sy=y;
needredraw=true;
break;
case RT:
width+=dx;height-=dy;
Y=y;
sx=x;sy=y;
needredraw=true;
break;
case RM:
width+=dx;
sx=x;sy=y;
needredraw=true;
break;
case RB:
width+=dx;height+=dy;
sx=x;sy=y;
needredraw=true;
break;
case MB:
height+=dy;
sx=x;sy=y;
needredraw=true;
break;
case LB:
width-=dx;height+=dy;
X=x;
sx=x;sy=y;
needredraw=true;
break;
case LM:
width-=dx;X=x;
sx=x;sy=y;
needredraw=true;
break;
case INNER:
Move(dx,dy);
sx=x;sy=y;
needredraw=true;
break;
}
}
}
void YRectangle::LeftReleased(int X,int Y)
{
pressed=false;
}
void YEllipse:raw()
{
if(canvas==NULL) return;
if(selected){
YRectangle:raw();
}
canvas->Ellipse(X,Y,X+width,Y+height);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void __fastcall TForm1:aintMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int x,y;
x=X-YObject:riginx;y=Y-YObject:riginy;
if(RBrect->Checked){
YRectangle *p=new YRectangle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBcircle->Checked){
YCircle *p=new YCircle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBellipse->Checked){
YEllipse *p=new YEllipse();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBline->Checked)
{
YLine *p=new YLine();
p->X=x;p->Y=y;p->EX=x+10;p->EY=y+10;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBselect->Checked){
myobjs.LeftPressed(x,y);
}
if(RBdelete->Checked){
YObject *p=myobjs.WhoIsIt(x,y);
if(p!=NULL) myobjs.Delete(p);
}
Paint->Invalidate();
}
void __fastcall TForm1:aintMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
myobjs.MouseMoved(X-YObject:riginx,Y-YObject:riginy);
if(YObject::needredraw){
Paint->Invalidate();
YObject::needredraw=false;
}
}
void __fastcall TForm1:aintMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
myobjs.LeftReleased(X-YObject:riginx,Y-YObject:riginy);
}
void __fastcall TForm1:aintPaint(TObject *Sender)
{
myobjs.Draw();
}
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
YObject:riginx=-ScrollBar1->Position;
Paint->Invalidate();
}
void __fastcall TForm1::ScrollBar2Change(TObject *Sender)
{
YObject:riginy=-ScrollBar2->Position;
Paint->Invalidate();
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
String path; char * str; int i;
TStringList * T =new TStringList();
TStringList * Temp =new TStringList();
path=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.DeleteAll();
T->LoadFromFile(path);
for (i=0;i<T->Count ;i++)
{
str=T->Strings.c_str() ;
if (str[0]=='L'){
YLine *p=new YLine();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->EX=Temp->Strings[3].ToInt();
p->EY=Temp->Strings[4].ToInt();
myobjs.Add(p);
}
if(str[0]=='C'){
YCircle *p=new YCircle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->radius=Temp->Strings[3].ToInt();
myobjs.Add(p);
}
if(str[0]=='R')
{
YRectangle *p=new YRectangle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(str[0]=='E')
{
YEllipse *p=new YEllipse();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
}
Temp->Free();
T->Free();
myobjs.Draw() ;
ShowMessage("打开成功!"
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
String str; str=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.Save(str); }
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
Close();
}
void __fastcall TForm1:aintMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int x,y;
x=X-YObject:riginx;y=Y-YObject:riginy;
if(RBrect->Checked){
YRectangle *p=new YRectangle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBcircle->Checked){
YCircle *p=new YCircle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBellipse->Checked){
YEllipse *p=new YEllipse();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBline->Checked)
{
YLine *p=new YLine();
p->X=x;p->Y=y;p->EX=x+10;p->EY=y+10;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBselect->Checked){
myobjs.LeftPressed(x,y);
}
if(RBdelete->Checked){
YObject *p=myobjs.WhoIsIt(x,y);
if(p!=NULL) myobjs.Delete(p);
}
Paint->Invalidate();
}
void __fastcall TForm1:aintMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
myobjs.MouseMoved(X-YObject:riginx,Y-YObject:riginy);
if(YObject::needredraw){
Paint->Invalidate();
YObject::needredraw=false;
}
}
void __fastcall TForm1:aintMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
myobjs.LeftReleased(X-YObject:riginx,Y-YObject:riginy);
}
void __fastcall TForm1:aintPaint(TObject *Sender)
{
myobjs.Draw();
}
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
YObject:riginx=-ScrollBar1->Position;
Paint->Invalidate();
}
void __fastcall TForm1::ScrollBar2Change(TObject *Sender)
{
YObject:riginy=-ScrollBar2->Position;
Paint->Invalidate();
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
String path;
char * str;
int i;
TStringList * T =new TStringList();
TStringList * Temp =new TStringList();
path=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.DeleteAll();
T->LoadFromFile(path);
for (i=0;i<T->Count ;i++)
{
str=T->Strings.c_str() ;
if (str[0]=='L'){
YLine *p=new YLine();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->EX=Temp->Strings[3].ToInt();
p->EY=Temp->Strings[4].ToInt();
myobjs.Add(p);
}
if(str[0]=='C'){
YCircle *p=new YCircle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->radius=Temp->Strings[3].ToInt();
myobjs.Add(p);
}
if(str[0]=='R')
{
YRectangle *p=new YRectangle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(str[0]=='E')
{
YEllipse *p=new YEllipse();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
}
Temp->Free(); T->Free(); myobjs.Draw() ;}
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
String str;
str=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.Save(str);
}
{
public:
YObject *head,*tail;
YObjects(){head=tail=NULL;}
~YObjects(){DeleteAll();}
void Add(YObject *obj);
void Delete(YObject *obj);
void Delete(int index);
void DeleteAll();
void UnSelectAll();
void SelectAll();
void MoveToBottom(YObject *obj);
void MoveToFront(YObject *obj){};
void Draw();
void Save(String path);
YObject *WhoIsIt(int x,int y);
virtual void LeftPressed(int X,int Y);
virtual void MouseMoved(int X,int Y);
virtual void LeftReleased(int X,int Y);
};
///////////
class YObject
{
protected:
int sx,sy;
public:
static bool needredraw;
static int originx,originy;
int X,Y;
bool selected,pressed;
enum YWHICHBOX which;
TCanvas *canvas;
YObject *next,*prior;
YObject(){X=Y=0;next=prior=NULL;canvas=NULL;selected=false;pressed=false;}
virtual void Draw();
virtual String Save();
virtual void DrawFocus(){};
virtual bool IsMe(int x,int y){return false;}
virtual enum YWHICHBOX InWhichBox(int x,int y);
virtual void MoveTo(int x,int y);
virtual void Move(int dx,int dy);
static bool IsInBox(int x,int y,int left,int top,int width,int height);
virtual void LeftPressed(int X,int Y){};
virtual void MouseMoved(int X,int Y){};
virtual void LeftReleased(int X,int Y){};
};
bool YObject::needredraw=false;
int YObject:riginx=0;
int YObject:: originy=0;
void YObject::MoveTo(int x,int y)
{
X=x;Y=y;
}
void YObject::Move(int dx,int dy)
{
X+=dx;Y+=dy;
}
String YObject::Save()
{
return "NULL";
}
enum YWHICHBOX YObject::InWhichBox(int x,int y)
{
return EXTE;
}
bool YObject::IsInBox(int x,int y,int left,int top,int width,int height)
{
return x>=left && x<=left+width && y>=top && y<=top+height;
}
void YObject:raw()
{
if(canvas==NULL) return;
if(selected) DrawFocus();
//canvas->TextOutA(X,Y,"obj"
}
class YLineublic YObject
{
public:
int EX,EY;
YLine(){EX=EY=10;}
void Draw();
String Save();
void DrawFocus();
void Move(int dx,int dy);
void MoveTo(int x,int y);
bool IsMe(int x,int y);
enum YWHICHBOX InWhichBox(int x,int y);
virtual void LeftPressed(int X,int Y);
virtual void MouseMoved(int X,int Y);
virtual void LeftReleased(int X,int Y);
};
String YLine::Save()
{
String str;
str="L|"+IntToStr(X)+"|";
str=str+IntToStr(Y)+"|";
str=str+IntToStr(EX)+"|";
str=str+IntToStr(EY);
return str;
}
void YLine:raw()
{
if(canvas==NULL) return;
YObject:raw();
canvas->MoveTo(X,Y);
canvas->LineTo(EX,EY);
}
void YLine:rawFocus()
{
int d=RECTLETW,w,h;
if(canvas==NULL) return;
canvas->Rectangle(X-d,Y-d,X+d,Y+d);
w=(EX-X)/2;h=(EY-Y)/2;
canvas->Rectangle(X+w-d,Y+h-d,X+w+d,Y+h+d);
canvas->Rectangle(EX-d,EY-d,EX+d,EY+d);
}
enum YWHICHBOX YLine::InWhichBox(int x,int y)
{
int d=RECTLETW,w,h;
w=(EX-X);h=(EY-Y);
if(IsInBox(x,y,X-d,Y-d,2*d,2*d)) return LT;
if(IsInBox(x,y,X+w/2-d,Y+h/2-d,2*d,2*d)) return MT;
if(IsInBox(x,y,X+w-d,Y+h-d,2*d,2*d)) return RB;
return EXTE;
}
void YLine::LeftPressed(int X,int Y)
{
pressed=true;
sx=X;sy=Y;
if(!selected){
if(IsMe(X,Y)) selected=true;
}
if(selected){
which=InWhichBox(X,Y);
if(which==EXTE) selected=false;
}
}
void YLine::MouseMoved(int x,int y)
{
if(!pressed) return;
if(selected){
switch(which)
{
case LT:
X+=x-sx;Y+=y-sy;
sx=x;sy=y;
needredraw=true;
break;
case MT:
X+=x-sx;Y+=y-sy;
EX+=x-sx;EY+=y-sy;
sx=x;sy=y;
needredraw=true;
break;
case RB:
EX+=x-sx;EY+=y-sy;
sx=x;sy=y;
needredraw=true;
break;
}
}
}
void YLine::LeftReleased(int X,int Y)
{
pressed=false;
}
void YLine::Move(int dx,int dy)
{
X+=dx;Y+=dy;
EX+=dx;EY+=dy;
}
void YLine::MoveTo(int x,int y)
{
int dx,dy;
dx=x-X;dy=y-Y;
Move(dx,dy);
}
bool YLine::IsMe(int x,int y)
{
int d=RECTLETW;
if(x>=X-d && x<=X+d && y>=Y-d && y<=Y+d) return true;
if(x>=EX-d && x<=EX+d && y>=EY-d && y<=EY+d) return true;
return false;
}
class YRectangleublic YObject
{
public:
int width,height;
YRectangle(){width=10;height=10;}
void Draw();
void DrawFocus();
String Save();
enum YWHICHBOX InWhichBox(int x,int y);
bool IsMe(int x,int y){return (x>=X && x<=X+width && y>=Y && y<=Y+height);}
virtual void LeftPressed(int X,int Y);
virtual void MouseMoved(int X,int Y);
virtual void LeftReleased(int X,int Y);
};
class YEllipseublic YRectangle
{
public:
void Draw();
};
void YRectangle:raw()
{
if(canvas==NULL) return;
YObject:raw();
canvas->Rectangle(X+originx,Y+originy,X+originx+width,Y+originy+height);
}
String YRectangle::Save()
{
String str;
str="R|"+IntToStr(X)+"|";
str=str+IntToStr(Y)+"|";
str=str+IntToStr(width)+"|";
str=str+IntToStr(height);
return str;
}
void YRectangle:rawFocus()
{
int d=RECTLETW;
int w=width,h=height;
int x=X+originx,y=Y+originy;
if(canvas==NULL) return;
canvas->Rectangle(x-d,y-d,x+d,y+d);
canvas->Rectangle(x+w/2-d,y-d,x+w/2+d,y+d);
canvas->Rectangle(x+w-d,y-d,x+w+d,y+d);
canvas->Rectangle(x+w-d,y+h/2-d,x+w+d,y+h/2+d);
canvas->Rectangle(x+w-d,y+h-d,x+w+d,y+h+d);
canvas->Rectangle(x+w/2-d,y+h-d,x+w/2+d,y+h+d);
canvas->Rectangle(x-d,y+h-d,x+d,y+h+d);
canvas->Rectangle(x-d,y+h/2-d,x+d,y+h/2+d);
}
enum YWHICHBOX YRectangle::InWhichBox(int x,int y)
{
int d=RECTLETW;
int w=width,h=height;
if(IsInBox(x,y,X-d,Y-d,2*d,2*d)) return LT;
if(IsInBox(x,y,X+w/2-d,Y-d,2*d,2*d)) return MT;
if(IsInBox(x,y,X+w-d,Y-d,2*d,2*d)) return RT;
if(IsInBox(x,y,X+w-d,Y+h/2-d,2*d,2*d)) return RM;
if(IsInBox(x,y,X+w-d,Y+h-d,2*d,2*d)) return RB;
if(IsInBox(x,y,X+w/2-d,Y+h-d,2*d,2*d)) return MB;
if(IsInBox(x,y,X-d,Y+h-d,2*d,2*d)) return LB;
if(IsInBox(x,y,X-d,Y+h/2-d,2*d,2*d)) return LM;
if(IsInBox(x,y,X,Y,w,h)) return INNER;
return EXTE;
}
void YRectangle::LeftPressed(int X,int Y)
{
pressed=true;
sx=X;sy=Y;
if(!selected){
if(IsMe(X,Y)) selected=true;
}
if(selected){
which=InWhichBox(X,Y);
if(which==EXTE) selected=false;
}
}
void YRectangle::MouseMoved(int x,int y)
{
if(!pressed) return;
if(selected){
int dx,dy;
dx=x-sx;dy=y-sy;
switch(which)
{
case LT:
width-=dx;height-=dy;
X=x;Y=y;
sx=x;sy=y;
needredraw=true;
break;
case MT:
height-=dy;Y=y;
sx=x;sy=y;
needredraw=true;
break;
case RT:
width+=dx;height-=dy;
Y=y;
sx=x;sy=y;
needredraw=true;
break;
case RM:
width+=dx;
sx=x;sy=y;
needredraw=true;
break;
case RB:
width+=dx;height+=dy;
sx=x;sy=y;
needredraw=true;
break;
case MB:
height+=dy;
sx=x;sy=y;
needredraw=true;
break;
case LB:
width-=dx;height+=dy;
X=x;
sx=x;sy=y;
needredraw=true;
break;
case LM:
width-=dx;X=x;
sx=x;sy=y;
needredraw=true;
break;
case INNER:
Move(dx,dy);
sx=x;sy=y;
needredraw=true;
break;
}
}
}
void YRectangle::LeftReleased(int X,int Y)
{
pressed=false;
}
void YEllipse:raw()
{
if(canvas==NULL) return;
if(selected){
YRectangle:raw();
}
canvas->Ellipse(X,Y,X+width,Y+height);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void __fastcall TForm1:aintMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int x,y;
x=X-YObject:riginx;y=Y-YObject:riginy;
if(RBrect->Checked){
YRectangle *p=new YRectangle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBcircle->Checked){
YCircle *p=new YCircle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBellipse->Checked){
YEllipse *p=new YEllipse();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBline->Checked)
{
YLine *p=new YLine();
p->X=x;p->Y=y;p->EX=x+10;p->EY=y+10;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBselect->Checked){
myobjs.LeftPressed(x,y);
}
if(RBdelete->Checked){
YObject *p=myobjs.WhoIsIt(x,y);
if(p!=NULL) myobjs.Delete(p);
}
Paint->Invalidate();
}
void __fastcall TForm1:aintMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
myobjs.MouseMoved(X-YObject:riginx,Y-YObject:riginy);
if(YObject::needredraw){
Paint->Invalidate();
YObject::needredraw=false;
}
}
void __fastcall TForm1:aintMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
myobjs.LeftReleased(X-YObject:riginx,Y-YObject:riginy);
}
void __fastcall TForm1:aintPaint(TObject *Sender)
{
myobjs.Draw();
}
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
YObject:riginx=-ScrollBar1->Position;
Paint->Invalidate();
}
void __fastcall TForm1::ScrollBar2Change(TObject *Sender)
{
YObject:riginy=-ScrollBar2->Position;
Paint->Invalidate();
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
String path; char * str; int i;
TStringList * T =new TStringList();
TStringList * Temp =new TStringList();
path=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.DeleteAll();
T->LoadFromFile(path);
for (i=0;i<T->Count ;i++)
{
str=T->Strings.c_str() ;
if (str[0]=='L'){
YLine *p=new YLine();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->EX=Temp->Strings[3].ToInt();
p->EY=Temp->Strings[4].ToInt();
myobjs.Add(p);
}
if(str[0]=='C'){
YCircle *p=new YCircle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->radius=Temp->Strings[3].ToInt();
myobjs.Add(p);
}
if(str[0]=='R')
{
YRectangle *p=new YRectangle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(str[0]=='E')
{
YEllipse *p=new YEllipse();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
}
Temp->Free();
T->Free();
myobjs.Draw() ;
ShowMessage("打开成功!"
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
String str; str=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.Save(str); }
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
Close();
}
void __fastcall TForm1:aintMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int x,y;
x=X-YObject:riginx;y=Y-YObject:riginy;
if(RBrect->Checked){
YRectangle *p=new YRectangle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBcircle->Checked){
YCircle *p=new YCircle();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBellipse->Checked){
YEllipse *p=new YEllipse();
p->X=x;p->Y=y;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBline->Checked)
{
YLine *p=new YLine();
p->X=x;p->Y=y;p->EX=x+10;p->EY=y+10;
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(RBselect->Checked){
myobjs.LeftPressed(x,y);
}
if(RBdelete->Checked){
YObject *p=myobjs.WhoIsIt(x,y);
if(p!=NULL) myobjs.Delete(p);
}
Paint->Invalidate();
}
void __fastcall TForm1:aintMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
myobjs.MouseMoved(X-YObject:riginx,Y-YObject:riginy);
if(YObject::needredraw){
Paint->Invalidate();
YObject::needredraw=false;
}
}
void __fastcall TForm1:aintMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
myobjs.LeftReleased(X-YObject:riginx,Y-YObject:riginy);
}
void __fastcall TForm1:aintPaint(TObject *Sender)
{
myobjs.Draw();
}
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
YObject:riginx=-ScrollBar1->Position;
Paint->Invalidate();
}
void __fastcall TForm1::ScrollBar2Change(TObject *Sender)
{
YObject:riginy=-ScrollBar2->Position;
Paint->Invalidate();
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
String path;
char * str;
int i;
TStringList * T =new TStringList();
TStringList * Temp =new TStringList();
path=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.DeleteAll();
T->LoadFromFile(path);
for (i=0;i<T->Count ;i++)
{
str=T->Strings.c_str() ;
if (str[0]=='L'){
YLine *p=new YLine();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->EX=Temp->Strings[3].ToInt();
p->EY=Temp->Strings[4].ToInt();
myobjs.Add(p);
}
if(str[0]=='C'){
YCircle *p=new YCircle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->canvas=Paint->Canvas;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->radius=Temp->Strings[3].ToInt();
myobjs.Add(p);
}
if(str[0]=='R')
{
YRectangle *p=new YRectangle();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
if(str[0]=='E')
{
YEllipse *p=new YEllipse();
Temp->Delimiter ='|';
Temp->DelimitedText =str;
p->X=Temp->Strings[1].ToInt();
p->Y=Temp->Strings[2].ToInt();
p->width=Temp->Strings[3].ToInt();
p->height=Temp->Strings[4].ToInt();
p->canvas=Paint->Canvas;
myobjs.Add(p);
}
}
Temp->Free(); T->Free(); myobjs.Draw() ;}
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
String str;
str=ExtractFilePath(Application->ExeName)+"Mysave.tst";
myobjs.Save(str);
}