⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arccpic.pas

📁 很不错的delphi 画失量图的delphi源代码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
           //mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           rateX :=1; // (RectW-MouseDiffX)/RectW;
           rateY := (RectH+MouseDiffY)/RectH;
           ConverPointXY;
           ChangPointXY;
           //绘制当前虚线图元
           //mouseDiffX := mouseX - mouseDownOldX;
           mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           rateX :=1; // (RectW-MouseDiffX)/RectW;
           rateY := (RectH+MouseDiffY)/RectH;
           //坐标变换
           ConverPointXY;
           ChangPointXY;
         //end;
       end;
     POS_LEFTCENTER: //      :Integer = 8  ; //左中
       begin
         {if (ssCtrl in ArccKeyState) then begin
           //清除前一次
           Center :=Point ((StartPos.x + Endpos.x) div 2,(StartPos.y + Endpos.y) div 2);
           mouseDiffX := mouseOldX - mouseDownOldX;
           //mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           tmpsp.X:=StartPos.X+MouseDiffX;
           tmpsp.Y:=StartPos.Y;
           tmpep.X :=EndPos.X-MouseDiffX;
           tmpep.Y :=EndPos.Y;
           //坐标变换
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           //mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           tmpsp.X:=StartPos.X+MouseDiffX;
           tmpsp.Y:=StartPos.Y;
           tmpep.X :=EndPos.X-MouseDiffX;
           tmpep.Y :=EndPos.Y;
           //坐标变换
           ChangPointXY;
         end else begin  }
           //清除前一次
           mouseDiffX := mouseOldX - mouseDownOldX;
           //mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           rateX := (RectW-MouseDiffX)/RectW;
           rateY :=1; // (RectH-MouseDiffY)/RectH;
           ConverPointXY;
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           //mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           rateX := (RectW-MouseDiffX)/RectW;
           rateY :=1; // (RectH-MouseDiffY)/RectH;
           //坐标变换
           ConverPointXY;
           ChangPointXY;
         //end;
       end;
     POS_ARCSTART:  //圆弧起点
       begin
         //绘制图元
         {if fARccType=ARCC_ARC Then} StartToEnd:=True;
         mouseDiffX := mouseOldX - mouseDownOldX;
         mouseDiffY := mouseOldY - mouseDownOldY;
         tmpsp :=StartPos;
         tmpep := EndPos;
         pp[1].X:=arcstartpos.X+mouseDiffX;
         pp[1].Y:=arcstartPos.Y+mouseDiffY;
         tmparcsp:=PointToCirclePoint(StartPos,EndPos,pp[1]);
         tmparcep:=ArcEndPos;
         ChangPointXY;
         //绘制当前虚线图元
         //绘制图元
         mouseDiffX := Mousex-mouseDownOldX;
         mouseDiffY := MouseY-mouseDownOldY;
         tmpsp :=StartPos;
         tmpep := EndPos;
         pp[1].X:=arcstartpos.X+mouseDiffX;
         pp[1].Y:=arcstartPos.Y+mouseDiffY;
         tmparcsp:=PointToCirclePoint(StartPos,EndPos,pp[1]);
         tmparcep:=ArcEndPos;
         ChangPointXY;
       end;
     POS_ARCEND: //圆角左
       begin
         mouseDiffX := mouseOldX - mouseDownOldX;
         mouseDiffY := mouseOldY - mouseDownOldY;
         tmpsp :=StartPos;
         tmpep := EndPos;
         pp[1].X:=arcendpos.X+mouseDiffX;
         pp[1].Y:=arcendPos.Y+mouseDiffY;
         tmparcsp:=ArcStartPos;
         tmparcep:=PointToCirclePoint(StartPos,EndPos,pp[1]);
         ChangPointXY;
         //绘制当前虚线图元
         //绘制图元
         mouseDiffX := Mousex-mouseDownOldX;
         mouseDiffY := MouseY-mouseDownOldY;
         tmpsp :=StartPos;
         tmpep := EndPos;
         pp[1].X:=arcendpos.X+mouseDiffX;
         pp[1].Y:=arcendPos.Y+mouseDiffY;
         tmparcsp:=ArcStartPos;
         tmparcep:=PointToCirclePoint(StartPos,EndPos,pp[1]);
         ChangPointXY;
       end;
     POS_CENTER: //         :Integer = 9  ; //矩形中央
       begin
         //绘制图元
         mouseDiffX := mouseOldX - mouseDownOldX;
         mouseDiffY := mouseOldY - mouseDownOldY;
         tmpsp :=Point( startPos.x + mouseDiffX,startPos.y + mouseDiffY);
         tmpep := Point( endPos.x + mouseDiffX,endPos.y + mouseDiffY);
         tmparcsp :=Point( arcstartPos.x + mouseDiffX,arcstartPos.y + mouseDiffY);
         tmparcep := Point( arcendPos.x + mouseDiffX,arcendPos.y + mouseDiffY);
         ChangPointXY;
         //绘制当前虚线图元
         mouseDiffX := mouseX - mouseDownOldX;
         mouseDiffY := mouseY - mouseDownOldY;
         //绘制图元
         tmpsp :=Point(startPos.x + mouseDiffX, startPos.y + mouseDiffY);
         tmpep := Point(endPos.x + mouseDiffX,endPos.y + mouseDiffY);
         tmparcsp :=Point( arcstartPos.x + mouseDiffX,arcstartPos.y + mouseDiffY);
         tmparcep := Point( arcendPos.x + mouseDiffX,arcendPos.y + mouseDiffY);
         //坐标变换
         ChangPointXY;
       end;
  end;
end;

procedure TArccPic.PicChangedUpdate(ACanvas:TCanvas; mouseInPos: MOUSE_POS;chooseRect: TRect; //选择图元形成的矩形
        mouseDownOldX, mouseDownOldY: Integer; mouseX, mouseY: Integer);  //鼠标当前的坐标
var
  tmprect:TRect;
  MouseDiffX,MouseDiffY:Integer;
  Center:TPoint;
  ratex,ratey:Single;
  rectw,recth:Integer;
  procedure UpdateConverPointXY;
  begin
    StartPos.X:=Center.X+ Round((StartPos.x - Center.x) *  rateX);
    StartPos.Y:=Center.Y+ Round((StartPos.Y - Center.Y) *  rateY);
    endPos.X:=Center.X+ Round((endPos.x - Center.x) *  rateX);
    endPos.Y:=Center.Y+ Round((EndPos.Y - Center.Y) *  rateY);
    arcstartPos.X:=Center.X+ Round((ArcStartPos.x - Center.x) *  rateX);
    arcstartpos.Y:=Center.Y+ Round((ArcStartPos.Y - Center.Y) *  rateY);
    arcendpos.X:=Center.X+ Round((ArcendPos.x - Center.x) *  rateX);
    arcendpos.Y:=Center.Y+ Round((ArcendPos.Y - Center.Y) *  rateY);
  end;
begin
  //计算选择图元的宽度和高度
  MouseDiffX:=Mousex-MouseDownOldX;
  MouseDiffY:=MouseY-MouseDownOldY;
  RectW:=EndPos.X-StartPos.X;
  RectH:=EndPos.Y-StartPos.Y;
  Center :=Point ((StartPos.x + Endpos.x) div 2,(StartPos.y + Endpos.y) div 2);
  case mouseInPos of
    POS_LEFTTOP: //           :Integer = 1  ; //左上
      begin
        //确定基准点
        {if (ssCtrl in ArccKeyState) then begin
          StartPos:=Point(Mousex,mouseY);
          EndPos.X:=EndPos.X-MouseDiffX;
          EndPos.Y:=EndPos.Y-MouseDiffY;
        end else begin }
          rateX := (RectW-MouseDiffX)/RectW;
          rateY := (RectH-MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_RIGHTTOP: //        :Integer = 2  ; //右上
      begin
        //确定基准点
        {if (ssCtrl in ArccKeyState) then begin
          StartPos.X:=StartPos.X-MouseDiffX;
          StartPos.Y:=MouseY;
          EndPos.X:=MouseX;
          EndPos.Y:=EndPos.Y-MouseDiffY;
        end else begin   }
          rateX := (RectW+MouseDiffX)/RectW;
          rateY := (RectH-MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_RIGHTBOTTOM: //     :Integer = 3  ; //右下
      begin
        {if (ssCtrl in ArccKeyState) then begin
          StartPos.X:=StartPos.X-MouseDiffX;
          StartPos.Y:=StartPos.Y-MouseDiffY;
          EndPos.X:=MouseX;
          EndPos.Y:=MouseY;
        end else begin }
          rateX := (RectW+MouseDiffX)/RectW;
          rateY := (RectH+MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_LEFTBOTTOM: //      :Integer = 4  ; //左下
      begin
        {if (ssCtrl in ArccKeyState) then begin
          StartPos.X:=MouseX;
          StartPos.Y:=StartPos.Y-MouseDiffY;
          EndPos.X:=EndPos.X-MouseDiffX;
          EndPos.Y:=MouseY;
        end else begin  }
          rateX := (RectW-MouseDiffX)/RectW;
          rateY := (RectH+MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_CENTERTOP: //       :Integer = 5  ; //上中
      begin
        {if (ssCtrl in ArccKeyState) then begin
          StartPos.Y:=MouseY;
          EndPos.Y:=EndPos.Y-MouseDiffY;
        end else begin }
          rateX :=1; // (RectW-MouseDiffX)/RectW;
          rateY := (RectH-MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_RIGHTCENTER: //      :Integer = 6  ; //右中
      begin
        {if (ssCtrl in ArccKeyState) then begin
          StartPos.X:=StartPos.X-MouseDiffX;
          EndPos.X:=EndPos.X+MouseDiffX;
        end else begin }
          rateX := (RectW+MouseDiffX)/RectW;
          rateY :=1; // (RectH-MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_CENTERBUTTOM: //     :Integer = 7  ; //下中
      begin
        {if (ssCtrl in ArccKeyState) then begin
          StartPos.Y:=StartPos.Y-MouseDiffY;
          EndPos.Y:=MouseY;
        end else begin  }
          rateX :=1; // (RectW-MouseDiffX)/RectW;
          rateY := (RectH+MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_LEFTCENTER: //      :Integer = 8  ; //左中
      begin
        {if (ssCtrl in ArccKeyState) then begin
          StartPos.X:=StartPos.X+MouseDiffX;
          EndPos.X:=EndPos.X-MouseDiffX;
        end else begin  }
          rateX := (RectW-MouseDiffX)/RectW;
          rateY :=1; // (RectH-MouseDiffY)/RectH;
          UpdateConverPointXY;
        //end;
      end;
    POS_ARCSTART:  //圆角上
       begin
         center.X:=arcstartpos.X+mouseDiffX;
         center.Y:=arcstartPos.Y+mouseDiffY;
         ArcStartPos:=PointToCirclePoint(StartPos,EndPos,Center);
       end;
    POS_ARCEND: //圆角左
       begin
         center.X:=arcendpos.X+mouseDiffX;
         center.Y:=arcendPos.Y+mouseDiffY;
         ArcEndPos:=PointToCirclePoint(StartPos,EndPos,Center);
       end;
    POS_CENTER: //         :Integer = 9  ; //矩形中央
      begin
        Inc(startPos.x, MouseDiffx);
        Inc(startPos.y, MouseDiffY);
        Inc(endPos.x,   MouseDiffx);
        Inc(endPos.y,   MouseDiffY);
        Inc(arcstartPos.x, MouseDiffx);
        Inc(arcstartPos.y, MouseDiffY);
        Inc(arcendPos.x,   MouseDiffx);
        Inc(arcendPos.y,   MouseDiffY);
      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;
  PicRect:=tmpRect;
end;

//位置代码可参见 PicConst.pas
procedure TArccPic.AssignPic(SourcePic: TPicBase);
begin
  inherited AssignPic(SourcePic);
  StartPos := TArccPic(SourcePic).PicStartPoint;
  EndPos := TArccPic(SourcePic).PicEndPoint;
  ArcStartPos:= TArccPic(SourcePic).PicArcStart;
  ArcEndPos:=TArccPic(SourcePic).PicArcStop;
  fArccType:=TArccPic(SourcePic).PicArccType;
end;

//非重载函数
//绘图函数
procedure TArccPic.DrawArccPic(ACanvas: TCanvas; startPoint:TPoint; endPoint:TPoint;ArcsPoint:TPoint;ArcePoint:TPoint);
begin
  Case fArccType of     //Arcc_Arc,Arcc_Sector,Acrr_Chord
    Arcc_Arc: // Arc
      begin
        ACanvas.Arc(StartPoint.X,StartPoint.Y, EndPoint.X, EndPoint.Y, ArcSPoint.X,
          ArcSPoint.Y,ArcePoint.X, ArcePoint.Y);
      end;
    Arcc_Sector: //PIE
      begin
        ACanvas.Pie(StartPoint.X,StartPoint.Y, EndPoint.X, EndPoint.Y, ArcSPoint.X,
          ArcSPoint.Y,ArcePoint.X, ArcePoint.Y);
      end;
    Arcc_Chord: //Chord
      begin
        ACanvas.Chord(StartPoint.X,StartPoint.Y, EndPoint.X, EndPoint.Y, ArcSPoint.X,
          ArcSPoint.Y,ArcePoint.X, ArcePoint.Y);
      end;
  end;
  PicId:=PIC_ARCC;
end;

procedure TArccPic.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;
  fArccType:=TArccType(PByte(P)^);
  Inc(PByte(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));
  ArcStartPos.X:=PInteger(P)^;
  Inc(PInteger(P));
  ArcStartPos.Y:=PInteger(P)^;
  Inc(PInteger(P));
  ArcEndPos.X:=PInteger(P)^;
  Inc(PInteger(P));
  ArcEndPos.Y:=PInteger(P)^;
  Inc(PInteger(P));
  //Len:=oLen+AddrOffSet(op,P);
  Len:=oLen+LongInt(P)-LongInt(Op);
end;

procedure TArccPic.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;
  PByte(P)^:=Ord(fArccType);
  Inc(PByte(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));
  PInteger(P)^:=ArcStartPos.X;
  Inc(PInteger(P));
  PInteger(P)^:=ArcStartPos.Y;
  Inc(PInteger(P));
  PInteger(P)^:=ArcEndPos.X;
  Inc(PInteger(P));
  PInteger(P)^:=ArcEndPos.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 + -