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

📄 linepic.pas

📁 矢量图源代码 包括直线文本矩形等等
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  ACanvas.Font := PicFont;
  DrawLinePic(ACanvas, StartPos,EndPos);
  if Assigned(DrawEndEvent) then DrawEndEvent(Self);
end;


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

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

procedure TLinePic.PicChangeing(ACanvas:TCanvas; mouseInPos: MOUSE_POS; chooseRect:TRect;
        mouseDownOldX, mouseDownOldY, mouseOldX, mouseOldY, mouseX, mouseY:Integer);
var
  mouseDiffX: Integer;
  mouseDiffY: Integer;
  tempStartPoint, tempEndPoint,Center: TPoint;
  pp: array[1..3] of TPoint;
  procedure ChangPointXY;  //坐标变换
  begin
    pp[1]:=tempstartpoint;
    pp[2]:=tempendpoint;
    LptoDp(ACanvas.Handle,pp[1],2);
    tempstartpoint:=pp[1];
    tempendpoint:=pp[2];
    DrawLinePic(ACanvas, tempStartPoint, tempEndPoint);
  end;
begin
  //坐标变换
  LineKeyState:=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;
  //计算选择图元的宽度和高度
  case mouseInPos of
    POS_CENTER:
       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;
     POS_LINESTART: //=10: //直线起点
       begin
         if (ssCtrl in LineKeyState) then begin
           //清除前一次
           Center :=Point ((StartPos.x + Endpos.x) div 2,(StartPos.y + Endpos.y) div 2);
           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 else begin
           //清除前一次
           mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           tempStartPoint :=Point(startPos.x + mouseDiffX, startPos.y + mouseDiffY);
           tempEndPoint :=endPos;
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           tempStartPoint :=Point(startPos.x + mouseDiffX, startPos.y + mouseDiffY);
           tempEndPoint := endPos; //+ mouseDiffX;
           //坐标变换
           ChangPointXY;
         end;
       end;
     POS_LINEEND: //=11: //直线终点
       begin
         if (ssCtrl in LineKeyState) then begin
           Center :=Point ((StartPos.x + Endpos.x) div 2,(StartPos.y + Endpos.y) div 2);
           //交换坐标
           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 else begin
           //清除前一次
           mouseDiffX := mouseOldX - mouseDownOldX;
           mouseDiffY := mouseOldY - mouseDownOldY;
           //绘制图元
           tempStartPoint := startPos; //+ mouseDiffX;
           tempEndPoint :=Point(endPos.x + mouseDiffX,endPos.y + mouseDiffY);
           //坐标变换
           ChangPointXY;
           //绘制当前虚线图元
           mouseDiffX := mouseX - mouseDownOldX;
           mouseDiffY := mouseY - mouseDownOldY;
           //绘制图元
           tempStartPoint := startPos; //+ mouseDiffX;
           tempEndPoint :=Point(endPos.x + mouseDiffX, endPos.y + mouseDiffY);
           //坐标变换
           ChangPointXY;
         end;
       end;
  end;
end;

procedure TLinePic.PicChangedUpdate(ACanvas:TCanvas; mouseInPos: MOUSE_POS;
  //鼠标位置
  chooseRect: TRect; //选择图元形成的矩形
  mouseDownOldX, mouseDownOldY: Integer; //mouse Down 时的坐标
  mouseX, mouseY: Integer); //鼠标当前的坐标
var
  tmprect:TRect;
  Center:TPoint;
begin
  //计算选择图元的宽度和高度
  case mouseInPos of
    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;
    POS_LINESTART: //=10:  //直线起点
      begin
        if (ssCtrl in LineKeyState) then begin
          Center.X:=(StartPos.X+EndPos.X) div 2;
          center.Y:=(StartPos.Y+EndPos.Y) div 2;
          StartPos:=Point(Mousex,mouseY);
          EndPos.X:=Center.x+(Center.x-StartPos.X);
          EndPos.Y:=Center.Y+(Center.Y-StartPos.Y);
        end else begin
          Inc(startPos.x, mouseX - mouseDownOldX);
          Inc(startPos.y, mousey - mouseDownOldY);
        end;
      end;
    POS_LINEEND: //=11:  //直线终点
      begin
        if (ssCtrl in LineKeyState) then begin
          Center.X:=(StartPos.X+EndPos.X) div 2;
          center.Y:=(StartPos.Y+EndPos.Y) div 2;
          EndPos:=Point(Mousex,mouseY);
          StartPos.X:=Center.x-(EndPos.X-Center.x);
          StartPos.Y:=Center.Y-(EndPos.Y-Center.Y);
        end else begin
          Inc(endPos.x, mouseX - mouseDownOldX);
          Inc(endPos.y, mousey - mouseDownOldY);
        end;
      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;
  PicRect:=tmpRect;
end;

//判断(x,y) 点是否在图元矩形区域内
//位置代码可参见 PicConst.pas
procedure TLinePic.AssignPic(SourcePic: TPicBase);
begin
  inherited AssignPic(SourcePic);
  StartPos := TLinePic(SourcePic).PicStartPoint;
  EndPos := TLinePic(SourcePic).PicEndPoint;
end;


procedure TLinePic.DrawLinePic(ACanvas:TCanvas; startPoint:TPoint; endPoint:TPoint);
begin
  ACanvas.MoveTo(startPoint.X, startPoint.Y);
  ACanvas. LineTo(endPoint.X, endPoint.Y);
  PicId:=PIC_LINE;
end;

procedure TLinePic.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));
  //Len:=oLen+AddrOffSet(op,P);
  Len:=oLen+LongInt(P)-LongInt(Op);
end;

procedure TLinePic.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));
  //Len:=oLen+AddrOffSet(op,P);
  Len:=oLen+LongInt(P)-LongInt(Op);
end;


end.

⌨️ 快捷键说明

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