1 | unit MetaCanvas;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Graphics, Types, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TArrayOfPoint = array of TPoint;
|
---|
10 |
|
---|
11 | { TCanvasObject }
|
---|
12 |
|
---|
13 | TCanvasObject = class
|
---|
14 | procedure Paint(Canvas: TCanvas); virtual;
|
---|
15 | procedure Zoom(Factor: Double); virtual;
|
---|
16 | procedure Move(Delta: TPoint); virtual;
|
---|
17 | end;
|
---|
18 |
|
---|
19 | TCanvasObjects = class(TObjectList<TCanvasObject>)
|
---|
20 | end;
|
---|
21 |
|
---|
22 | { TCanvasText }
|
---|
23 |
|
---|
24 | TCanvasText = class(TCanvasObject)
|
---|
25 | Brush: TBrush;
|
---|
26 | Font: TFont;
|
---|
27 | Position: TPoint;
|
---|
28 | Text: string;
|
---|
29 | procedure Paint(Canvas: TCanvas); override;
|
---|
30 | procedure Zoom(Factor: Double); override;
|
---|
31 | procedure Move(Delta: TPoint); override;
|
---|
32 | constructor Create;
|
---|
33 | destructor Destroy; override;
|
---|
34 | end;
|
---|
35 |
|
---|
36 | { TCanvasRectangle }
|
---|
37 |
|
---|
38 | TCanvasRectangle = class(TCanvasObject)
|
---|
39 | Pen: TPen;
|
---|
40 | Brush: TBrush;
|
---|
41 | BoundingRect: TRect;
|
---|
42 | Rounded: TPoint;
|
---|
43 | procedure Paint(Canvas: TCanvas); override;
|
---|
44 | procedure Zoom(Factor: Double); override;
|
---|
45 | procedure Move(Delta: TPoint); override;
|
---|
46 | constructor Create;
|
---|
47 | destructor Destroy; override;
|
---|
48 | end;
|
---|
49 |
|
---|
50 | { TCanvasLine }
|
---|
51 |
|
---|
52 | TCanvasLine = class(TCanvasObject)
|
---|
53 | Pen: TPen;
|
---|
54 | P1, P2: TPoint;
|
---|
55 | procedure Paint(Canvas: TCanvas); override;
|
---|
56 | procedure Zoom(Factor: Double); override;
|
---|
57 | procedure Move(Delta: TPoint); override;
|
---|
58 | constructor Create;
|
---|
59 | destructor Destroy; override;
|
---|
60 | end;
|
---|
61 |
|
---|
62 | { TCanvasPolygon }
|
---|
63 |
|
---|
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)
|
---|
91 | Pen: TPen;
|
---|
92 | Brush: TBrush;
|
---|
93 | Points: array of TPoint;
|
---|
94 | procedure Paint(Canvas: TCanvas); override;
|
---|
95 | procedure Zoom(Factor: Double); override;
|
---|
96 | procedure Move(Delta: TPoint); override;
|
---|
97 | constructor Create;
|
---|
98 | destructor Destroy; override;
|
---|
99 | end;
|
---|
100 |
|
---|
101 | { TCanvasEllipse }
|
---|
102 |
|
---|
103 | TCanvasEllipse = class(TCanvasObject)
|
---|
104 | Pen: TPen;
|
---|
105 | Brush: TBrush;
|
---|
106 | BoundingRect: TRect;
|
---|
107 | procedure Paint(Canvas: TCanvas); override;
|
---|
108 | procedure Zoom(Factor: Double); override;
|
---|
109 | procedure Move(Delta: TPoint); override;
|
---|
110 | constructor Create;
|
---|
111 | destructor Destroy; override;
|
---|
112 | end;
|
---|
113 |
|
---|
114 | { TCanvasPie }
|
---|
115 |
|
---|
116 | TCanvasPie = class(TCanvasObject)
|
---|
117 | Pen: TPen;
|
---|
118 | Brush: TBrush;
|
---|
119 | BoundingRect: TRect;
|
---|
120 | StartPoint: TPoint;
|
---|
121 | EndPoint: TPoint;
|
---|
122 | procedure Paint(Canvas: TCanvas); override;
|
---|
123 | procedure Zoom(Factor: Double); override;
|
---|
124 | procedure Move(Delta: TPoint); override;
|
---|
125 | constructor Create;
|
---|
126 | destructor Destroy; override;
|
---|
127 | end;
|
---|
128 |
|
---|
129 | { TCanvasStretchDraw }
|
---|
130 |
|
---|
131 | TCanvasStretchDraw = class(TCanvasObject)
|
---|
132 | SrcGraphic: TGraphic;
|
---|
133 | DestRect: TRect;
|
---|
134 | procedure Paint(Canvas: TCanvas); override;
|
---|
135 | procedure Zoom(Factor: Double); override;
|
---|
136 | procedure Move(Delta: TPoint); override;
|
---|
137 | constructor Create;
|
---|
138 | destructor Destroy; override;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | { TMetaCanvas }
|
---|
142 |
|
---|
143 | TMetaCanvas = class(TCanvas)
|
---|
144 | private
|
---|
145 | FSize: TPoint;
|
---|
146 | FPenPos: TPoint;
|
---|
147 | protected
|
---|
148 | procedure SetHeight(AValue: Integer); override;
|
---|
149 | function GetHeight: Integer; override;
|
---|
150 | procedure SetWidth(AValue: Integer); override;
|
---|
151 | function GetWidth: Integer; override;
|
---|
152 | procedure DoLine (x1,y1,x2,y2:integer); override;
|
---|
153 | procedure DoTextOut(X, Y: Integer; Text: string); override;
|
---|
154 | procedure DoRectangle(const Bounds: TRect); override;
|
---|
155 | procedure DoRectangleFill(const Bounds: TRect); override;
|
---|
156 | procedure DoPolygon(const Points: array of TPoint); override;
|
---|
157 | procedure CreateHandle; override;
|
---|
158 | procedure DoEllipse(const Bounds: TRect); override;
|
---|
159 | procedure DoMoveTo(X, Y: Integer); override;
|
---|
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;
|
---|
164 | public
|
---|
165 | Objects: TCanvasObjects;
|
---|
166 | procedure FillRect(const ARect: TRect); overload; override;
|
---|
167 | procedure FillRect(X1,Y1,X2,Y2: Integer); overload;
|
---|
168 | procedure RoundRect(X1, Y1, X2, Y2: Integer; RX,RY: Integer); overload; override;
|
---|
169 | procedure RoundRect(const Rect: TRect; RX,RY: Integer); overload;
|
---|
170 | procedure TextOut(X,Y: Integer; const Text: String); 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;
|
---|
175 | procedure Ellipse(x1, y1, x2, y2: Integer); override;
|
---|
176 | procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); override;
|
---|
177 | function TextExtent(const Text: string): TSize; override;
|
---|
178 | procedure Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2,
|
---|
179 | StartX, StartY, EndX, EndY: Integer); override;
|
---|
180 | procedure Reset;
|
---|
181 | procedure DrawTo(Canvas: TCanvas);
|
---|
182 | procedure Zoom(Factor: Double);
|
---|
183 | procedure Move(Delta: TPoint);
|
---|
184 | constructor Create;
|
---|
185 | destructor Destroy; override;
|
---|
186 | property Size: TPoint read FSize write FSize;
|
---|
187 | end;
|
---|
188 |
|
---|
189 |
|
---|
190 | implementation
|
---|
191 |
|
---|
192 | uses
|
---|
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;
|
---|
274 |
|
---|
275 | { TCanvasPie }
|
---|
276 |
|
---|
277 | procedure TCanvasPie.Paint(Canvas: TCanvas);
|
---|
278 | begin
|
---|
279 | Canvas.Brush.Assign(Brush);
|
---|
280 | Canvas.Pen.Assign(Pen);
|
---|
281 | Canvas.Pie(BoundingRect.Left, BoundingRect.Top,
|
---|
282 | BoundingRect.Right, BoundingRect.Bottom, StartPoint.X, StartPoint.Y,
|
---|
283 | EndPoint.X, EndPoint.Y);
|
---|
284 | end;
|
---|
285 |
|
---|
286 | procedure TCanvasPie.Zoom(Factor: Double);
|
---|
287 | begin
|
---|
288 | BoundingRect := Rect(Trunc(BoundingRect.Left * Factor),
|
---|
289 | Trunc(BoundingRect.Top * Factor),
|
---|
290 | Trunc(BoundingRect.Right * Factor),
|
---|
291 | Trunc(BoundingRect.Bottom * Factor));
|
---|
292 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
293 | StartPoint := Point(Trunc(StartPoint.X * Factor), Trunc(StartPoint.Y * Factor));
|
---|
294 | EndPoint := Point(Trunc(EndPoint.X * Factor), Trunc(EndPoint.Y * Factor));
|
---|
295 | end;
|
---|
296 |
|
---|
297 | procedure TCanvasPie.Move(Delta: TPoint);
|
---|
298 | begin
|
---|
299 | BoundingRect := ShiftRect(BoundingRect, Delta);
|
---|
300 | StartPoint := AddPoint(StartPoint, Delta);
|
---|
301 | EndPoint := AddPoint(EndPoint, Delta);
|
---|
302 | end;
|
---|
303 |
|
---|
304 | constructor TCanvasPie.Create;
|
---|
305 | begin
|
---|
306 | Pen := TPen.Create;
|
---|
307 | Brush := TBrush.Create;
|
---|
308 | end;
|
---|
309 |
|
---|
310 | destructor TCanvasPie.Destroy;
|
---|
311 | begin
|
---|
312 | Pen.Free;
|
---|
313 | Brush.Free;
|
---|
314 | inherited;
|
---|
315 | end;
|
---|
316 |
|
---|
317 | { TCanvasStretchDraw }
|
---|
318 |
|
---|
319 | procedure TCanvasStretchDraw.Paint(Canvas: TCanvas);
|
---|
320 | begin
|
---|
321 | Canvas.StretchDraw(DestRect, SrcGraphic);
|
---|
322 | end;
|
---|
323 |
|
---|
324 | procedure TCanvasStretchDraw.Zoom(Factor: Double);
|
---|
325 | begin
|
---|
326 | DestRect := Rect(Trunc(DestRect.Left * Factor),
|
---|
327 | Trunc(DestRect.Top * Factor),
|
---|
328 | Trunc(DestRect.Right * Factor),
|
---|
329 | Trunc(DestRect.Bottom * Factor));
|
---|
330 | end;
|
---|
331 |
|
---|
332 | procedure TCanvasStretchDraw.Move(Delta: TPoint);
|
---|
333 | begin
|
---|
334 | DestRect := ShiftRect(DestRect, Delta);
|
---|
335 | end;
|
---|
336 |
|
---|
337 | constructor TCanvasStretchDraw.Create;
|
---|
338 | begin
|
---|
339 | SrcGraphic := nil;
|
---|
340 | end;
|
---|
341 |
|
---|
342 | destructor TCanvasStretchDraw.Destroy;
|
---|
343 | begin
|
---|
344 | inherited;
|
---|
345 | end;
|
---|
346 |
|
---|
347 | { TCanvasEllipse }
|
---|
348 |
|
---|
349 | procedure TCanvasEllipse.Paint(Canvas: TCanvas);
|
---|
350 | begin
|
---|
351 | Canvas.Pen.Assign(Pen);
|
---|
352 | Canvas.Brush.Assign(Brush);
|
---|
353 | Canvas.Ellipse(BoundingRect);
|
---|
354 | end;
|
---|
355 |
|
---|
356 | procedure TCanvasEllipse.Zoom(Factor: Double);
|
---|
357 | begin
|
---|
358 | BoundingRect := Rect(Trunc(BoundingRect.Left * Factor),
|
---|
359 | Trunc(BoundingRect.Top * Factor),
|
---|
360 | Trunc(BoundingRect.Right * Factor),
|
---|
361 | Trunc(BoundingRect.Bottom * Factor));
|
---|
362 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
363 | end;
|
---|
364 |
|
---|
365 | procedure TCanvasEllipse.Move(Delta: TPoint);
|
---|
366 | begin
|
---|
367 | BoundingRect := ShiftRect(BoundingRect, Delta);
|
---|
368 | end;
|
---|
369 |
|
---|
370 | constructor TCanvasEllipse.Create;
|
---|
371 | begin
|
---|
372 | Pen := TPen.Create;
|
---|
373 | Brush := TBrush.Create;
|
---|
374 | end;
|
---|
375 |
|
---|
376 | destructor TCanvasEllipse.Destroy;
|
---|
377 | begin
|
---|
378 | Pen.Free;
|
---|
379 | Brush.Free;
|
---|
380 | inherited;
|
---|
381 | end;
|
---|
382 |
|
---|
383 | { TCanvasPolygon }
|
---|
384 |
|
---|
385 | procedure TCanvasPolygon.Paint(Canvas: TCanvas);
|
---|
386 | begin
|
---|
387 | Canvas.Pen.Assign(Pen);
|
---|
388 | Canvas.Brush.Assign(Brush);
|
---|
389 | Canvas.Polygon(Points);
|
---|
390 | end;
|
---|
391 |
|
---|
392 | procedure TCanvasPolygon.Zoom(Factor: Double);
|
---|
393 | var
|
---|
394 | I: Integer;
|
---|
395 | begin
|
---|
396 | for I := 0 to High(Points) do
|
---|
397 | Points[I] := Point(Trunc(Points[I].X * Factor),
|
---|
398 | Trunc(Points[I].Y * Factor));
|
---|
399 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
400 | end;
|
---|
401 |
|
---|
402 | procedure TCanvasPolygon.Move(Delta: TPoint);
|
---|
403 | var
|
---|
404 | I: Integer;
|
---|
405 | begin
|
---|
406 | for I := 0 to High(Points) do
|
---|
407 | Points[I] := AddPoint(Points[I], Delta);
|
---|
408 | end;
|
---|
409 |
|
---|
410 | constructor TCanvasPolygon.Create;
|
---|
411 | begin
|
---|
412 | Pen := TPen.Create;
|
---|
413 | Brush := TBrush.Create;
|
---|
414 | end;
|
---|
415 |
|
---|
416 | destructor TCanvasPolygon.Destroy;
|
---|
417 | begin
|
---|
418 | FreeAndNil(Brush);
|
---|
419 | FreeAndNil(Pen);
|
---|
420 | inherited;
|
---|
421 | end;
|
---|
422 |
|
---|
423 | { TCanvasLine }
|
---|
424 |
|
---|
425 | procedure TCanvasLine.Paint(Canvas: TCanvas);
|
---|
426 | begin
|
---|
427 | Canvas.Pen.Assign(Pen);
|
---|
428 | Canvas.Line(P1, P2);
|
---|
429 | end;
|
---|
430 |
|
---|
431 | procedure TCanvasLine.Zoom(Factor: Double);
|
---|
432 | begin
|
---|
433 | P1 := Point(Trunc(P1.X * Factor), Trunc(P1.Y * Factor));
|
---|
434 | P2 := Point(Trunc(P2.X * Factor), Trunc(P2.Y * Factor));
|
---|
435 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
436 | end;
|
---|
437 |
|
---|
438 | procedure TCanvasLine.Move(Delta: TPoint);
|
---|
439 | begin
|
---|
440 | P1 := AddPoint(P1, Delta);
|
---|
441 | P2 := AddPoint(P2, Delta);
|
---|
442 | end;
|
---|
443 |
|
---|
444 | constructor TCanvasLine.Create;
|
---|
445 | begin
|
---|
446 | Pen := TPen.Create;
|
---|
447 | end;
|
---|
448 |
|
---|
449 | destructor TCanvasLine.Destroy;
|
---|
450 | begin
|
---|
451 | Pen.Free;
|
---|
452 | inherited;
|
---|
453 | end;
|
---|
454 |
|
---|
455 | { TCanvasRectangle }
|
---|
456 |
|
---|
457 | procedure TCanvasRectangle.Paint(Canvas: TCanvas);
|
---|
458 | begin
|
---|
459 | Canvas.Pen.Assign(Pen);
|
---|
460 | Canvas.Brush.Assign(Brush);
|
---|
461 |
|
---|
462 | if Rounded <> Point(0, 0) then Canvas.RoundRect(BoundingRect, Rounded.X, Rounded.Y)
|
---|
463 | else Canvas.Rectangle(BoundingRect);
|
---|
464 | end;
|
---|
465 |
|
---|
466 | procedure TCanvasRectangle.Zoom(Factor: Double);
|
---|
467 | begin
|
---|
468 | BoundingRect := Rect(Trunc(BoundingRect.Left * Factor),
|
---|
469 | Trunc(BoundingRect.Top * Factor),
|
---|
470 | Trunc(BoundingRect.Right * Factor),
|
---|
471 | Trunc(BoundingRect.Bottom * Factor));
|
---|
472 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
473 | end;
|
---|
474 |
|
---|
475 | procedure TCanvasRectangle.Move(Delta: TPoint);
|
---|
476 | begin
|
---|
477 | BoundingRect := ShiftRect(BoundingRect, Delta);
|
---|
478 | end;
|
---|
479 |
|
---|
480 | constructor TCanvasRectangle.Create;
|
---|
481 | begin
|
---|
482 | Pen := TPen.Create;
|
---|
483 | Brush := TBrush.Create;
|
---|
484 | Rounded := Point(0, 0);
|
---|
485 | end;
|
---|
486 |
|
---|
487 | destructor TCanvasRectangle.Destroy;
|
---|
488 | begin
|
---|
489 | Pen.Free;
|
---|
490 | Brush.Free;
|
---|
491 | inherited;
|
---|
492 | end;
|
---|
493 |
|
---|
494 | { TCanvasText }
|
---|
495 |
|
---|
496 | procedure TCanvasText.Paint(Canvas: TCanvas);
|
---|
497 | begin
|
---|
498 | Canvas.Brush.Assign(Brush);
|
---|
499 | Canvas.Font.Assign(Font);
|
---|
500 | Canvas.TextOut(Position.X, Position.Y, Text);
|
---|
501 | end;
|
---|
502 |
|
---|
503 | procedure TCanvasText.Zoom(Factor: Double);
|
---|
504 | begin
|
---|
505 | Position := Point(Trunc(Position.X * Factor), Trunc(Position.Y * Factor));
|
---|
506 | Font.Size := Trunc(Font.Size * Factor);
|
---|
507 | end;
|
---|
508 |
|
---|
509 | procedure TCanvasText.Move(Delta: TPoint);
|
---|
510 | begin
|
---|
511 | Position := AddPoint(Position, Delta);
|
---|
512 | end;
|
---|
513 |
|
---|
514 | constructor TCanvasText.Create;
|
---|
515 | begin
|
---|
516 | Font := TFont.Create;
|
---|
517 | Brush := TBrush.Create;
|
---|
518 | end;
|
---|
519 |
|
---|
520 | destructor TCanvasText.Destroy;
|
---|
521 | begin
|
---|
522 | Brush.Free;
|
---|
523 | Font.Free;
|
---|
524 | inherited;
|
---|
525 | end;
|
---|
526 |
|
---|
527 | { TCanvasObject }
|
---|
528 |
|
---|
529 | procedure TCanvasObject.Paint(Canvas: TCanvas);
|
---|
530 | begin
|
---|
531 |
|
---|
532 | end;
|
---|
533 |
|
---|
534 | procedure TCanvasObject.Zoom(Factor: Double);
|
---|
535 | begin
|
---|
536 |
|
---|
537 | end;
|
---|
538 |
|
---|
539 | procedure TCanvasObject.Move(Delta: TPoint);
|
---|
540 | begin
|
---|
541 | end;
|
---|
542 |
|
---|
543 | { TMetaCanvas }
|
---|
544 |
|
---|
545 | procedure TMetaCanvas.SetHeight(AValue: Integer);
|
---|
546 | begin
|
---|
547 | FSize.Y := AValue;
|
---|
548 | end;
|
---|
549 |
|
---|
550 | function TMetaCanvas.GetHeight: Integer;
|
---|
551 | begin
|
---|
552 | Result := FSize.Y;
|
---|
553 | end;
|
---|
554 |
|
---|
555 | procedure TMetaCanvas.SetWidth(AValue: Integer);
|
---|
556 | begin
|
---|
557 | FSize.X := AValue;
|
---|
558 | end;
|
---|
559 |
|
---|
560 | function TMetaCanvas.GetWidth: Integer;
|
---|
561 | begin
|
---|
562 | Result := FSize.X;
|
---|
563 | end;
|
---|
564 |
|
---|
565 | procedure TMetaCanvas.DoLine(x1, y1, x2, y2: integer);
|
---|
566 | var
|
---|
567 | NewObj: TCanvasLine;
|
---|
568 | begin
|
---|
569 | NewObj := TCanvasLine.Create;
|
---|
570 | NewObj.Pen.Assign(Pen);
|
---|
571 | NewObj.P1 := Point(X1, Y1);
|
---|
572 | NewObj.P2 := Point(X2, Y2);
|
---|
573 | Objects.Add(NewObj);
|
---|
574 | end;
|
---|
575 |
|
---|
576 | procedure TMetaCanvas.DoTextOut(X, Y: Integer; Text: string);
|
---|
577 | var
|
---|
578 | NewObj: TCanvasText;
|
---|
579 | begin
|
---|
580 | NewObj := TCanvasText.Create;
|
---|
581 | NewObj.Font.Assign(Font);
|
---|
582 | NewObj.Brush.Assign(Brush);
|
---|
583 | NewObj.Position := Point(X, Y);
|
---|
584 | NewObj.Text := Text;
|
---|
585 | Objects.Add(NewObj);
|
---|
586 | end;
|
---|
587 |
|
---|
588 | procedure TMetaCanvas.TextOut(X, Y: Integer; const Text: String);
|
---|
589 | begin
|
---|
590 | DoTextOut(X, Y, Text);
|
---|
591 | end;
|
---|
592 |
|
---|
593 | procedure TMetaCanvas.DoRectangle(const Bounds: TRect);
|
---|
594 | var
|
---|
595 | NewObj: TCanvasRectangle;
|
---|
596 | begin
|
---|
597 | NewObj := TCanvasRectangle.Create;
|
---|
598 | NewObj.Pen.Assign(Pen);
|
---|
599 | NewObj.BoundingRect := Bounds;
|
---|
600 | Objects.Add(NewObj);
|
---|
601 | end;
|
---|
602 |
|
---|
603 | procedure TMetaCanvas.DoRectangleFill(const Bounds: TRect);
|
---|
604 | var
|
---|
605 | NewObj: TCanvasRectangle;
|
---|
606 | begin
|
---|
607 | NewObj := TCanvasRectangle.Create;
|
---|
608 | NewObj.Brush.Assign(Brush);
|
---|
609 | NewObj.Pen.Assign(Pen);
|
---|
610 | NewObj.BoundingRect := Bounds;
|
---|
611 | Objects.Add(NewObj);
|
---|
612 | end;
|
---|
613 |
|
---|
614 | procedure TMetaCanvas.Polygon(Points: PPoint; NumPts: Integer; Winding: Boolean
|
---|
615 | );
|
---|
616 | var
|
---|
617 | APoints: array of TPoint;
|
---|
618 | I: Integer;
|
---|
619 | begin
|
---|
620 | APoints := nil;
|
---|
621 | SetLength(APoints, NumPts);
|
---|
622 | for I := 0 to High(APoints) do
|
---|
623 | APoints[I] := Points[I];
|
---|
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);
|
---|
643 | end;
|
---|
644 |
|
---|
645 | procedure TMetaCanvas.DoPolygon(const Points: array of TPoint);
|
---|
646 | var
|
---|
647 | NewObj: TCanvasPolygon;
|
---|
648 | I: Integer;
|
---|
649 | begin
|
---|
650 | NewObj := TCanvasPolygon.Create;
|
---|
651 | NewObj.Brush.Assign(Brush);
|
---|
652 | NewObj.Pen.Assign(Pen);
|
---|
653 | SetLength(NewObj.Points, Length(Points));
|
---|
654 | for I := 0 to High(Points) do
|
---|
655 | NewObj.Points[I] := Points[I];
|
---|
656 | Objects.Add(NewObj);
|
---|
657 | end;
|
---|
658 |
|
---|
659 | procedure TMetaCanvas.CreateHandle;
|
---|
660 | begin
|
---|
661 | end;
|
---|
662 |
|
---|
663 | procedure TMetaCanvas.Ellipse(x1, y1, x2, y2: Integer);
|
---|
664 | begin
|
---|
665 | DoEllipse(Rect(X1, Y1, X2, Y2));
|
---|
666 | end;
|
---|
667 |
|
---|
668 | procedure TMetaCanvas.DoEllipse(const Bounds: TRect);
|
---|
669 | var
|
---|
670 | NewObj: TCanvasEllipse;
|
---|
671 | begin
|
---|
672 | NewObj := TCanvasEllipse.Create;
|
---|
673 | NewObj.Brush.Assign(Brush);
|
---|
674 | NewObj.Pen.Assign(Pen);
|
---|
675 | NewObj.BoundingRect := Bounds;
|
---|
676 | Objects.Add(NewObj);
|
---|
677 | end;
|
---|
678 |
|
---|
679 | procedure TMetaCanvas.StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic);
|
---|
680 | var
|
---|
681 | NewObj: TCanvasStretchDraw;
|
---|
682 | begin
|
---|
683 | NewObj := TCanvasStretchDraw.Create;
|
---|
684 | NewObj.SrcGraphic := SrcGraphic;
|
---|
685 | NewObj.DestRect := DestRect;
|
---|
686 | Objects.Add(NewObj);
|
---|
687 | end;
|
---|
688 |
|
---|
689 | function TMetaCanvas.TextExtent(const Text: string): TSize;
|
---|
690 | var
|
---|
691 | Canvas: TCanvas;
|
---|
692 | begin
|
---|
693 | Canvas := TCanvas.Create;
|
---|
694 | Canvas.Handle := CreateCompatibleDC(0);
|
---|
695 | Canvas.Font.Assign(Font);
|
---|
696 | Result := Canvas.TextExtent(Text);
|
---|
697 | DeleteDC(Canvas.Handle);
|
---|
698 | Canvas.Free;
|
---|
699 | end;
|
---|
700 |
|
---|
701 | procedure TMetaCanvas.DoMoveTo(X, Y: Integer);
|
---|
702 | begin
|
---|
703 | FPenPos := Point(X, Y);
|
---|
704 | end;
|
---|
705 |
|
---|
706 | procedure TMetaCanvas.DoLineTo(X, Y: Integer);
|
---|
707 | begin
|
---|
708 | DoLine(FPenPos.X, FPenPos.Y, X, Y);
|
---|
709 | DoMoveTo(X, Y);
|
---|
710 | end;
|
---|
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 |
|
---|
741 | procedure TMetaCanvas.FillRect(const ARect: TRect);
|
---|
742 | begin
|
---|
743 | DoRectangleFill(ARect);
|
---|
744 | end;
|
---|
745 |
|
---|
746 | procedure TMetaCanvas.FillRect(X1, Y1, X2, Y2: Integer);
|
---|
747 | begin
|
---|
748 | FillRect(Rect(X1, Y1, X2, Y2));
|
---|
749 | end;
|
---|
750 |
|
---|
751 | procedure TMetaCanvas.RoundRect(X1, Y1, X2, Y2: Integer; RX, RY: Integer);
|
---|
752 | begin
|
---|
753 | RoundRect(Rect(X1, Y1, X2, Y2), RX, RY);
|
---|
754 | end;
|
---|
755 |
|
---|
756 | procedure TMetaCanvas.RoundRect(const Rect: TRect; RX, RY: Integer);
|
---|
757 | var
|
---|
758 | NewObj: TCanvasRectangle;
|
---|
759 | begin
|
---|
760 | NewObj := TCanvasRectangle.Create;
|
---|
761 | NewObj.Brush.Assign(Brush);
|
---|
762 | NewObj.Pen.Assign(Pen);
|
---|
763 | NewObj.BoundingRect := Rect;
|
---|
764 | NewObj.Rounded := Point(RX, RY);
|
---|
765 | Objects.Add(NewObj);
|
---|
766 | end;
|
---|
767 |
|
---|
768 | procedure TMetaCanvas.Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2, StartX,
|
---|
769 | StartY, EndX, EndY: Integer);
|
---|
770 | var
|
---|
771 | NewObj: TCanvasPie;
|
---|
772 | begin
|
---|
773 | NewObj := TCanvasPie.Create;
|
---|
774 | NewObj.Brush.Assign(Brush);
|
---|
775 | NewObj.Pen.Assign(Pen);
|
---|
776 | NewObj.BoundingRect := Rect(EllipseX1, EllipseY1, EllipseX2, EllipseY2);
|
---|
777 | NewObj.StartPoint := Point(StartX, StartY);
|
---|
778 | NewObj.EndPoint := Point(EndX, EndY);
|
---|
779 | Objects.Add(NewObj);
|
---|
780 | end;
|
---|
781 |
|
---|
782 | procedure TMetaCanvas.Reset;
|
---|
783 | begin
|
---|
784 | Objects.Count := 0;
|
---|
785 | end;
|
---|
786 |
|
---|
787 | procedure TMetaCanvas.DrawTo(Canvas: TCanvas);
|
---|
788 | var
|
---|
789 | I: Integer;
|
---|
790 | begin
|
---|
791 | for I := 0 to Objects.Count - 1 do
|
---|
792 | Objects[I].Paint(Canvas);
|
---|
793 | end;
|
---|
794 |
|
---|
795 | procedure TMetaCanvas.Zoom(Factor: Double);
|
---|
796 | var
|
---|
797 | I: Integer;
|
---|
798 | begin
|
---|
799 | for I := 0 to Objects.Count - 1 do
|
---|
800 | Objects[I].Zoom(Factor);
|
---|
801 | end;
|
---|
802 |
|
---|
803 | procedure TMetaCanvas.Move(Delta: TPoint);
|
---|
804 | var
|
---|
805 | I: Integer;
|
---|
806 | begin
|
---|
807 | for I := 0 to Objects.Count - 1 do
|
---|
808 | Objects[I].Move(Delta);
|
---|
809 | end;
|
---|
810 |
|
---|
811 | constructor TMetaCanvas.Create;
|
---|
812 | begin
|
---|
813 | inherited;
|
---|
814 | FPenPos := Point(0, 0);
|
---|
815 | Objects := TCanvasObjects.Create;
|
---|
816 | end;
|
---|
817 |
|
---|
818 | destructor TMetaCanvas.Destroy;
|
---|
819 | begin
|
---|
820 | Objects.Free;
|
---|
821 | inherited;
|
---|
822 | end;
|
---|
823 |
|
---|
824 | end.
|
---|