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

📄 polypic.pas

📁 矢量图源代码 包括直线文本矩形等等
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    ACanvas.Pen.Mode:=pmXor;
    //设置Brush的格式
    ACanvas.Brush:=PicBrush;
    DrawState:=True;
    Inc(fPolyPoint.fPolyPointNum,2);
    SetLength(fPolyPoint.aPolyPoint,fPolyPoint.fPolyPointNum);
    fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2]:=APoint;
    fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1]:=APoint;
  end else begin
    if Button=mbRight then begin
      DrawState:=False;
      ACanvas.Pen:=PicPen;  //设置pen的格式
      ACanvas.Pen.Mode:=pmXor;
      //设置Brush的格式
      ACanvas.Brush:=PicBrush;
      ACanvas.MoveTo(fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2].X,
          fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2].Y);
      ACanvas.LineTo(fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1].X,
          fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1].Y);
      if fPolyPoint.fPolyPointNum=2 then begin
        fPolyPoint.fPolyPointNum:=0;
        Picid:=PIC_NONE;
        DrawState:=False;
        Exit;
      end;
      SetLength(bPolyPoint,fPolyPoint.fPolyPointNum-1);
      for i:=0 to fPolyPoint.fPolyPointNum-2 do bPolyPoint[i]:=fPolyPoint.aPolyPoint[i];
      Dec(fPolyPoint.fPolyPointNum);
      SetLength(fPolyPoint.aPolyPoint,fPolyPoint.fPolyPointNum);
      for i:=0 to fPolyPoint.fPolyPointNum-1 do fPolyPoint.aPolyPoint[i]:=bPolyPoint[i];
      if fPolyType=PolyClose then begin
        ACanvas.MoveTo(fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1].X,
            fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1].Y);
        ACanvas.LineTo(fPolyPoint.aPolyPoint[0].X, fPolyPoint.aPolyPoint[0].Y);
      end;
      PicId:=PIC_POLY;
      DrawState:=False;
      SetPolyPicRect;
      DrawFocusRect(ACanvas);
      if Assigned(DrawEndEvent) then DrawEndEvent(Self);
    end else begin
      ACanvas.Pen:=PicPen;
      ACanvas.Pen.Mode:=pmXor;
      //设置Brush的格式
      ACanvas.Brush:=PicBrush;
      SetLength(bPolyPoint,fPolyPoint.fPolyPointNum-1);
      for i:=0 to fPolyPoint.fPolyPointNum-2 do bPolyPoint[i]:=fPolyPoint.aPolyPoint[i];
      Inc(fPolyPoint.fPolyPointNum);
      SetLength(fPolyPoint.aPolyPoint,fPolyPoint.fPolyPointNum);
      for i:=0 to fPolyPoint.fPolyPointNum-2 do fPolyPoint.aPolyPoint[i]:=bPolyPoint[i];
      fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2]:=APoint;
      fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1]:=APoint;
    end;
  end;
end;

procedure TPolyPic.ParentMouseMove(ACanvas:TCanvas;CursorNum:Integer; Shift: TShiftState;APoint:TPoint);
begin
  if DrawState then begin //绘制多边形开始
    ACanvas.Pen:=PicPen;  //设置pen的格式
    ACanvas.Pen.Mode:=pmXor;
    //设置Brush的格式
    ACanvas.Brush:=PicBrush;
    ACanvas.MoveTo(fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2].X,
        fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2].Y);
    ACanvas.LineTo(fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1].X,
        fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1].Y);
    ACanvas.MoveTo(fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2].X,
        fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-2].Y);
    ACanvas.LineTo(APoint.x, APoint.y);
    fPolyPoint.aPolyPoint[fPolyPoint.fPolyPointNum-1]:=APoint;
  end;
end;

procedure TPolyPic.ParentMouseUp(ACanvas:TCanvas;CursorNum:Integer; Button: TMouseButton;  Shift: TShiftState; APoint:TPoint);
begin
  if Button = mbRight then begin
    DrawState:=False;
    DrawFocusRect(ACanvas);
  end
end;

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

end;

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

end;

//图象改变
procedure TPolyPic.PicChangeing(ACanvas:TCanvas; mouseInPos: MOUSE_POS; chooseRect:TRect;
        mouseDownOldX, mouseDownOldY, mouseOldX, mouseOldY, mouseX, mouseY:Integer);
var
  mouseDiffX: Integer;
  mouseDiffY: Integer;
  Center:TPoint;
  ratex,ratey:Single;
  RectW,RectH: Integer; //选择图元的宽度和高度
  tmpPoint:Array of TPoint;
  pp: array[1..3] of TPoint;
  i: Integer;
  procedure ConverPointXY;
  var
    j: Integer;
  begin
    for j:= 0 to fPolyPoint.fPolyPointNum-1 do begin
      tmpPoint[j].x := center.x + Round((fPolyPoint.aPolyPoint[j].x - center.x) * rateX);
      tmpPoint[j].y := center.y + Round((fPolyPoint.aPolyPoint[j].y - center.y) * rateY);
    end;
  end;
  procedure ChangPointXY;  //坐标变换 是否交换起点和钟点
  begin
    //顶点坐标变换
    LpToDp(ACanvas.Handle, tmpPoint[0],fPolyPoint.fPolyPointNum);
    DrawPolyPic(ACanvas, tmpPoint);
  end;
  procedure ChangPolyPointXY;
  begin
    if mouseFocus = 0 then  begin
      Case fPolyType of
        PolyOpen:
          begin
            ACanvas.moveTo(tmpPoint[MouseFocus].x, tmpPoint[MouseFocus].y);
            ACanvas.lineTo(tmpPoint[MouseFocus +1].x, tmpPoint[MouseFocus +1].y);
          end;
        PolyClose:
          begin
            ACanvas.MoveTo(tmpPoint[fPolyPoint.fPolyPointNum-1].x, tmpPoint[fPolyPoint.fPolyPointNum-1].y);
            ACanvas.LineTo(tmpPoint[MouseFocus].x, tmpPoint[MouseFocus].y);
            ACanvas.lineTo(tmpPoint[MouseFocus + 1].x, tmpPoint[MouseFocus + 1].y);
          end;
      end;
    end else if (mouseFocus=fPolyPoint.fPolyPointNum-1) then begin
      Case fPolyType of
        PolyOpen:
          begin
            ACanvas.moveTo(tmpPoint[MouseFocus].x, tmpPoint[MouseFocus].y);
            ACanvas.lineTo(tmpPoint[MouseFocus-1].x, tmpPoint[MouseFocus-1].y);
          end;
        PolyClose:
          begin
            ACanvas.MoveTo(tmpPoint[fPolyPoint.fPolyPointNum-2].x, tmpPoint[fPolyPoint.fPolyPointNum-2].y);
            ACanvas.LineTo(tmpPoint[MouseFocus].x, tmpPoint[MouseFocus].y);
            ACanvas.lineTo(tmpPoint[0].x, tmpPoint[0].y);
          end;
      end;
    end else  begin
      ACanvas.MoveTo(tmpPoint[MouseFocus - 1].x, tmpPoint[MouseFocus - 1].y);
      ACanvas.LineTo(tmpPoint[MouseFocus].x, tmpPoint[MouseFocus].y);
      ACanvas.lineTo(tmpPoint[MouseFocus + 1].x, tmpPoint[MouseFocus + 1].y);
    end;
  end;
begin
  pp[1].x := mouseDownOldX;
  pp[1].y := mouseDownOldY;
  pp[2].x := mouseOldX;
  pp[2].y := mouseOldY;
  pp[3].x := mouseX;
  pp[3].y := mouseY;
  DPtoLP(ACanvas.Handle, pp[1], 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:=ChooseRect.Right - ChooseRect.Left;
  RectH:=ChooseRect.Bottom - ChooseRect.Top;
  //设置数组长度
  SetLength(tmpPoint, fPolyPoint.fPolyPointNum);
  //计算选择图元的宽度和高度
  case mouseInPos of
    POS_LEFTTOP: //         :Integer = 1  ; //左上
      begin
        //确定基准点
        Center.X:=ChooseRect.Right;
        Center.y := ChooseRect.Bottom;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseOldX - mouseDownOldX;
        mouseDiffY := mouseOldY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW - mouseDiffX) / RectW;
        Ratey := (RectH - mouseDiffY) / RectH;
        //绘制前一次虚线图元
        ConverPointXY;
        ChangPointXY;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseX - mouseDownOldX;
        mouseDiffY := mouseY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW - mouseDiffX) / RectW;
        Ratey := (RectH - mouseDiffY) / RectH;
        //绘制当前虚线图元
        ConverPointXY;
        ChangPointXY;
      end;
    POS_RIGHTTOP: //        :Integer = 2  ; //右上
      begin
        //确定基准点
        Center.x := ChooseRect.Left;
        Center.y := ChooseRect.Bottom;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseOldX - mouseDownOldX;
        mouseDiffY := mouseOldY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW + mouseDiffX) / RectW;
        Ratey := (RectH - mouseDiffY) / RectH;
        //绘制前一次虚线图元
        ConverPointXY;
        ChangPointXY;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseX - mouseDownOldX;
        mouseDiffY := mouseY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW + mouseDiffX) / RectW;
        Ratey := (RectH - mouseDiffY) / RectH;
        //绘制前一次虚线图元
        ConverPointXY;
        ChangPointXY;
      end;
    POS_RIGHTBOTTOM: //    :Integer = 3  ; //右下
      begin
        //确定基准点
        Center.x := ChooseRect.Left;
        Center.y := ChooseRect.Top;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseOldX - mouseDownOldX;
        mouseDiffY := mouseOldY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW + mouseDiffX) / RectW;
        Ratey := (RectH + mouseDiffY) / RectH;
        //绘制前一次虚线图元
        ConverPointXY;
        ChangPointXY;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseX - mouseDownOldX;
        mouseDiffY := mouseY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW + mouseDiffX) / RectW;
        Ratey := (RectH + mouseDiffY) / RectH;
        //绘制前一次虚线图元
        ConverPointXY;
        ChangPointXY;
      end;
    POS_LEFTBOTTOM: //      :Integer = 4  ; //左下
      begin
        //确定基准点
        Center.x := ChooseRect.Right;
        Center.y := ChooseRect.Top;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseOldX - mouseDownOldX;
        mouseDiffY := mouseOldY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW - mouseDiffX) / RectW;
        Ratey := (RectH + mouseDiffY) / RectH;
        //绘制前一次虚线图元
        ConverPointXY;
        ChangPointXY;
        //鼠标当前位置与鼠标Down的差别
        mouseDiffX := mouseX - mouseDownOldX;
        mouseDiffY := mouseY - mouseDownOldY;
        //计算变化比例
        Ratex := (RectW - mouseDiffX) / RectW;
        Ratey := (RectH + mouseDiffY) / RectH;
        //绘制前一次虚线图元
        ConverPointXY;
        ChangPointXY;
      end;
    POS_CENTERTOP: //       :Integer = 5  ; //上中
      begin
        //确定基准点
        Center.x := ChooseRect.Right;
        Center.y := ChooseRect.Bottom;
        //鼠标当前位置与鼠标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_RIGHTCENTER: //    :Integer = 6  ; //右中
      begin
        //确定基准点
        Center.x := ChooseRect.Left;
        Center.y := ChooseRect.Bottom;
        //鼠标当前位置与鼠标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;
        //绘制前一次虚线图元

⌨️ 快捷键说明

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