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

📄 arccpic.pas

📁 矢量图形绘制
💻 PAS
📖 第 1 页 / 共 3 页
字号:
         if (ssLeft in Shift) then begin
          //清除前一次绘制的图形
           DrawArccPic(ACanvas,StartPos,EndPos,ArcStartPos,ArcEndPos);
           //绘制当前的图形
           centerX := (endPos.X + StartPos.x) div 2; //圆心
           centerY := (EndPos.y + StartPos.y) div 2;
           radiu := round(sqrt(sqr(Apoint.X - centerX) + sqr(Apoint.Y - centerY))); //半径
           StartPos.x := centerX - radiu; //调整圆弧的四角坐标
           StartPos.y := centerY - radiu;
           endPos.x := centerX + radiu;
           EndPos.y := centerY + radiu;
           DrawArccPic(ACanvas,StartPos,EndPos,ArcStartPos,ArcEndPos);
         end;
       end;
    ARC_SET: //确定圆弧终点
       begin
         //设置pen的格式
         ACanvas.Pen:=PicPen;
         ACanvas.Pen.Mode:=pmXor;
         //设置Brush的格式
         ACanvas.Brush:=PicBrush;
         centerX := (EndPos.x + StartPos.x) div 2; //圆心
         centerY := (EndPos.y + StartPos.y) div 2;
         //清除前一次绘制的图形
         //if fArccType<>ARCC_SECTOR then begin
           ACanvas.MoveTo(centerX, centerY);
           ACanvas.LineTo(arcEndPos.x, arcEndPos.y);
         //end;
         DrawArccPic(ACanvas,StartPos,EndPos,ArcStartPos,ArcEndPos);
         //绘制当前的图形
         pp[1] :=PointToCirclePoint(StartPos,EndPos, APoint);
         DpToLp(ACanvas.Handle, pp[1], 1);
         arcEndPos := pp[1]; //确定新的圆弧终点
         //if fArccType<>ARCC_SECTOR then begin
           ACanvas.MoveTo(centerX, centerY);
           ACanvas.LineTo(arcEndPos.x, arcEndPos.y);
         //end;
         DrawArccPic(ACanvas,StartPos,EndPos,ArcStartPos,ArcEndPos);
      end;
  end;
end;

procedure TArccPic.ParentMouseUp(ACanvas:TCanvas;CursorNum:Integer;
        Button: TMouseButton;  Shift: TShiftState; APoint:TPoint);
var
  pp: array[1..4] of TPoint;
  tmpRect:TRect;
  centerx,centery:Integer;
begin
  case fDrawState of
    ARC_DRAW: //确定半径和圆弧的起点
      begin
        arcStartPos:=APoint;
        arcEndPos := APoint;
        if ((Abs(EndPos.x - StartPos.x) < MinCellSize) or
            (Abs(EndPos.y - StartPos.y) < MinCellSize)) then  begin
          endPos.x := endPos.x + MinCellSize;
          endpos.y := endpos.y + MinCellSize;
        end;
        pp[1] := StartPos;
        pp[2] := EndPos;
        pp[3] := arcStartPos;
        pp[4] := arcEndPos;
        DpToLp(ACanvas.Handle, pp[1], 4);
        StartPos := pp[1];
        endPos   := pp[2];
        arcStartPos := pp[3];
        arcEndPos := pp[4];
        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);
        end;
        PicRect:=tmpRect;
        ACanvas.Pen := PicPen;
        ACanvas.Brush := PicBrush;
        ACanvas.Font := PicFont;
        DrawArccPic(ACanvas, StartPos,EndPos,ArcStartPos,ArcEndPos);
        fDrawState:=ARC_SET;
      end;
    ARC_SET: //确定圆弧的终点 圆弧绘制完毕
      begin
        //设置pen的格式
        ACanvas.Pen:=PicPen;
        ACanvas.Pen.Mode:=pmXor;
        //设置Brush的格式
        ACanvas.Brush:=PicBrush;
        centerX := (EndPos.x + StartPos.x) div 2; //圆心
        centerY := (EndPos.y + StartPos.y) div 2;
        //清除前一次绘制的图形
        DrawArccPic(ACanvas,StartPos,EndPos,ArcStartPos,ArcEndPos);
        //if fArccType<>ARCC_SECTOR then begin
          ACanvas.MoveTo(centerX, centerY);
          ACanvas.LineTo(arcStartPos.x, arcStartPos.y);
          ACanvas.MoveTo(centerX, centerY);
          ACanvas.LineTo(arcEndPos.x, arcEndPos.y);
        //end;
        //重画图象用来擦除
        arcEndPos := APoint;
        pp[1] := arcEndPos;
        DpToLp(ACanvas.Handle, pp[1], 1);
        arcEndPos :=PointToCirclePoint(StartPos,EndPos,pp[1]);
        //由于arcEndpoint是变化的,因此先确定刷新区域,
        //以保证最后根线即使在Arc的区域外也能被清除
        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);
        end;
        PicRect:=tmpRect;
        ACanvas.Pen := PicPen;
        ACanvas.Brush := PicBrush;
        ACanvas.Font := PicFont;
        DrawArccPic(ACanvas, StartPos,EndPos,ArcStartPos,ArcEndPos);
        FDrawState:=ARC_DRAW;
        if Assigned(DrawEndEvent) then DrawEndEvent(Self);
      end;
  end;
end;

//键盘响应
procedure TArccPic.ParentKeyDown(ACanvas:TCanvas;CursorNum:Integer; var Key: Word;
        mouse: TPoint; Shift:TShiftState);
begin
  //
end;

procedure TArccPic.ParentKeyUp(ACanvas:TCanvas;CursorNum:Integer; var Key: Word;
        mouse: TPoint; Shift: TShiftState);
begin
  //
end;

//图象改变
procedure TArccPic.PicChangeing(ACanvas:TCanvas; mouseInPos: MOUSE_POS; chooseRect:TRect;
        mouseDownOldX, mouseDownOldY, mouseOldX, mouseOldY, mouseX, mouseY:Integer);
var
  mouseDiffX: Integer;
  mouseDiffY: Integer;
  tmpSP, tmpEp: TPoint;
  tmpArcSp,tmparcep:TPoint;
  RectW,RectH:Integer;
  Center:TPoint;
  ratex,ratey:Single;
  pp: array[1..4] of TPoint;
  StartToEnd:Boolean;
  procedure ConverPointXY;
  begin
    tmpsp.X:=Center.X+ Round((StartPos.x - Center.x) *  rateX);
    tmpsp.Y:=Center.Y+ Round((StartPos.Y - Center.Y) *  rateY);
    tmpep.X:=Center.X+ Round((endPos.x - Center.x) *  rateX);
    tmpep.Y:=Center.Y+ Round((EndPos.Y - Center.Y) *  rateY);
    tmparcsp.X:=Center.X+ Round((ArcStartPos.x - Center.x) *  rateX);
    tmparcsp.Y:=Center.Y+ Round((ArcStartPos.Y - Center.Y) *  rateY);
    tmparcep.X:=Center.X+ Round((ArcendPos.x - Center.x) *  rateX);
    tmparcep.Y:=Center.Y+ Round((ArcendPos.Y - Center.Y) *  rateY);
  end;
  procedure ChangPointXY;  //坐标变换 是否交换起点和钟点
  begin
    pp[1]:=tmpsp;
    pp[2]:=tmpep;
    pp[3]:=tmparcsp;
    pp[4]:=tmparcep;
    LptoDp(ACanvas.Handle,pp[1],4);
    if StartToEnd then
      DrawArccPic(ACanvas, pp[1],pp[2],pp[4],pp[3])
    else
      DrawArccPic(ACanvas, pp[1],pp[2],pp[3],pp[4]);
  end;
begin
  //ArccKeyState:=GetPicKeyState;
  //坐标变换
  pp[1]:=Point(mouseDownOldX,mouseDownOldY);
  pp[2]:=Point(mouseOldX, mouseOldY);
  pp[3]:=Point(mouseX, mouseY);
  DPtoLP(ACanvas.Handle, pp, 3);
  mouseDownOldX := pp[1].x;
  mouseDownOldY := pp[1].y;
  mouseOldX := pp[2].x;
  mouseOldY := pp[2].y;
  mouseX := pp[3].x;
  mouseY := pp[3].y;
  //设置绘图方式
  ACanvas.Pen.Width := 1;
  ACanvas.Pen.Mode := pmXor;
  ACanvas.Pen.Style := psDot;
  ACanvas.Brush.Style := bsClear;
  //初始化变量值
  RectW:=EndPos.X-StartPos.X;
  RectH:=EndPos.Y-StartPos.Y;
  Center :=Point ((StartPos.x + Endpos.x) div 2,(StartPos.y + Endpos.y) div 2);
  StartToEnd:=False;
  //计算选择图元的宽度和高度
  case mouseInPos of
     POS_LEFTTOP: //         :Integer = 1  ; //左上
       begin
           //清除前一次
           mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           rateX := (RectW-MouseDiffX)/RectW;
           rateY := (RectH-MouseDiffY)/RectH;
           ConverPointXY;
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           rateX := (RectW-MouseDiffX)/RectW;
           rateY := (RectH-MouseDiffY)/RectH;
           //坐标变换
           ConverPointXY;
           ChangPointXY;
         //end;
       end;
     POS_RIGHTTOP: //       :Integer = 2  ; //右上
       begin
           //清除前一次
           mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           rateX := (RectW+MouseDiffX)/RectW;
           rateY := (RectH-MouseDiffY)/RectH;
           ConverPointXY;
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           rateX := (RectW+MouseDiffX)/RectW;
           rateY := (RectH-MouseDiffY)/RectH;
           //坐标变换
           ConverPointXY;
           ChangPointXY;
         //end;
       end;
     POS_RIGHTBOTTOM: //    :Integer = 3  ; //右下
       begin
           //清除前一次
           mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           rateX := (RectW+MouseDiffX)/RectW;
           rateY := (RectH+MouseDiffY)/RectH;
           ConverPointXY;
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           rateX := (RectW+MouseDiffX)/RectW;
           rateY := (RectH+MouseDiffY)/RectH;
           //坐标变换
           ConverPointXY;
           ChangPointXY;
         //end;
       end;
     POS_LEFTBOTTOM: //       :Integer = 4  ; //左下
       begin
           //清除前一次
           mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           rateX := (RectW-MouseDiffX)/RectW;
           rateY := (RectH+MouseDiffY)/RectH;
           ConverPointXY;
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           rateX := (RectW-MouseDiffX)/RectW;
           rateY := (RectH+MouseDiffY)/RectH;
           //坐标变换
           ConverPointXY;
           ChangPointXY;
         //end;
       end;
     POS_CENTERTOP: //       :Integer = 5  ; //上中
       begin
           //清除前一次
           //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_RIGHTCENTER: //     :Integer = 6  ; //右中
       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_CENTERBUTTOM: //    :Integer = 7  ; //下中
       begin
           //清除前一次
           //mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           rateX :=1; // (RectW-MouseDiffX)/RectW;
           rateY := (RectH+MouseDiffY)/RectH;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -