Ignore:
Timestamp:
Jun 28, 2024, 11:08:43 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/MetaCanvas.pas

    r29 r30  
    1 unit UMetaCanvas;
     1unit MetaCanvas;
    22
    33interface
     
    6363
    6464  TCanvasPolygon = class(TCanvasObject)
     65    Pen: TPen;
     66    Brush: TBrush;
     67    Points: array of TPoint;
     68    procedure Paint(Canvas: TCanvas); override;
     69    procedure Zoom(Factor: Double); override;
     70    procedure Move(Delta: TPoint); override;
     71    constructor Create;
     72    destructor Destroy; override;
     73  end;
     74
     75  { TCanvasPolyline }
     76
     77  TCanvasPolyline = class(TCanvasObject)
     78    Pen: TPen;
     79    Brush: TBrush;
     80    Points: array of TPoint;
     81    procedure Paint(Canvas: TCanvas); override;
     82    procedure Zoom(Factor: Double); override;
     83    procedure Move(Delta: TPoint); override;
     84    constructor Create;
     85    destructor Destroy; override;
     86  end;
     87
     88  { TCanvasPolyBezier }
     89
     90  TCanvasPolyBezier = class(TCanvasObject)
    6591    Pen: TPen;
    6692    Brush: TBrush;
     
    133159    procedure DoMoveTo(X, Y: Integer); override;
    134160    procedure DoLineTo(X, Y: Integer); override;
     161    procedure DoPolyline(const Points: array of TPoint); override;
     162    procedure DoPolyBezier(Points: PPoint; NumPts: Integer;
     163      Filled: Boolean = False; Continuous: Boolean = False); override;
    135164  public
    136165    Objects: TCanvasObjects;
     
    141170    procedure TextOut(X,Y: Integer; const Text: String); override;
    142171    procedure Polygon(Points: PPoint; NumPts: Integer; Winding: Boolean = False); override;
     172    procedure Polyline(Points: PPoint; NumPts: Integer); override;
     173    procedure PolyBezier(Points: PPoint; NumPts: Integer;
     174      Filled: Boolean = False; Continuous: Boolean = True); override;
    143175    procedure Ellipse(x1, y1, x2, y2: Integer); override;
    144176    procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); override;
     
    159191
    160192uses
    161   UGeometric, LCLIntf;
     193  Geometric, LCLIntf;
     194
     195{ TCanvasPolyBezier }
     196
     197procedure TCanvasPolyBezier.Paint(Canvas: TCanvas);
     198begin
     199  Canvas.Pen.Assign(Pen);
     200  Canvas.Brush.Assign(Brush);
     201  Canvas.PolyBezier(Points);
     202end;
     203
     204procedure TCanvasPolyBezier.Zoom(Factor: Double);
     205var
     206  I: Integer;
     207begin
     208  for I := 0 to High(Points) do
     209    Points[I] := Point(Trunc(Points[I].X * Factor),
     210      Trunc(Points[I].Y * Factor));
     211  Pen.Width := Trunc(Pen.Width * Factor);
     212end;
     213
     214procedure TCanvasPolyBezier.Move(Delta: TPoint);
     215var
     216  I: Integer;
     217begin
     218  for I := 0 to High(Points) do
     219    Points[I] := AddPoint(Points[I], Delta);
     220end;
     221
     222constructor TCanvasPolyBezier.Create;
     223begin
     224  Pen := TPen.Create;
     225  Brush := TBrush.Create;
     226end;
     227
     228destructor TCanvasPolyBezier.Destroy;
     229begin
     230  FreeAndNil(Brush);
     231  FreeAndNil(Pen);
     232  inherited;
     233end;
     234
     235{ TCanvasPolyline }
     236
     237procedure TCanvasPolyline.Paint(Canvas: TCanvas);
     238begin
     239  Canvas.Pen.Assign(Pen);
     240  Canvas.Brush.Assign(Brush);
     241  Canvas.Polyline(Points);
     242end;
     243
     244procedure TCanvasPolyline.Zoom(Factor: Double);
     245var
     246  I: Integer;
     247begin
     248  for I := 0 to High(Points) do
     249    Points[I] := Point(Trunc(Points[I].X * Factor),
     250      Trunc(Points[I].Y * Factor));
     251  Pen.Width := Trunc(Pen.Width * Factor);
     252end;
     253
     254procedure TCanvasPolyline.Move(Delta: TPoint);
     255var
     256  I: Integer;
     257begin
     258  for I := 0 to High(Points) do
     259    Points[I] := AddPoint(Points[I], Delta);
     260end;
     261
     262constructor TCanvasPolyline.Create;
     263begin
     264  Pen := TPen.Create;
     265  Brush := TBrush.Create;
     266end;
     267
     268destructor TCanvasPolyline.Destroy;
     269begin
     270  FreeAndNil(Brush);
     271  FreeAndNil(Pen);
     272  inherited;
     273end;
    162274
    163275{ TCanvasPie }
     
    304416destructor TCanvasPolygon.Destroy;
    305417begin
    306   Brush.Free;
    307   Pen.Free;
     418  FreeAndNil(Brush);
     419  FreeAndNil(Pen);
    308420  inherited;
    309421end;
     
    511623    APoints[I] := Points[I];
    512624  DoPolygon(APoints);
     625end;
     626
     627procedure TMetaCanvas.Polyline(Points: PPoint; NumPts: Integer);
     628var
     629  APoints: array of TPoint;
     630  I: Integer;
     631begin
     632  APoints := nil;
     633  SetLength(APoints, NumPts);
     634  for I := 0 to High(APoints) do
     635    APoints[I] := Points[I];
     636  DoPolyline(APoints);
     637end;
     638
     639procedure TMetaCanvas.PolyBezier(Points: PPoint; NumPts: Integer;
     640  Filled: Boolean; Continuous: Boolean);
     641begin
     642  DoPolyBezier(Points, NumPts, Filled, Continuous);
    513643end;
    514644
     
    580710end;
    581711
     712procedure TMetaCanvas.DoPolyline(const Points: array of TPoint);
     713var
     714  NewObj: TCanvasPolyline;
     715  I: Integer;
     716begin
     717  NewObj := TCanvasPolyline.Create;
     718  NewObj.Brush.Assign(Brush);
     719  NewObj.Pen.Assign(Pen);
     720  SetLength(NewObj.Points, Length(Points));
     721  for I := 0 to High(Points) do
     722    NewObj.Points[I] := Points[I];
     723  Objects.Add(NewObj);
     724end;
     725
     726procedure TMetaCanvas.DoPolyBezier(Points: PPoint; NumPts: Integer;
     727  Filled: Boolean; Continuous: Boolean);
     728var
     729  NewObj: TCanvasPolyBezier;
     730  I: Integer;
     731begin
     732  NewObj := TCanvasPolyBezier.Create;
     733  NewObj.Brush.Assign(Brush);
     734  NewObj.Pen.Assign(Pen);
     735  SetLength(NewObj.Points, NumPts);
     736  for I := 0 to High(NewObj.Points) do
     737    NewObj.Points[I] := Points[I];
     738  Objects.Add(NewObj);
     739end;
     740
    582741procedure TMetaCanvas.FillRect(const ARect: TRect);
    583742begin
     
    664823
    665824end.
    666 
Note: See TracChangeset for help on using the changeset viewer.