📄 rounpic.pas
字号:
mouseDiffY := mouseOldY - mouseDownOldY;
//绘制图元
tempStartPoint:=StartPos;
tempendPoint.X:=EndPos.X;
tempendPoint.Y:=endpos.Y+MouseDiffY;
ChangPointXY;
//绘制当前虚线图元
//mouseDiffX := mouseX - mouseDownOldX;
mouseDiffY := mouseY - mouseDownOldY;
//绘制图元
tempStartPoint:=StartPos;
tempendPoint.X:=EndPos.X;
tempendPoint.Y:=endpos.Y+MouseDiffY;
//坐标变换
ChangPointXY;
end;
end;
POS_LEFTCENTER: // :Integer = 8 ; //左中
begin
if (ssCtrl in RounKeyState) then begin
//清除前一次
Center :=Point ((StartPos.x + Endpos.x) div 2,(StartPos.y + Endpos.y) div 2);
mouseDiffX := mouseOldX - mouseDownOldX;
//mouseDiffY := mouseOldY - mouseDownOldY;
//绘制图元
tempStartPoint.X:=StartPos.X+MouseDiffX;
tempStartPoint.Y:=StartPos.Y;
tempendPoint.X :=EndPos.X-MouseDiffX;
tempendPoint.Y :=EndPos.Y;
//坐标变换
ChangPointXY;
//绘制当前虚线图元
mouseDiffX := mouseX - mouseDownOldX;
//mouseDiffY := mouseY - mouseDownOldY;
//绘制图元
tempStartPoint.X:=StartPos.X+MouseDiffX;
tempStartPoint.Y:=StartPos.Y;
tempendPoint.X :=EndPos.X-MouseDiffX;
tempendPoint.Y :=EndPos.Y;
//坐标变换
ChangPointXY;
end else begin
//清除前一次
mouseDiffX := mouseOldX - mouseDownOldX;
//mouseDiffY := mouseOldY - mouseDownOldY;
//绘制图元
tempStartPoint.X:=StartPos.X+MouseDiffX;
tempStartPoint.Y:=StartPos.Y;
tempendPoint:=endpos;
ChangPointXY;
//绘制当前虚线图元
mouseDiffX := mouseX - mouseDownOldX;
//mouseDiffY := mouseY - mouseDownOldY;
//绘制图元
tempStartPoint.X:=StartPos.X+MouseDiffX;
tempStartPoint.Y:=StartPos.Y;
tempendPoint:=endpos;
//坐标变换
ChangPointXY;
end;
end;
POS_ROUNDRECT_TOP: //圆角上
begin
//绘制图元
fRoundRate[0] := (MouseOldX-StartPos.X) / (EndPos.X-StartPos.X);
if fRoundRate[0]<0 then fRoundRate[0]:=0;
if fRoundRate[0]>1 then fRoundRate[0]:=1;
tempStartPoint :=StartPos;
tempEndPoint := EndPos;
ChangPointXY;
//绘制当前虚线图元
fRoundRate[0] := (MouseX-StartPos.X) / (EndPos.X-StartPos.X);
if fRoundRate[0]<0 then fRoundRate[0]:=0;
if fRoundRate[0]>1 then fRoundRate[0]:=1;
//绘制图元
tempStartPoint :=StartPos;
tempEndPoint := EndPos;
//坐标变换
ChangPointXY;
end;
POS_ROUNDRECT_LEFT: //圆角左
begin
//绘制图元
fRoundRate[1] := (MouseOldY-StartPos.Y) / (EndPos.Y-StartPos.Y);
if fRoundRate[1]<0 then fRoundRate[1]:=0;
if fRoundRate[1]>1 then fRoundRate[1]:=1;
tempStartPoint :=StartPos;
tempEndPoint := EndPos;
ChangPointXY;
//绘制当前虚线图元
fRoundRate[1] := (MouseY-StartPos.Y) / (EndPos.Y-StartPos.Y);
if fRoundRate[1]<0 then fRoundRate[1]:=0;
if fRoundRate[1]>1 then fRoundRate[1]:=1;
//绘制图元
tempStartPoint :=StartPos;
tempEndPoint := EndPos;
//坐标变换
ChangPointXY;
end;
POS_CENTER: // :Integer = 9 ; //矩形中央
begin
//绘制图元
mouseDiffX := mouseOldX - mouseDownOldX;
mouseDiffY := mouseOldY - mouseDownOldY;
tempStartPoint :=Point( startPos.x + mouseDiffX,startPos.y + mouseDiffY);
tempEndPoint := Point( endPos.x + mouseDiffX,endPos.y + mouseDiffY);
ChangPointXY;
//绘制当前虚线图元
mouseDiffX := mouseX - mouseDownOldX;
mouseDiffY := mouseY - mouseDownOldY;
//绘制图元
tempStartPoint :=Point(startPos.x + mouseDiffX, startPos.y + mouseDiffY);
tempEndPoint := Point(endPos.x + mouseDiffX,endPos.y + mouseDiffY);
//坐标变换
ChangPointXY;
end;
end;
end;
procedure TRounPic.PicChangedUpdate(ACanvas:TCanvas; mouseInPos: MOUSE_POS;chooseRect: TRect; //选择图元形成的矩形
mouseDownOldX, mouseDownOldY: Integer; mouseX, mouseY: Integer); //鼠标当前的坐标
var
tmprect:TRect;
MouseDiffX,MouseDiffY:Integer;
begin
//计算选择图元的宽度和高度
MouseDiffX:=Mousex-MouseDownOldX;
MouseDiffY:=MouseY-MouseDownOldY;
case mouseInPos of
POS_LEFTTOP: // :Integer = 1 ; //左上
begin
//确定基准点
if (ssCtrl in RounKeyState) then begin
StartPos:=Point(Mousex,mouseY);
EndPos.X:=EndPos.X-MouseDiffX;
EndPos.Y:=EndPos.Y-MouseDiffY;
end else begin
Inc(startPos.x, MouseDiffX);
Inc(startPos.y, MousediffY);
end;
end;
POS_RIGHTTOP: // :Integer = 2 ; //右上
begin
//确定基准点
if (ssCtrl in RounKeyState) then begin
StartPos.X:=StartPos.X-MouseDiffX;
StartPos.Y:=MouseY;
EndPos.X:=MouseX;
EndPos.Y:=EndPos.Y-MouseDiffY;
end else begin
Inc(startPos.y, MouseDiffY);
Inc(endPos.x, MouseDiffX);
end;
end;
POS_RIGHTBOTTOM: // :Integer = 3 ; //右下
begin
if (ssCtrl in RounKeyState) then begin
StartPos.X:=StartPos.X-MouseDiffX;
StartPos.Y:=StartPos.Y-MouseDiffY;
EndPos.X:=MouseX;
EndPos.Y:=MouseY;
end else begin
Inc(endPos.x, mouseX - mouseDownOldX);
Inc(endPos.y, mouseY - mouseDownOldY);
end;
end;
POS_LEFTBOTTOM: // :Integer = 4 ; //左下
begin
if (ssCtrl in RounKeyState) then begin
StartPos.X:=MouseX;
StartPos.Y:=StartPos.Y-MouseDiffY;
EndPos.X:=EndPos.X-MouseDiffX;
EndPos.Y:=MouseY;
end else begin
Inc(startPos.x, mouseX - mouseDownOldX);
Inc(endPos.Y, mouseY - mouseDownOldY);
end;
end;
POS_CENTERTOP: // :Integer = 5 ; //上中
begin
if (ssCtrl in RounKeyState) then begin
StartPos.Y:=MouseY;
EndPos.Y:=EndPos.Y-MouseDiffY;
end else begin
Inc(startPos.Y, mouseY - mouseDownOldY);
end;
end;
POS_RIGHTCENTER: // :Integer = 6 ; //右中
begin
if (ssCtrl in RounKeyState) then begin
StartPos.X:=StartPos.X-MouseDiffX;
EndPos.X:=EndPos.X+MouseDiffX;
end else begin
Inc(endPos.X, mouseX - mouseDownOldX);
end;
end;
POS_CENTERBUTTOM: // :Integer = 7 ; //下中
begin
if (ssCtrl in RounKeyState) then begin
StartPos.Y:=StartPos.Y-MouseDiffY;
EndPos.Y:=MouseY;
end else begin
Inc(endPos.Y, mouseY - mouseDownOldY);
end;
end;
POS_LEFTCENTER: // :Integer = 8 ; //左中
begin
if (ssCtrl in RounKeyState) then begin
StartPos.X:=StartPos.X+MouseDiffX;
EndPos.X:=EndPos.X-MouseDiffX;
end else begin
Inc(StartPos.X, mouseX - mouseDownOldX);
end;
end;
POS_ROUNDRECT_TOP: //圆角上
begin
end;
POS_ROUNDRECT_LEFT: //圆角左
begin
end;
POS_CENTER: // :Integer = 9 ; //矩形中央
begin
Inc(startPos.x, mouseX - mouseDownOldX);
Inc(startPos.y, mouseY - mouseDownOldY);
Inc(endPos.x, mouseX - mouseDownOldX);
Inc(endPos.y, mouseY - mouseDownOldY);
end;
end;
//统一调整图元矩形区域和起点和终点的位置
//保证起点坐标小于终点坐标
with tmpRect do begin //调整图元矩形区域
Left := Min(startPos.x, endPos.x);
Top := Min(startPos.y, endpos.Y);
Right := Max(startPos.x, endPos.x);
Bottom := Max(startPos.y, endPos.y);
if Right = Left then Inc(Right, 2);
if Top = Bottom then Inc(Bottom, 2);
//更新坐标点
end;
StartPos:=tmpRect.TopLeft;
EndPos:=tmpRect.BottomRight;
WhPoint.X := Round((EndPos.X-StartPos.X) * fRoundRate[0]);
WhPoint.Y := Round((EndPos.Y-StartPos.Y) * fRoundRate[1]);
PicRect:=tmpRect;
end;
//位置代码可参见 PicConst.pas
procedure TRounPic.AssignPic(SourcePic: TPicBase);
begin
inherited AssignPic(SourcePic);
StartPos := TRounPic(SourcePic).PicStartPoint;
EndPos := TRounPic(SourcePic).PicEndPoint;
whPoint:= TRounPic(SourcePic).PicWhPoint;
fRoundRate[0] := whPoint.X / (EndPos.X-StartPos.X);
fRoundRate[1] := whPoint.Y / (EndPos.Y-StartPos.Y);
end;
//非重载函数
//绘图函数
procedure TRounPic.DrawRounPic(ACanvas: TCanvas; startPoint:TPoint; endPoint:TPoint;aWhPoint:TPoint);
begin
ACanvas.RoundRect(StartPoint.X,StartPoint.Y,EndPoint.X,EndPoint.Y, aWhPoint.X,aWhPoint.Y);
PicId:=PIC_ROUN;
end;
procedure TRounPic.GetClassDataFromChar(var Len:Integer; var Buf:Array of Char);
var
op,P:Pointer;
oLen:Integer;
begin
inherited GetClassDataFromChar(Len,Buf);
olen:=Len;
p:=Pointer(@Buf[Len]);
op:=p;
StartPos.X:=PInteger(P)^;
Inc(PInteger(P));
StartPos.Y:=PInteger(P)^;
Inc(PInteger(P));
EndPos.X:=PInteger(P)^;
Inc(PInteger(P));
EndPos.Y:=PInteger(P)^;
Inc(PInteger(P));
fRoundRate[0]:=PSingle(P)^;
Inc(PSingle(P));
fRoundRate[1]:=PSingle(P)^;
Inc(PSingle(P));
whPoint.X:=PInteger(P)^;
Inc(PInteger(P));
whPoint.Y:=PInteger(P)^;
Inc(PInteger(P));
//Len:=oLen+AddrOffSet(op,P);
Len:=oLen+LongInt(P)-LongInt(Op);
end;
procedure TRounPic.SaveClassDataToChar(var Len:Integer; var Buf:Array of Char);
var
op,P:Pointer;
oLen:Integer;
begin
inherited SaveClassDataToChar(Len,Buf);
olen:=Len;
p:=Pointer(@Buf[Len]);
op:=p;
PInteger(P)^:=StartPos.X;
Inc(PInteger(P));
PInteger(P)^:=StartPos.Y;
Inc(PInteger(P));
PInteger(P)^:=EndPos.X;
Inc(PInteger(P));
PInteger(P)^:=EndPos.Y;
Inc(PInteger(P));
PSingle(P)^:=fRoundRate[0];
Inc(PSingle(P));
PSingle(P)^:=fRoundRate[1];
Inc(PSingle(P));
PInteger(P)^:=whPoint.X;
Inc(PInteger(P));
PInteger(P)^:=whPoint.Y;
Inc(PInteger(P));
//Len:=oLen+AddrOffSet(op,P);
Len:=oLen+LongInt(P)-LongInt(Op);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -