📄 polypic.pas
字号:
ConverPointXY;
ChangPointXY;
end;
POS_CENTERBUTTOM: // :Integer = 7 ; //下中
begin
//确定基准点
Center.x := ChooseRect.Left;
Center.y := ChooseRect.Top;
//鼠标当前位置与鼠标Down的差别
// mouseDiffX :=mouseOldX - mouseDownOldX;
mouseDiffY := mouseOldY - mouseDownOldY;
//计算变化比例
Ratex := 1; //(RectW + mouseDiffX)/RectW;
Ratey := (RectH + mouseDiffY) / RectH;
//绘制前一次虚线图元
ConverPointXY;
ChangPointXY;
//鼠标当前位置与鼠标Down的差别
// mouseDiffX :=mouseX-mouseDownOldX;
mouseDiffY := mouseY - mouseDownOldY;
//计算变化比例
Ratex := 1; //(RectW +mouseDiffX)/RectW;
Ratey := (RectH + mouseDiffY) / RectH;
//绘制前一次虚线图元
ConverPointXY;
ChangPointXY;
end;
POS_LEFTCENTER: // :Integer = 8 ; //左中
begin
//确定基准点
Center.x := ChooseRect.Right;
Center.y := ChooseRect.Top;
//鼠标当前位置与鼠标Down的差别
mouseDiffX := mouseOldX - mouseDownOldX;
// mouseDiffY :=mouseOldY - mouseDownOldY;
//计算变化比例
Ratex := (RectW - mouseDiffX) / RectW;
Ratey := 1; //(RectH + mouseDiffY)/RectH;
//绘制前一次虚线图元
ConverPointXY;
ChangPointXY;
//鼠标当前位置与鼠标Down的差别
mouseDiffX := mouseX - mouseDownOldX;
// mouseDiffY :=mouseY-mouseDownOldY;
//计算变化比例
Ratex := (RectW - mouseDiffX) / RectW;
Ratey := 1; //(RectH + mouseDiffY)/RectH;
//绘制前一次虚线图元
ConverPointXY;
ChangPointXY;
end;
POS_CENTER: // :Integer = 9 ; //矩形中央
begin
//清除前一次
mouseDiffX := mouseOldX - mouseDownOldX;
mouseDiffY := mouseOldY - mouseDownOldY;
//绘制图元
for i := 0 to fPolyPoint.fPolyPointNum-1 do begin
tmpPoint[i].x := fPolyPoint.aPolyPoint[i].x + mouseDiffX;
tmpPoint[i].y := fPolyPoint.aPolyPoint[i].y + mouseDiffY;
end;
ChangPointXY;
//绘制当前虚线图元
mouseDiffX := mouseX - mouseDownOldX;
mouseDiffY := mouseY - mouseDownOldY;
//绘制图元
for i := 0 to fPolyPoint.fPolyPointNum-1 do begin
tmpPoint[i].x := fPolyPoint.aPolyPoint[i].x + mouseDiffX;
tmpPoint[i].y := fPolyPoint.aPolyPoint[i].y + mouseDiffY;
end;
ChangPointXY;
end;
POS_POLYPOINT: //=16 多边形顶点
begin
//**** 清除前一次 ****
mouseDiffX := mouseOldX - mouseDownOldX;
mouseDiffY := mouseOldY - mouseDownOldY;
//绘制图元
for i := 0 to fPolyPoint.fPolyPointNum-1 do tmpPoint[i]:= fPolyPoint.aPolyPoint[i];
tmpPoint[MouseFocus].X:=fPolyPoint.aPolyPoint[MouseFocus].X+mouseDiffX;
tmpPoint[MouseFocus].Y:=fPolyPoint.aPolyPoint[MouseFocus].Y+mouseDiffY;
//绘制当前虚线图元
ChangPolyPointXY;
mouseDiffX := mouseX - mouseDownOldX;
mouseDiffY := mouseY - mouseDownOldY;
//绘制图元
for i := 0 to fPolyPoint.fPolyPointNum-1 do tmpPoint[i]:= fPolyPoint.aPolyPoint[i];
tmpPoint[MouseFocus].X:=fPolyPoint.aPolyPoint[MouseFocus].X+mouseDiffX;
tmpPoint[MouseFocus].Y:=fPolyPoint.aPolyPoint[MouseFocus].Y+mouseDiffY;
ChangPolyPointXY;
end;
end;
end;
procedure TPolyPic.PicChangedUpdate(ACanvas:TCanvas; mouseInPos: MOUSE_POS;chooseRect: TRect; //选择图元形成的矩形
mouseDownOldX, mouseDownOldY: Integer; mouseX, mouseY: Integer); //鼠标当前的坐标
var
mouseDiffX: Integer;
mouseDiffY: Integer;
Center:TPoint;
ratex,ratey:Single;
RectW,RectH: Integer; //选择图元的宽度和高度
tmpPoint:array of TPoint;
pp: array[1..2] of TPoint;
i: Integer;
procedure ConverPointXY;
var
j: Integer;
begin
for j:= 0 to fPolyPoint.fPolyPointNum-1 do begin
fPolyPoint.aPolyPoint[j].x := center.x + Round((fPolyPoint.aPolyPoint[j].x - center.x) * rateX);
fPolyPoint.aPolyPoint[j].y := center.y + Round((fPolyPoint.aPolyPoint[j].y - center.y) * rateY);
end;
end;
begin
pp[1].x := mouseDownOldX;
pp[1].y := mouseDownOldY;
pp[2].x := mouseX;
pp[2].y := mouseY;
DPtoLP(ACanvas.Handle, pp[1], 2);
mouseDownOldX := pp[1].x;
mouseDownOldY := pp[1].y;
mouseX := pp[2].x;
mouseY := pp[2].y;
//设置绘图方式
ACanvas.Pen.Width := 1;
ACanvas.Pen.Mode := pmXor;
ACanvas.Pen.Style := psDot;
ACanvas.Brush.Style := bsClear;
//初始化变量值
RectW:=ChooseRect.Right - ChooseRect.Left;
RectH:=ChooseRect.Bottom - ChooseRect.Top;
//设置数组长度
SetLength(tmpPoint,fPolyPoint.fPolyPointNum);
//鼠标当前位置与鼠标Down的差别
mouseDiffX := mouseX - mouseDownOldX;
mouseDiffY := mouseY - mouseDownOldY;
//计算选择图元的宽度和高度
case mouseInPos of
POS_LEFTTOP: // :Integer = 1 ; //左上
begin
//确定基准点
Center.X:=ChooseRect.Right;
Center.y := ChooseRect.Bottom;
//计算变化比例
Ratex := (RectW - mouseDiffX) / RectW;
Ratey := (RectH - mouseDiffY) / RectH;
//绘制当前虚线图元
ConverPointXY;
end;
POS_RIGHTTOP: // :Integer = 2 ; //右上
begin
//确定基准点
Center.x := ChooseRect.Left;
Center.y := ChooseRect.Bottom;
//计算变化比例
Ratex := (RectW + mouseDiffX) / RectW;
Ratey := (RectH - mouseDiffY) / RectH;
//绘制前一次虚线图元
ConverPointXY;
end;
POS_RIGHTBOTTOM: // :Integer = 3 ; //右下
begin
//确定基准点
Center.x := ChooseRect.Left;
Center.y := ChooseRect.Top;
//计算变化比例
Ratex := (RectW + mouseDiffX) / RectW;
Ratey := (RectH + mouseDiffY) / RectH;
//绘制前一次虚线图元
ConverPointXY;
end;
POS_LEFTBOTTOM: // :Integer = 4 ; //左下
begin
//确定基准点
Center.x := ChooseRect.Right;
Center.y := ChooseRect.Top;
//计算变化比例
Ratex := (RectW - mouseDiffX) / RectW;
Ratey := (RectH + mouseDiffY) / RectH;
//绘制前一次虚线图元
ConverPointXY;
end;
POS_CENTERTOP: // :Integer = 5 ; //上中
begin
//确定基准点
Center.x := ChooseRect.Right;
Center.y := ChooseRect.Bottom;
//计算变化比例
Ratex := 1; //(RectW -mouseDiffX)/RectW;
Ratey := (RectH - mouseDiffY) / RectH;
//绘制前一次虚线图元
ConverPointXY;
end;
POS_RIGHTCENTER: // :Integer = 6 ; //右中
begin
//确定基准点
Center.x := ChooseRect.Left;
Center.y := ChooseRect.Bottom;
//计算变化比例
Ratex := (RectW + mouseDiffX) / RectW;
Ratey := 1; //(RectH-mouseDiffY)/RectH;
//绘制前一次虚线图元
ConverPointXY;
end;
POS_CENTERBUTTOM: // :Integer = 7 ; //下中
begin
//确定基准点
Center.x := ChooseRect.Left;
Center.y := ChooseRect.Top;
//计算变化比例
Ratex := 1; //(RectW +mouseDiffX)/RectW;
Ratey := (RectH + mouseDiffY) / RectH;
//绘制前一次虚线图元
ConverPointXY;
end;
POS_LEFTCENTER: // :Integer = 8 ; //左中
begin
//确定基准点
Center.x := ChooseRect.Right;
Center.y := ChooseRect.Top;
//计算变化比例
Ratex := (RectW - mouseDiffX) / RectW;
Ratey := 1; //(RectH + mouseDiffY)/RectH;
//绘制前一次虚线图元
ConverPointXY;
end;
POS_CENTER: // :Integer = 9 ; //矩形中央
begin
//绘制图元
for i := 0 to fPolyPoint.fPolyPointNum-1 do begin
Inc(fPolyPoint.aPolyPoint[i].x, mouseDiffX);
Inc(fPolyPoint.aPolyPoint[i].y, mouseDiffY);
end;
end;
POS_POLYPOINT: //=16 多边形顶点
begin
//绘制图元
Inc(fPolyPoint.aPolyPoint[MouseFocus].X, mouseDiffX);
Inc(fPolyPoint.aPolyPoint[MouseFocus].Y, mouseDiffY);
end;
end;
SetPolyPicRect;
end;
//位置代码可参见 PicConst.pas
procedure TPolyPic.AssignPic(SourcePic: TPicBase);
begin
inherited AssignPic(SourcePic);
fPolyType:=TPolyPic(SourcePic).PolyType; //
fPolyPoint:=TPolyPic(SourcePic).PolyPoint;
end;
//非重载函数
//绘图函数
procedure TPolyPic.DrawPolyPic(ACanvas: TCanvas; aPoints:Array of TPoint);
begin
case fPolyType of
PolyOpen: // 不封闭
begin
ACanvas.Polyline(aPoints);
end;
PolyClose: //封闭
begin
ACanvas.Polygon(aPoints);
end;
end;
PicId:=PIC_POLY;
end;
procedure TPolyPic.GetClassDataFromChar(var Len:Integer; var Buf:Array of Char);
var
op,P:Pointer;
oLen:Integer;
i1:Integer;
begin
inherited GetClassDataFromChar(Len,Buf);
olen:=Len;
p:=Pointer(@Buf[Len]);
op:=p;
fPolyType:=TPolyType(PByte(P)^);
Inc(PByte(P));
fPolyPoint.fPolyPointNum:=PInteger(P)^;
Inc(PInteger(P));
SetLength(fPolyPoint.aPolyPoint,fPolyPoint.fPolyPointNum);
For i1:=0 to fPolyPoint.fPolyPointNum-1 do begin
fPolyPoint.aPolyPoint[i1].X:=PInteger(P)^;
Inc(PInteger(P));
fPolyPoint.aPolyPoint[i1].Y:=PInteger(P)^;
Inc(PInteger(P));
end;
//Len:=oLen+AddrOffSet(op,P);
Len:=oLen+LongInt(P)-LongInt(Op);
end;
procedure TPolyPic.SaveClassDataToChar(var Len:Integer; var Buf:Array of Char);
var
op,P:Pointer;
oLen:Integer;
i1:Integer;
begin
inherited SaveClassDataToChar(Len,Buf);
olen:=Len;
p:=Pointer(@Buf[Len]);
op:=p;
PByte(P)^:=Ord(fPolyType);
Inc(PByte(P));
PInteger(P)^:=fPolyPoint.fPolyPointNum;
Inc(PInteger(P));
For i1:=0 to fPolyPoint.fPolyPointNum-1 do begin
PInteger(P)^:=fPolyPoint.aPolyPoint[i1].X;
Inc(PInteger(P));
PInteger(P)^:=fPolyPoint.aPolyPoint[i1].Y;
Inc(PInteger(P));
end;
//Len:=oLen+AddrOffSet(op,P);
Len:=oLen+LongInt(P)-LongInt(Op);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -