1 | unit UMetaCanvas;
|
---|
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 | { TCanvasEllipse }
|
---|
76 |
|
---|
77 | TCanvasEllipse = class(TCanvasObject)
|
---|
78 | Pen: TPen;
|
---|
79 | Brush: TBrush;
|
---|
80 | BoundingRect: TRect;
|
---|
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 | { TCanvasPie }
|
---|
89 |
|
---|
90 | TCanvasPie = class(TCanvasObject)
|
---|
91 | Pen: TPen;
|
---|
92 | Brush: TBrush;
|
---|
93 | BoundingRect: TRect;
|
---|
94 | StartPoint: TPoint;
|
---|
95 | EndPoint: TPoint;
|
---|
96 | procedure Paint(Canvas: TCanvas); override;
|
---|
97 | procedure Zoom(Factor: Double); override;
|
---|
98 | procedure Move(Delta: TPoint); override;
|
---|
99 | constructor Create;
|
---|
100 | destructor Destroy; override;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | { TCanvasStretchDraw }
|
---|
104 |
|
---|
105 | TCanvasStretchDraw = class(TCanvasObject)
|
---|
106 | SrcGraphic: TGraphic;
|
---|
107 | DestRect: TRect;
|
---|
108 | procedure Paint(Canvas: TCanvas); override;
|
---|
109 | procedure Zoom(Factor: Double); override;
|
---|
110 | procedure Move(Delta: TPoint); override;
|
---|
111 | constructor Create;
|
---|
112 | destructor Destroy; override;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | { TMetaCanvas }
|
---|
116 |
|
---|
117 | TMetaCanvas = class(TCanvas)
|
---|
118 | private
|
---|
119 | FSize: TPoint;
|
---|
120 | FPenPos: TPoint;
|
---|
121 | protected
|
---|
122 | procedure SetHeight(AValue: Integer); override;
|
---|
123 | function GetHeight: Integer; override;
|
---|
124 | procedure SetWidth(AValue: Integer); override;
|
---|
125 | function GetWidth: Integer; override;
|
---|
126 | procedure DoLine (x1,y1,x2,y2:integer); override;
|
---|
127 | procedure DoTextOut(X, Y: Integer; Text: string); override;
|
---|
128 | procedure DoRectangle(const Bounds: TRect); override;
|
---|
129 | procedure DoRectangleFill(const Bounds: TRect); override;
|
---|
130 | procedure DoPolygon(const Points: array of TPoint); override;
|
---|
131 | procedure CreateHandle; override;
|
---|
132 | procedure DoEllipse(const Bounds: TRect); override;
|
---|
133 | procedure DoMoveTo(X, Y: Integer); override;
|
---|
134 | procedure DoLineTo(X, Y: Integer); override;
|
---|
135 | public
|
---|
136 | Objects: TCanvasObjects;
|
---|
137 | procedure FillRect(const ARect: TRect); overload; override;
|
---|
138 | procedure FillRect(X1,Y1,X2,Y2: Integer); overload;
|
---|
139 | procedure RoundRect(X1, Y1, X2, Y2: Integer; RX,RY: Integer); overload; override;
|
---|
140 | procedure RoundRect(const Rect: TRect; RX,RY: Integer); overload;
|
---|
141 | procedure TextOut(X,Y: Integer; const Text: String); override;
|
---|
142 | procedure Polygon(Points: PPoint; NumPts: Integer; Winding: Boolean = False); override;
|
---|
143 | procedure Ellipse(x1, y1, x2, y2: Integer); override;
|
---|
144 | procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); override;
|
---|
145 | function TextExtent(const Text: string): TSize; override;
|
---|
146 | procedure Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2,
|
---|
147 | StartX, StartY, EndX, EndY: Integer); override;
|
---|
148 | procedure Reset;
|
---|
149 | procedure DrawTo(Canvas: TCanvas);
|
---|
150 | procedure Zoom(Factor: Double);
|
---|
151 | procedure Move(Delta: TPoint);
|
---|
152 | constructor Create;
|
---|
153 | destructor Destroy; override;
|
---|
154 | property Size: TPoint read FSize write FSize;
|
---|
155 | end;
|
---|
156 |
|
---|
157 |
|
---|
158 | implementation
|
---|
159 |
|
---|
160 | uses
|
---|
161 | UGeometric, LCLIntf;
|
---|
162 |
|
---|
163 | { TCanvasPie }
|
---|
164 |
|
---|
165 | procedure TCanvasPie.Paint(Canvas: TCanvas);
|
---|
166 | begin
|
---|
167 | Canvas.Brush.Assign(Brush);
|
---|
168 | Canvas.Pen.Assign(Pen);
|
---|
169 | Canvas.Pie(BoundingRect.Left, BoundingRect.Top,
|
---|
170 | BoundingRect.Right, BoundingRect.Bottom, StartPoint.X, StartPoint.Y,
|
---|
171 | EndPoint.X, EndPoint.Y);
|
---|
172 | end;
|
---|
173 |
|
---|
174 | procedure TCanvasPie.Zoom(Factor: Double);
|
---|
175 | begin
|
---|
176 | BoundingRect := Rect(Trunc(BoundingRect.Left * Factor),
|
---|
177 | Trunc(BoundingRect.Top * Factor),
|
---|
178 | Trunc(BoundingRect.Right * Factor),
|
---|
179 | Trunc(BoundingRect.Bottom * Factor));
|
---|
180 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
181 | StartPoint := Point(Trunc(StartPoint.X * Factor), Trunc(StartPoint.Y * Factor));
|
---|
182 | EndPoint := Point(Trunc(EndPoint.X * Factor), Trunc(EndPoint.Y * Factor));
|
---|
183 | end;
|
---|
184 |
|
---|
185 | procedure TCanvasPie.Move(Delta: TPoint);
|
---|
186 | begin
|
---|
187 | BoundingRect := ShiftRect(BoundingRect, Delta);
|
---|
188 | StartPoint := AddPoint(StartPoint, Delta);
|
---|
189 | EndPoint := AddPoint(EndPoint, Delta);
|
---|
190 | end;
|
---|
191 |
|
---|
192 | constructor TCanvasPie.Create;
|
---|
193 | begin
|
---|
194 | Pen := TPen.Create;
|
---|
195 | Brush := TBrush.Create;
|
---|
196 | end;
|
---|
197 |
|
---|
198 | destructor TCanvasPie.Destroy;
|
---|
199 | begin
|
---|
200 | Pen.Free;
|
---|
201 | Brush.Free;
|
---|
202 | inherited;
|
---|
203 | end;
|
---|
204 |
|
---|
205 | { TCanvasStretchDraw }
|
---|
206 |
|
---|
207 | procedure TCanvasStretchDraw.Paint(Canvas: TCanvas);
|
---|
208 | begin
|
---|
209 | Canvas.StretchDraw(DestRect, SrcGraphic);
|
---|
210 | end;
|
---|
211 |
|
---|
212 | procedure TCanvasStretchDraw.Zoom(Factor: Double);
|
---|
213 | begin
|
---|
214 | DestRect := Rect(Trunc(DestRect.Left * Factor),
|
---|
215 | Trunc(DestRect.Top * Factor),
|
---|
216 | Trunc(DestRect.Right * Factor),
|
---|
217 | Trunc(DestRect.Bottom * Factor));
|
---|
218 | end;
|
---|
219 |
|
---|
220 | procedure TCanvasStretchDraw.Move(Delta: TPoint);
|
---|
221 | begin
|
---|
222 | DestRect := ShiftRect(DestRect, Delta);
|
---|
223 | end;
|
---|
224 |
|
---|
225 | constructor TCanvasStretchDraw.Create;
|
---|
226 | begin
|
---|
227 | SrcGraphic := nil;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | destructor TCanvasStretchDraw.Destroy;
|
---|
231 | begin
|
---|
232 | inherited;
|
---|
233 | end;
|
---|
234 |
|
---|
235 | { TCanvasEllipse }
|
---|
236 |
|
---|
237 | procedure TCanvasEllipse.Paint(Canvas: TCanvas);
|
---|
238 | begin
|
---|
239 | Canvas.Pen.Assign(Pen);
|
---|
240 | Canvas.Brush.Assign(Brush);
|
---|
241 | Canvas.Ellipse(BoundingRect);
|
---|
242 | end;
|
---|
243 |
|
---|
244 | procedure TCanvasEllipse.Zoom(Factor: Double);
|
---|
245 | begin
|
---|
246 | BoundingRect := Rect(Trunc(BoundingRect.Left * Factor),
|
---|
247 | Trunc(BoundingRect.Top * Factor),
|
---|
248 | Trunc(BoundingRect.Right * Factor),
|
---|
249 | Trunc(BoundingRect.Bottom * Factor));
|
---|
250 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
251 | end;
|
---|
252 |
|
---|
253 | procedure TCanvasEllipse.Move(Delta: TPoint);
|
---|
254 | begin
|
---|
255 | BoundingRect := ShiftRect(BoundingRect, Delta);
|
---|
256 | end;
|
---|
257 |
|
---|
258 | constructor TCanvasEllipse.Create;
|
---|
259 | begin
|
---|
260 | Pen := TPen.Create;
|
---|
261 | Brush := TBrush.Create;
|
---|
262 | end;
|
---|
263 |
|
---|
264 | destructor TCanvasEllipse.Destroy;
|
---|
265 | begin
|
---|
266 | Pen.Free;
|
---|
267 | Brush.Free;
|
---|
268 | inherited;
|
---|
269 | end;
|
---|
270 |
|
---|
271 | { TCanvasPolygon }
|
---|
272 |
|
---|
273 | procedure TCanvasPolygon.Paint(Canvas: TCanvas);
|
---|
274 | begin
|
---|
275 | Canvas.Pen.Assign(Pen);
|
---|
276 | Canvas.Brush.Assign(Brush);
|
---|
277 | Canvas.Polygon(Points);
|
---|
278 | end;
|
---|
279 |
|
---|
280 | procedure TCanvasPolygon.Zoom(Factor: Double);
|
---|
281 | var
|
---|
282 | I: Integer;
|
---|
283 | begin
|
---|
284 | for I := 0 to High(Points) do
|
---|
285 | Points[I] := Point(Trunc(Points[I].X * Factor),
|
---|
286 | Trunc(Points[I].Y * Factor));
|
---|
287 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
288 | end;
|
---|
289 |
|
---|
290 | procedure TCanvasPolygon.Move(Delta: TPoint);
|
---|
291 | var
|
---|
292 | I: Integer;
|
---|
293 | begin
|
---|
294 | for I := 0 to High(Points) do
|
---|
295 | Points[I] := AddPoint(Points[I], Delta);
|
---|
296 | end;
|
---|
297 |
|
---|
298 | constructor TCanvasPolygon.Create;
|
---|
299 | begin
|
---|
300 | Pen := TPen.Create;
|
---|
301 | Brush := TBrush.Create;
|
---|
302 | end;
|
---|
303 |
|
---|
304 | destructor TCanvasPolygon.Destroy;
|
---|
305 | begin
|
---|
306 | Brush.Free;
|
---|
307 | Pen.Free;
|
---|
308 | inherited;
|
---|
309 | end;
|
---|
310 |
|
---|
311 | { TCanvasLine }
|
---|
312 |
|
---|
313 | procedure TCanvasLine.Paint(Canvas: TCanvas);
|
---|
314 | begin
|
---|
315 | Canvas.Pen.Assign(Pen);
|
---|
316 | Canvas.Line(P1, P2);
|
---|
317 | end;
|
---|
318 |
|
---|
319 | procedure TCanvasLine.Zoom(Factor: Double);
|
---|
320 | begin
|
---|
321 | P1 := Point(Trunc(P1.X * Factor), Trunc(P1.Y * Factor));
|
---|
322 | P2 := Point(Trunc(P2.X * Factor), Trunc(P2.Y * Factor));
|
---|
323 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
324 | end;
|
---|
325 |
|
---|
326 | procedure TCanvasLine.Move(Delta: TPoint);
|
---|
327 | begin
|
---|
328 | P1 := AddPoint(P1, Delta);
|
---|
329 | P2 := AddPoint(P2, Delta);
|
---|
330 | end;
|
---|
331 |
|
---|
332 | constructor TCanvasLine.Create;
|
---|
333 | begin
|
---|
334 | Pen := TPen.Create;
|
---|
335 | end;
|
---|
336 |
|
---|
337 | destructor TCanvasLine.Destroy;
|
---|
338 | begin
|
---|
339 | Pen.Free;
|
---|
340 | inherited;
|
---|
341 | end;
|
---|
342 |
|
---|
343 | { TCanvasRectangle }
|
---|
344 |
|
---|
345 | procedure TCanvasRectangle.Paint(Canvas: TCanvas);
|
---|
346 | begin
|
---|
347 | Canvas.Pen.Assign(Pen);
|
---|
348 | Canvas.Brush.Assign(Brush);
|
---|
349 |
|
---|
350 | if Rounded <> Point(0, 0) then Canvas.RoundRect(BoundingRect, Rounded.X, Rounded.Y)
|
---|
351 | else Canvas.Rectangle(BoundingRect);
|
---|
352 | end;
|
---|
353 |
|
---|
354 | procedure TCanvasRectangle.Zoom(Factor: Double);
|
---|
355 | begin
|
---|
356 | BoundingRect := Rect(Trunc(BoundingRect.Left * Factor),
|
---|
357 | Trunc(BoundingRect.Top * Factor),
|
---|
358 | Trunc(BoundingRect.Right * Factor),
|
---|
359 | Trunc(BoundingRect.Bottom * Factor));
|
---|
360 | Pen.Width := Trunc(Pen.Width * Factor);
|
---|
361 | end;
|
---|
362 |
|
---|
363 | procedure TCanvasRectangle.Move(Delta: TPoint);
|
---|
364 | begin
|
---|
365 | BoundingRect := ShiftRect(BoundingRect, Delta);
|
---|
366 | end;
|
---|
367 |
|
---|
368 | constructor TCanvasRectangle.Create;
|
---|
369 | begin
|
---|
370 | Pen := TPen.Create;
|
---|
371 | Brush := TBrush.Create;
|
---|
372 | Rounded := Point(0, 0);
|
---|
373 | end;
|
---|
374 |
|
---|
375 | destructor TCanvasRectangle.Destroy;
|
---|
376 | begin
|
---|
377 | Pen.Free;
|
---|
378 | Brush.Free;
|
---|
379 | inherited;
|
---|
380 | end;
|
---|
381 |
|
---|
382 | { TCanvasText }
|
---|
383 |
|
---|
384 | procedure TCanvasText.Paint(Canvas: TCanvas);
|
---|
385 | begin
|
---|
386 | Canvas.Brush.Assign(Brush);
|
---|
387 | Canvas.Font.Assign(Font);
|
---|
388 | Canvas.TextOut(Position.X, Position.Y, Text);
|
---|
389 | end;
|
---|
390 |
|
---|
391 | procedure TCanvasText.Zoom(Factor: Double);
|
---|
392 | begin
|
---|
393 | Position := Point(Trunc(Position.X * Factor), Trunc(Position.Y * Factor));
|
---|
394 | Font.Size := Trunc(Font.Size * Factor);
|
---|
395 | end;
|
---|
396 |
|
---|
397 | procedure TCanvasText.Move(Delta: TPoint);
|
---|
398 | begin
|
---|
399 | Position := AddPoint(Position, Delta);
|
---|
400 | end;
|
---|
401 |
|
---|
402 | constructor TCanvasText.Create;
|
---|
403 | begin
|
---|
404 | Font := TFont.Create;
|
---|
405 | Brush := TBrush.Create;
|
---|
406 | end;
|
---|
407 |
|
---|
408 | destructor TCanvasText.Destroy;
|
---|
409 | begin
|
---|
410 | Brush.Free;
|
---|
411 | Font.Free;
|
---|
412 | inherited;
|
---|
413 | end;
|
---|
414 |
|
---|
415 | { TCanvasObject }
|
---|
416 |
|
---|
417 | procedure TCanvasObject.Paint(Canvas: TCanvas);
|
---|
418 | begin
|
---|
419 |
|
---|
420 | end;
|
---|
421 |
|
---|
422 | procedure TCanvasObject.Zoom(Factor: Double);
|
---|
423 | begin
|
---|
424 |
|
---|
425 | end;
|
---|
426 |
|
---|
427 | procedure TCanvasObject.Move(Delta: TPoint);
|
---|
428 | begin
|
---|
429 | end;
|
---|
430 |
|
---|
431 | { TMetaCanvas }
|
---|
432 |
|
---|
433 | procedure TMetaCanvas.SetHeight(AValue: Integer);
|
---|
434 | begin
|
---|
435 | FSize.Y := AValue;
|
---|
436 | end;
|
---|
437 |
|
---|
438 | function TMetaCanvas.GetHeight: Integer;
|
---|
439 | begin
|
---|
440 | Result := FSize.Y;
|
---|
441 | end;
|
---|
442 |
|
---|
443 | procedure TMetaCanvas.SetWidth(AValue: Integer);
|
---|
444 | begin
|
---|
445 | FSize.X := AValue;
|
---|
446 | end;
|
---|
447 |
|
---|
448 | function TMetaCanvas.GetWidth: Integer;
|
---|
449 | begin
|
---|
450 | Result := FSize.X;
|
---|
451 | end;
|
---|
452 |
|
---|
453 | procedure TMetaCanvas.DoLine(x1, y1, x2, y2: integer);
|
---|
454 | var
|
---|
455 | NewObj: TCanvasLine;
|
---|
456 | begin
|
---|
457 | NewObj := TCanvasLine.Create;
|
---|
458 | NewObj.Pen.Assign(Pen);
|
---|
459 | NewObj.P1 := Point(X1, Y1);
|
---|
460 | NewObj.P2 := Point(X2, Y2);
|
---|
461 | Objects.Add(NewObj);
|
---|
462 | end;
|
---|
463 |
|
---|
464 | procedure TMetaCanvas.DoTextOut(X, Y: Integer; Text: string);
|
---|
465 | var
|
---|
466 | NewObj: TCanvasText;
|
---|
467 | begin
|
---|
468 | NewObj := TCanvasText.Create;
|
---|
469 | NewObj.Font.Assign(Font);
|
---|
470 | NewObj.Brush.Assign(Brush);
|
---|
471 | NewObj.Position := Point(X, Y);
|
---|
472 | NewObj.Text := Text;
|
---|
473 | Objects.Add(NewObj);
|
---|
474 | end;
|
---|
475 |
|
---|
476 | procedure TMetaCanvas.TextOut(X, Y: Integer; const Text: String);
|
---|
477 | begin
|
---|
478 | DoTextOut(X, Y, Text);
|
---|
479 | end;
|
---|
480 |
|
---|
481 | procedure TMetaCanvas.DoRectangle(const Bounds: TRect);
|
---|
482 | var
|
---|
483 | NewObj: TCanvasRectangle;
|
---|
484 | begin
|
---|
485 | NewObj := TCanvasRectangle.Create;
|
---|
486 | NewObj.Pen.Assign(Pen);
|
---|
487 | NewObj.BoundingRect := Bounds;
|
---|
488 | Objects.Add(NewObj);
|
---|
489 | end;
|
---|
490 |
|
---|
491 | procedure TMetaCanvas.DoRectangleFill(const Bounds: TRect);
|
---|
492 | var
|
---|
493 | NewObj: TCanvasRectangle;
|
---|
494 | begin
|
---|
495 | NewObj := TCanvasRectangle.Create;
|
---|
496 | NewObj.Brush.Assign(Brush);
|
---|
497 | NewObj.Pen.Assign(Pen);
|
---|
498 | NewObj.BoundingRect := Bounds;
|
---|
499 | Objects.Add(NewObj);
|
---|
500 | end;
|
---|
501 |
|
---|
502 | procedure TMetaCanvas.Polygon(Points: PPoint; NumPts: Integer; Winding: Boolean
|
---|
503 | );
|
---|
504 | var
|
---|
505 | APoints: array of TPoint;
|
---|
506 | I: Integer;
|
---|
507 | begin
|
---|
508 | APoints := nil;
|
---|
509 | SetLength(APoints, NumPts);
|
---|
510 | for I := 0 to High(APoints) do
|
---|
511 | APoints[I] := Points[I];
|
---|
512 | DoPolygon(APoints);
|
---|
513 | end;
|
---|
514 |
|
---|
515 | procedure TMetaCanvas.DoPolygon(const Points: array of TPoint);
|
---|
516 | var
|
---|
517 | NewObj: TCanvasPolygon;
|
---|
518 | I: Integer;
|
---|
519 | begin
|
---|
520 | NewObj := TCanvasPolygon.Create;
|
---|
521 | NewObj.Brush.Assign(Brush);
|
---|
522 | NewObj.Pen.Assign(Pen);
|
---|
523 | SetLength(NewObj.Points, Length(Points));
|
---|
524 | for I := 0 to High(Points) do
|
---|
525 | NewObj.Points[I] := Points[I];
|
---|
526 | Objects.Add(NewObj);
|
---|
527 | end;
|
---|
528 |
|
---|
529 | procedure TMetaCanvas.CreateHandle;
|
---|
530 | begin
|
---|
531 | end;
|
---|
532 |
|
---|
533 | procedure TMetaCanvas.Ellipse(x1, y1, x2, y2: Integer);
|
---|
534 | begin
|
---|
535 | DoEllipse(Rect(X1, Y1, X2, Y2));
|
---|
536 | end;
|
---|
537 |
|
---|
538 | procedure TMetaCanvas.DoEllipse(const Bounds: TRect);
|
---|
539 | var
|
---|
540 | NewObj: TCanvasEllipse;
|
---|
541 | begin
|
---|
542 | NewObj := TCanvasEllipse.Create;
|
---|
543 | NewObj.Brush.Assign(Brush);
|
---|
544 | NewObj.Pen.Assign(Pen);
|
---|
545 | NewObj.BoundingRect := Bounds;
|
---|
546 | Objects.Add(NewObj);
|
---|
547 | end;
|
---|
548 |
|
---|
549 | procedure TMetaCanvas.StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic);
|
---|
550 | var
|
---|
551 | NewObj: TCanvasStretchDraw;
|
---|
552 | begin
|
---|
553 | NewObj := TCanvasStretchDraw.Create;
|
---|
554 | NewObj.SrcGraphic := SrcGraphic;
|
---|
555 | NewObj.DestRect := DestRect;
|
---|
556 | Objects.Add(NewObj);
|
---|
557 | end;
|
---|
558 |
|
---|
559 | function TMetaCanvas.TextExtent(const Text: string): TSize;
|
---|
560 | var
|
---|
561 | Canvas: TCanvas;
|
---|
562 | begin
|
---|
563 | Canvas := TCanvas.Create;
|
---|
564 | Canvas.Handle := CreateCompatibleDC(0);
|
---|
565 | Canvas.Font.Assign(Font);
|
---|
566 | Result := Canvas.TextExtent(Text);
|
---|
567 | DeleteDC(Canvas.Handle);
|
---|
568 | Canvas.Free;
|
---|
569 | end;
|
---|
570 |
|
---|
571 | procedure TMetaCanvas.DoMoveTo(X, Y: Integer);
|
---|
572 | begin
|
---|
573 | FPenPos := Point(X, Y);
|
---|
574 | end;
|
---|
575 |
|
---|
576 | procedure TMetaCanvas.DoLineTo(X, Y: Integer);
|
---|
577 | begin
|
---|
578 | DoLine(FPenPos.X, FPenPos.Y, X, Y);
|
---|
579 | DoMoveTo(X, Y);
|
---|
580 | end;
|
---|
581 |
|
---|
582 | procedure TMetaCanvas.FillRect(const ARect: TRect);
|
---|
583 | begin
|
---|
584 | DoRectangleFill(ARect);
|
---|
585 | end;
|
---|
586 |
|
---|
587 | procedure TMetaCanvas.FillRect(X1, Y1, X2, Y2: Integer);
|
---|
588 | begin
|
---|
589 | FillRect(Rect(X1, Y1, X2, Y2));
|
---|
590 | end;
|
---|
591 |
|
---|
592 | procedure TMetaCanvas.RoundRect(X1, Y1, X2, Y2: Integer; RX, RY: Integer);
|
---|
593 | begin
|
---|
594 | RoundRect(Rect(X1, Y1, X2, Y2), RX, RY);
|
---|
595 | end;
|
---|
596 |
|
---|
597 | procedure TMetaCanvas.RoundRect(const Rect: TRect; RX, RY: Integer);
|
---|
598 | var
|
---|
599 | NewObj: TCanvasRectangle;
|
---|
600 | begin
|
---|
601 | NewObj := TCanvasRectangle.Create;
|
---|
602 | NewObj.Brush.Assign(Brush);
|
---|
603 | NewObj.Pen.Assign(Pen);
|
---|
604 | NewObj.BoundingRect := Rect;
|
---|
605 | NewObj.Rounded := Point(RX, RY);
|
---|
606 | Objects.Add(NewObj);
|
---|
607 | end;
|
---|
608 |
|
---|
609 | procedure TMetaCanvas.Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2, StartX,
|
---|
610 | StartY, EndX, EndY: Integer);
|
---|
611 | var
|
---|
612 | NewObj: TCanvasPie;
|
---|
613 | begin
|
---|
614 | NewObj := TCanvasPie.Create;
|
---|
615 | NewObj.Brush.Assign(Brush);
|
---|
616 | NewObj.Pen.Assign(Pen);
|
---|
617 | NewObj.BoundingRect := Rect(EllipseX1, EllipseY1, EllipseX2, EllipseY2);
|
---|
618 | NewObj.StartPoint := Point(StartX, StartY);
|
---|
619 | NewObj.EndPoint := Point(EndX, EndY);
|
---|
620 | Objects.Add(NewObj);
|
---|
621 | end;
|
---|
622 |
|
---|
623 | procedure TMetaCanvas.Reset;
|
---|
624 | begin
|
---|
625 | Objects.Count := 0;
|
---|
626 | end;
|
---|
627 |
|
---|
628 | procedure TMetaCanvas.DrawTo(Canvas: TCanvas);
|
---|
629 | var
|
---|
630 | I: Integer;
|
---|
631 | begin
|
---|
632 | for I := 0 to Objects.Count - 1 do
|
---|
633 | Objects[I].Paint(Canvas);
|
---|
634 | end;
|
---|
635 |
|
---|
636 | procedure TMetaCanvas.Zoom(Factor: Double);
|
---|
637 | var
|
---|
638 | I: Integer;
|
---|
639 | begin
|
---|
640 | for I := 0 to Objects.Count - 1 do
|
---|
641 | Objects[I].Zoom(Factor);
|
---|
642 | end;
|
---|
643 |
|
---|
644 | procedure TMetaCanvas.Move(Delta: TPoint);
|
---|
645 | var
|
---|
646 | I: Integer;
|
---|
647 | begin
|
---|
648 | for I := 0 to Objects.Count - 1 do
|
---|
649 | Objects[I].Move(Delta);
|
---|
650 | end;
|
---|
651 |
|
---|
652 | constructor TMetaCanvas.Create;
|
---|
653 | begin
|
---|
654 | inherited;
|
---|
655 | FPenPos := Point(0, 0);
|
---|
656 | Objects := TCanvasObjects.Create;
|
---|
657 | end;
|
---|
658 |
|
---|
659 | destructor TMetaCanvas.Destroy;
|
---|
660 | begin
|
---|
661 | Objects.Free;
|
---|
662 | inherited;
|
---|
663 | end;
|
---|
664 |
|
---|
665 | end.
|
---|
666 |
|
---|