这是我的程序的一部分片段,现贴出来(*:此程序运行效果完全能够
满足上面大家提到的要求,(如:move,pick,drag 等)。
为了我程序本身的功能,所以还添加了如阴影效果,颜色设置等一些其他的属性。
注:由于是我从我的程序上截下来的,肯定会有语法错误。
如果有谁感兴趣可以到我的www://166.111.78.92/上下载Exe文件。
type
TLineObj=class(TSimpleObj)
private
FStartX: integer;
FStartY: integer;
FEndX: integer;
FEndY: integer;
......
constructor TLineObj.Create(StartPoint,EndPoint:TPoint);
begin
inherited Create(StartPoint,EndPoint);
ObjectType := 'Line';
FStartX:=StartPoint.x;
FStartY:=StartPoint.y;
FEndX:=EndPoint.x;
FEndY:=EndPoint.y;
end;
Procedure TLineObj.Draw(ACanvas:TCanvas);
var
AOldPen:TPen;
A,X1,Y1,X2,Y2,CX,CY:Integer;
begin
with ACanvas do
begin
Pen.Width:=BorderWidth;
if Shadow then
begin
Pen.Color:=ShadowColor;
Inc(FStartX,ShadowX);Inc(FStartY,ShadowY);
Inc(FEndX,ShadowX);Inc(FEndY,ShadowY);
MoveTo(FStartX,FStartY);
LineTo(FEndX,FEndY);
Dec(FStartX,ShadowX);Dec(FStartY,ShadowY);
Dec(FEndX,ShadowX);Dec(FEndY,ShadowY);
end;
Pen.Color:=BorderColor;
MoveTo(FStartX,FStartY);
LineTo(FEndX,FEndY);
end;
end;
Const MinSpace=8;
function TLineObj.isInBound(X,Y:integer):boolean;
var
L,L1,L2: Real;
begin
L:=Sqrt((FStartX-FEndX)*(FStartX-FEndX)
+(FStartY-FEndY)*(FStartY-FEndY));
L1:=Sqrt((FStartX-X)*(FSTartX-X)
+(FStartY-y)*(FStartY-y));
L2:=Sqrt((FEndX-X)*(FEndX-X)
+(FEndY-Y)*(FEndY-Y));
if (L1+L2-L)<MinSpace then Result :=True
else Result:= False;
end;
procedure TLineObj.Move(ADiffPoint,ANewPoint:TPoint);
var
tempWidth,tempHeight:integer;
begin
tempwidth:=FEndX-FStartx;
tempheight:=FEndY-FStartY;;
FStartX:=ANewPoint.x-ADiffPoint.x;
FStartY:=ANewPoint.y-ADiffPoint.y;
FEndX:=FStartX+tempwidth;
FEndy:=FStartY+tempheight;
end;
procedure TLineObj.Drag(APoint:TPoint;PointKind:Integer);
var
tempPoint:TPoint;
L1,L2: Real;
begin
Case PointKind of
4 :
begin
FStartX:=APoint.x;
FStartY:=APoint.y;
end;
5 :
begin
FEndX:=Apoint.x;
FEndY:=Apoint.y;
end;
end;//case
end;