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

Legend:

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

    r84 r85  
    1 unit UMetaCanvas;
    2 
    3 {$mode delphi}
     1unit MetaCanvas;
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, Graphics, Contnrs, Types, fgl;
     6  Classes, SysUtils, Graphics, Types, Generics.Collections;
    97
    108type
     
    1917  end;
    2018
    21   TCanvasObjects = class(TFPGObjectList<TCanvasObject>)
     19  TCanvasObjects = class(TObjectList<TCanvasObject>)
    2220  end;
    2321
     
    6563
    6664  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)
    6791    Pen: TPen;
    6892    Brush: TBrush;
     
    135159    procedure DoMoveTo(X, Y: Integer); override;
    136160    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;
    137164  public
    138165    Objects: TCanvasObjects;
     
    142169    procedure RoundRect(const Rect: TRect; RX,RY: Integer); overload;
    143170    procedure TextOut(X,Y: Integer; const Text: String); override;
    144     procedure Polygon(Points: PPoint; NumPts: Integer; Winding: boolean = False); override;
     171    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;
    145175    procedure Ellipse(x1, y1, x2, y2: Integer); override;
    146176    procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); override;
     
    161191
    162192uses
    163   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;
    164274
    165275{ TCanvasPie }
     
    306416destructor TCanvasPolygon.Destroy;
    307417begin
    308   Brush.Free;
    309   Pen.Free;
     418  FreeAndNil(Brush);
     419  FreeAndNil(Pen);
    310420  inherited;
    311421end;
     
    502612end;
    503613
    504 procedure TMetaCanvas.Polygon(Points: PPoint; NumPts: Integer; Winding: boolean
     614procedure TMetaCanvas.Polygon(Points: PPoint; NumPts: Integer; Winding: Boolean
    505615  );
    506616var
     
    508618  I: Integer;
    509619begin
     620  APoints := nil;
    510621  SetLength(APoints, NumPts);
    511622  for I := 0 to High(APoints) do
    512623    APoints[I] := Points[I];
    513624  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);
    514643end;
    515644
     
    581710end;
    582711
     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
    583741procedure TMetaCanvas.FillRect(const ARect: TRect);
    584742begin
     
    665823
    666824end.
    667 
Note: See TracChangeset for help on using the changeset viewer.