Changeset 145 for trunk/Packages/Common/MetaCanvas.pas
- Timestamp:
- Jun 5, 2023, 6:44:57 PM (18 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/MetaCanvas.pas
r144 r145 1 unit UMetaCanvas;1 unit MetaCanvas; 2 2 3 3 interface 4 4 5 5 uses 6 Classes, SysUtils, Graphics, Types, fgl;6 Classes, SysUtils, Graphics, Types, Generics.Collections; 7 7 8 8 type … … 17 17 end; 18 18 19 TCanvasObjects = class(T FPGObjectList<TCanvasObject>)19 TCanvasObjects = class(TObjectList<TCanvasObject>) 20 20 end; 21 21 … … 63 63 64 64 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) 65 91 Pen: TPen; 66 92 Brush: TBrush; … … 133 159 procedure DoMoveTo(X, Y: Integer); override; 134 160 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; 135 164 public 136 165 Objects: TCanvasObjects; … … 141 170 procedure TextOut(X,Y: Integer; const Text: String); override; 142 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; 143 175 procedure Ellipse(x1, y1, x2, y2: Integer); override; 144 176 procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); override; … … 159 191 160 192 uses 161 UGeometric, LCLIntf; 193 Geometric, LCLIntf; 194 195 { TCanvasPolyBezier } 196 197 procedure TCanvasPolyBezier.Paint(Canvas: TCanvas); 198 begin 199 Canvas.Pen.Assign(Pen); 200 Canvas.Brush.Assign(Brush); 201 Canvas.PolyBezier(Points); 202 end; 203 204 procedure TCanvasPolyBezier.Zoom(Factor: Double); 205 var 206 I: Integer; 207 begin 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); 212 end; 213 214 procedure TCanvasPolyBezier.Move(Delta: TPoint); 215 var 216 I: Integer; 217 begin 218 for I := 0 to High(Points) do 219 Points[I] := AddPoint(Points[I], Delta); 220 end; 221 222 constructor TCanvasPolyBezier.Create; 223 begin 224 Pen := TPen.Create; 225 Brush := TBrush.Create; 226 end; 227 228 destructor TCanvasPolyBezier.Destroy; 229 begin 230 FreeAndNil(Brush); 231 FreeAndNil(Pen); 232 inherited; 233 end; 234 235 { TCanvasPolyline } 236 237 procedure TCanvasPolyline.Paint(Canvas: TCanvas); 238 begin 239 Canvas.Pen.Assign(Pen); 240 Canvas.Brush.Assign(Brush); 241 Canvas.Polyline(Points); 242 end; 243 244 procedure TCanvasPolyline.Zoom(Factor: Double); 245 var 246 I: Integer; 247 begin 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); 252 end; 253 254 procedure TCanvasPolyline.Move(Delta: TPoint); 255 var 256 I: Integer; 257 begin 258 for I := 0 to High(Points) do 259 Points[I] := AddPoint(Points[I], Delta); 260 end; 261 262 constructor TCanvasPolyline.Create; 263 begin 264 Pen := TPen.Create; 265 Brush := TBrush.Create; 266 end; 267 268 destructor TCanvasPolyline.Destroy; 269 begin 270 FreeAndNil(Brush); 271 FreeAndNil(Pen); 272 inherited; 273 end; 162 274 163 275 { TCanvasPie } … … 304 416 destructor TCanvasPolygon.Destroy; 305 417 begin 306 Brush.Free;307 Pen.Free;418 FreeAndNil(Brush); 419 FreeAndNil(Pen); 308 420 inherited; 309 421 end; … … 511 623 APoints[I] := Points[I]; 512 624 DoPolygon(APoints); 625 end; 626 627 procedure TMetaCanvas.Polyline(Points: PPoint; NumPts: Integer); 628 var 629 APoints: array of TPoint; 630 I: Integer; 631 begin 632 APoints := nil; 633 SetLength(APoints, NumPts); 634 for I := 0 to High(APoints) do 635 APoints[I] := Points[I]; 636 DoPolyline(APoints); 637 end; 638 639 procedure TMetaCanvas.PolyBezier(Points: PPoint; NumPts: Integer; 640 Filled: Boolean; Continuous: Boolean); 641 begin 642 DoPolyBezier(Points, NumPts, Filled, Continuous); 513 643 end; 514 644 … … 580 710 end; 581 711 712 procedure TMetaCanvas.DoPolyline(const Points: array of TPoint); 713 var 714 NewObj: TCanvasPolyline; 715 I: Integer; 716 begin 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); 724 end; 725 726 procedure TMetaCanvas.DoPolyBezier(Points: PPoint; NumPts: Integer; 727 Filled: Boolean; Continuous: Boolean); 728 var 729 NewObj: TCanvasPolyBezier; 730 I: Integer; 731 begin 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); 739 end; 740 582 741 procedure TMetaCanvas.FillRect(const ARect: TRect); 583 742 begin … … 664 823 665 824 end. 666
Note:
See TracChangeset
for help on using the changeset viewer.