source: trunk/Packages/bgrabitmap/bgragraphics.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 24.1 KB
Line 
1unit BGRAGraphics;
2{=== Types imported from Graphics ===}
3{$mode objfpc}{$H+}
4
5interface
6
7{$I bgrabitmap.inc}
8
9{$IFDEF BGRABITMAP_USE_LCL}
10uses Graphics, GraphType, FPImage;
11
12type
13 PColor = Graphics.PColor;
14 TColor = Graphics.TColor;
15 TAntialiasingMode = Graphics.TAntialiasingMode;
16 TGradientDirection = Graphics.TGradientDirection;
17 TPenEndCap = Graphics.TPenEndCap;
18 TPenJoinStyle = Graphics.TPenJoinStyle;
19 TPenStyle = Graphics.TPenStyle;
20
21const
22 amDontCare = Graphics.amDontCare;
23 amOn = Graphics.amOn;
24 amOff = Graphics.amOff;
25
26 gdVertical = Graphics.gdVertical;
27 gdHorizontal = Graphics.gdHorizontal;
28
29 pecRound = Graphics.pecRound;
30 pecSquare = Graphics.pecSquare;
31 pecFlat = Graphics.pecFlat;
32
33 pjsRound = Graphics.pjsRound;
34 pjsBevel = Graphics.pjsBevel;
35 pjsMiter = Graphics.pjsMiter;
36
37 psSolid = Graphics.psSolid;
38 psDash = Graphics.psDash;
39 psDot = Graphics.psDot;
40 psDashDot = Graphics.psDashDot;
41 psDashDotDot = Graphics.psDashDotDot;
42 psClear = Graphics.psClear;
43 psInsideframe = Graphics.psInsideframe;
44 psPattern = Graphics.psPattern;
45
46 tmAuto = Graphics.tmAuto;
47 tmFixed = Graphics.tmFixed;
48
49type
50 TPen = Graphics.TPen;
51 TTextLayout = Graphics.TTextLayout;
52 TTextStyle = Graphics.TTextStyle;
53
54 TFillStyle = Graphics.TFillStyle;
55 TFillMode = Graphics.TFillMode;
56 TBrushStyle = Graphics.TBrushStyle;
57
58const
59 tlTop = Graphics.tlTop;
60 tlCenter = Graphics.tlCenter;
61 tlBottom = Graphics.tlBottom;
62
63 fsSurface = GraphType.fsSurface;
64 fsBorder = GraphType.fsBorder;
65
66 fmAlternate = Graphics.fmAlternate;
67 fmWinding = Graphics.fmWinding;
68
69 bsSolid = Graphics.bsSolid;
70 bsClear = Graphics.bsClear;
71 bsHorizontal = Graphics.bsHorizontal;
72 bsVertical = Graphics.bsVertical;
73 bsFDiagonal = Graphics.bsFDiagonal;
74 bsBDiagonal = Graphics.bsBDiagonal;
75 bsCross = Graphics.bsCross;
76 bsDiagCross = Graphics.bsDiagCross;
77
78type
79 TBrush = Graphics.TBrush;
80 TCanvas = Graphics.TCanvas;
81 TGraphic = Graphics.TGraphic;
82 TRawImage = GraphType.TRawImage;
83 TBitmap = Graphics.TBitmap;
84
85 TRasterImage = Graphics.TRasterImage;
86
87 TFontStyle = Graphics.TFontStyle;
88 TFontStyles = Graphics.TFontStyles;
89 TFontQuality = Graphics.TFontQuality;
90
91type
92 TFont = Graphics.TFont;
93
94const
95 fsBold = Graphics.fsBold;
96 fsItalic = Graphics.fsItalic;
97 fsStrikeOut = Graphics.fsStrikeOut;
98 fsUnderline = Graphics.fsUnderline;
99
100 fqDefault = Graphics.fqDefault;
101 fqDraft = Graphics.fqDraft;
102 fqProof = Graphics.fqProof;
103 fqNonAntialiased = Graphics.fqNonAntialiased;
104 fqAntialiased = Graphics.fqAntialiased;
105 fqCleartype = Graphics.fqCleartype;
106 fqCleartypeNatural = Graphics.fqCleartypeNatural;
107
108 clNone = Graphics.clNone;
109
110 clBlack = Graphics.clBlack;
111 clMaroon = Graphics.clMaroon;
112 clGreen = Graphics.clGreen;
113 clOlive = Graphics.clOlive;
114 clNavy = Graphics.clNavy;
115 clPurple = Graphics.clPurple;
116 clTeal = Graphics.clTeal;
117 clGray = Graphics.clGray;
118 clSilver = Graphics.clSilver;
119 clRed = Graphics.clRed;
120 clLime = Graphics.clLime;
121 clYellow = Graphics.clYellow;
122 clBlue = Graphics.clBlue;
123 clFuchsia = Graphics.clFuchsia;
124 clAqua = Graphics.clAqua;
125 clLtGray = Graphics.clLtGray; // clSilver alias
126 clDkGray = Graphics.clDkGray; // clGray alias
127 clWhite = Graphics.clWhite;
128
129function FPColorToTColor(const FPColor: TFPColor): TColor; inline;
130function TColorToFPColor(const c: TColor): TFPColor; inline;
131function ColorToRGB(c: TColor): TColor; inline;
132function RGBToColor(R, G, B: Byte): TColor; inline;
133procedure RedGreenBlue(rgb: TColor; out Red, Green, Blue: Byte); inline;// does not work on system color
134function clRgbBtnHighlight: TColor;
135function clRgbBtnShadow: TColor;
136
137implementation
138
139function FPColorToTColor(const FPColor: TFPColor): TColor;
140begin
141 result := Graphics.FPColorToTColor(FPColor);
142end;
143
144function TColorToFPColor(const c: TColor): TFPColor;
145begin
146 result := Graphics.TColorToFPColor(c);
147end;
148
149function ColorToRGB(c: TColor): TColor;
150begin
151 result := Graphics.ColorToRGB(c);
152end;
153
154function RGBToColor(R, G, B: Byte): TColor;
155begin
156 result := Graphics.RGBToColor(R, G, B);
157end;
158
159procedure RedGreenBlue(rgb: TColor; out Red, Green, Blue: Byte);
160begin
161 Graphics.RedGreenBlue(rgb, Red, Green, Blue);
162end;
163
164function clRgbBtnHighlight: TColor;
165begin
166 result := Graphics.ColorToRGB(clBtnHighlight);
167end;
168
169function clRgbBtnShadow: TColor;
170begin
171 result := Graphics.ColorToRGB(clBtnShadow);
172end;
173
174{$ELSE}
175
176uses
177 Classes, FPCanvas, FPImage
178 {$DEFINE INCLUDE_USES}
179 {$IFDEF BGRABITMAP_USE_FPGUI}
180 {$i bgrafpgui.inc}
181 {$ELSE}
182 {$i bgranogui.inc}
183 {$ENDIF}
184;
185
186{$DEFINE INCLUDE_INTERFACE}
187{$IFDEF BGRABITMAP_USE_FPGUI}
188 {$i bgrafpgui.inc}
189{$ELSE}
190 {$i bgranogui.inc}
191{$ENDIF}
192
193type
194 {* Pointer to a ''TColor'' value }
195 PColor = ^TColor;
196 {* Contains a color stored as RGB. The red/green/blue values
197 range from 0 to 255. The formula to get the color value is:
198 * ''color'' = ''red'' + (''green'' '''shl''' 8) + (''blue'' '''shl''' 16)
199 *except with fpGUI where it is:
200 * ''color'' = (''red'' '''shl''' 16) + (''green'' '''shl''' 8) + ''blue'' }{import
201 TColor = Int32;
202 }
203 {** Converts a ''TFPColor'' into a ''TColor'' value }
204 function FPColorToTColor(const FPColor: TFPColor): TColor;
205 {** Converts a ''TColor'' into a ''TFPColor'' value }
206 function TColorToFPColor(const c: TColor): TFPColor;
207
208type
209 {* Direction of change in a gradient }
210 TGradientDirection = (
211 {** Color changes vertically }
212 gdVertical,
213 {** Color changes horizontally }
214 gdHorizontal);
215
216 {* Antialiasing mode for a Canvas }
217 TAntialiasingMode = (
218 {** It does not matter if there is antialiasing or not }
219 amDontCare,
220 {** Antialiasing is required (BGRACanvas provide it) }
221 amOn,
222 {** Antialiasing is disabled }
223 amOff);
224
225 {* How to draw the end of line }
226 TPenEndCap = TFPPenEndCap;
227
228const
229 {** Draw a half-disk at the end of the line. The diameter of the disk is
230 equal to the pen width. }
231 pecRound = FPCanvas.pecRound;
232 {** Draw a half-square. The size of the square is equal to the pen width.
233 This is visually equivalent to extend the line of half the pen width }
234 pecSquare = FPCanvas.pecSquare;
235 {** The line ends exactly at the end point }
236 pecFlat = FPCanvas.pecFlat;
237
238type
239 {* How to join segments. This makes sense only for geometric pens (that
240 have a certain width) }
241 TPenJoinStyle = TFPPenJoinStyle;
242
243const
244 {** Segments are joined by filling the gap with an arc }
245 pjsRound = FPCanvas.pjsRound;
246 {** Segments are joind by filling the gap with an intermediary segment }
247 pjsBevel = FPCanvas.pjsBevel;
248 {** Segments are joined by extending them up to their intersection.
249 There is a miter limit so that if the intersection is too far,
250 an intermediary segment is used }
251 pjsMiter = FPCanvas.pjsMiter;
252
253type
254 {* Style to use for the pen. The unit for the pattern is the width of the
255 line }
256 TPenStyle = TFPPenStyle;
257
258const
259 {** Pen is continuous }
260 psSolid = FPCanvas.psSolid;
261 {** Pen is dashed. The dash have a length of 3 unit and the gaps of 1 unit }
262 psDash = FPCanvas.psDash;
263 {** Pen is dotted. The dots have a length of 1 unit and the gaps of 1 unit }
264 psDot = FPCanvas.psDot;
265 {** Pattern is a dash of length 3 followed by a dot of length 1, separated by a gap of length 1 }
266 psDashDot = FPCanvas.psDashDot;
267 {** Dash of length 3, and two dots of length 1 }
268 psDashDotDot = FPCanvas.psDashDotDot;
269 {** Pen is not drawn }
270 psClear = FPCanvas.psClear;
271 {** Not used. Provided for compatibility }
272 psInsideframe = FPCanvas.psInsideframe;
273 {** Custom pattern used }
274 psPattern = FPCanvas.psPattern;
275
276type
277 TTransparentMode = (
278 tmAuto,
279 tmFixed
280 );
281
282 { TPen }
283 {* A class containing a pen }
284 TPen = class(TFPCustomPen)
285 private
286 FEndCap: TPenEndCap;
287 FJoinStyle: TPenJoinStyle;
288 function GetColor: TColor;
289 procedure SetColor(AValue: TColor);
290 public
291 constructor Create; override;
292 {** Color of the pen }
293 property Color: TColor read GetColor write SetColor;
294 {** End cap of the pen: how to draw the ends of the lines }
295 property EndCap;
296 {** Join style: how to join the segments of a polyline }
297 property JoinStyle;
298 {** Pen style: solid, dash, dot... }{inherited
299 property Style : TPenStyle read write;
300 }{** Pen width in pixels }{inherited
301 property Width : Integer read write;
302 }
303 end;
304
305type
306 {* Vertical position of a text }
307 TTextLayout = (tlTop, tlCenter, tlBottom);
308 {* Styles to describe how a text is drawn in a rectangle }
309 TTextStyle = packed record
310 {** Horizontal alignment }
311 Alignment : TAlignment;
312
313 {** Vertical alignment }
314 Layout : TTextLayout;
315
316 {** If WordBreak is false then process #13, #10 as
317 standard chars and perform no Line breaking }
318 SingleLine: boolean;
319
320 {** Clip Text to passed Rectangle }
321 Clipping : boolean;
322
323 {** Replace #9 by apropriate amount of spaces (default is usually 8) }
324 ExpandTabs: boolean;
325
326 {** Process first single '&' per line as an underscore and draw '&&' as '&' }
327 ShowPrefix: boolean;
328
329 {** If line of text is too long too fit between left and right boundaries
330 try to break into multiple lines between words. See also ''EndEllipsis'' }
331 Wordbreak : boolean;
332
333 {** Fills background with current brush }
334 Opaque : boolean;
335
336 {** Use the system font instead of canvas font }
337 SystemFont: Boolean;
338
339 {** For RightToLeft text reading (Text Direction) }
340 RightToLeft: Boolean;
341
342 {** If line of text is too long to fit between left and right boundaries
343 truncates the text and adds "...". If Wordbreak is set as well,
344 Workbreak will dominate }
345 EndEllipsis: Boolean;
346 end;
347
348 {* Option for floodfill (used in BGRACanvas) }
349 TFillStyle =
350 (
351 {** Fill up to the color (it fills all except the specified color) }
352 fsSurface,
353 {** Fill the specified color (it fills only connected pixels of this color) }
354 fsBorder
355 );
356 {* How to handle polygons that intersect with themselves and
357 overlapping polygons }
358 TFillMode = (
359 {** Each time a boundary is found, it enters or exit the filling zone }
360 fmAlternate,
361 {** Adds or subtract 1 depending on the order of the points of the
362 polygons (clockwise or counter clockwise) and fill when the
363 result is non-zero. So, to draw a hole, you must specify the points
364 of the hole in the opposite order }
365 fmWinding);
366
367 {* Pattern when filling with a brush. It is used in BGRACanvas but can
368 also be created with TBGRABitmap.CreateBrushTexture function }
369 TBrushStyle = TFPBrushStyle;
370
371const
372 {** Fill with the current color }
373 bsSolid = FPCanvas.bsSolid;
374 {** Does not fill at all }
375 bsClear = FPCanvas.bsClear;
376 {** Draw horizontal lines }
377 bsHorizontal = FPCanvas.bsHorizontal;
378 {** Draw vertical lines }
379 bsVertical = FPCanvas.bsVertical;
380 {** Draw diagonal lines from top-left to bottom-right }
381 bsFDiagonal = FPCanvas.bsFDiagonal;
382 {** Draw diagonal lines from bottom-left to top-right }
383 bsBDiagonal = FPCanvas.bsBDiagonal;
384 {** Draw both horizontal and vertical lines }
385 bsCross = FPCanvas.bsCross;
386 {** Draw both diagonal lines }
387 bsDiagCross = FPCanvas.bsDiagCross;
388
389type
390
391 { TBrush }
392 {* A class describing a brush }
393 TBrush = class(TFPCustomBrush)
394 private
395 function GetColor: TColor;
396 procedure SetColor(AValue: TColor);
397 public
398 constructor Create; override;
399 {** Color of the brush }
400 property Color: TColor read GetColor write SetColor;
401 {** Style of the brush: solid, diagonal lines, horizontal lines... }{inherited
402 property Style : TBrushStyle read write;
403 }
404 end;
405
406type
407 TGraphic = class;
408
409 { TCanvas }
410 {* A surface on which to draw }
411 TCanvas = class
412 protected
413 FCanvas: TGUICanvas;
414 public
415 constructor Create(ACanvas: TGUICanvas);
416 {** Draw an image with top-left corner at (''x'',''y'') }
417 procedure Draw(x,y: integer; AImage: TGraphic);
418 {** Draw and stretch an image within the rectangle ''ARect'' }
419 procedure StretchDraw(ARect: TRect; AImage: TGraphic);
420 property GUICanvas: TGUICanvas read FCanvas;
421 end;
422
423 { TGraphic }
424 {* A class containing any element that can be drawn within rectangular bounds }
425 TGraphic = class(TPersistent)
426 protected
427 procedure Draw(ACanvas: TCanvas; const Rect: TRect); virtual; abstract;
428 function GetEmpty: Boolean; virtual; abstract;
429 function GetHeight: Integer; virtual; abstract;
430 function GetWidth: Integer; virtual; abstract;
431 function GetTransparent: Boolean; virtual; abstract;
432 procedure SetTransparent(Value: Boolean); virtual; abstract;
433 procedure SetHeight(Value: Integer); virtual; abstract;
434 procedure SetWidth(Value: Integer); virtual; abstract;
435 function GetMimeType: string; virtual;
436 public
437 constructor Create; virtual;
438 {** Load the content from a given file }
439 procedure LoadFromFile({%H-}const Filename: string); virtual;
440 {** Load the content from a given stream }
441 procedure LoadFromStream(Stream: TStream); virtual; abstract;
442 {** Saves the content to a file }
443 procedure SaveToFile({%H-}const Filename: string); virtual;
444 {** Saves the content into a given stream }
445 procedure SaveToStream(Stream: TStream); virtual; abstract;
446 {** Returns the list of possible file extensions }
447 class function GetFileExtensions: string; virtual;
448 {** Clears the content }
449 procedure Clear; virtual;
450 public
451 {** Returns if the content is completely empty }
452 property Empty: Boolean read GetEmpty;
453 {** Returns the height of the bounding rectangle }
454 property Height: Integer read GetHeight write SetHeight;
455 {** Returns the width of the bounding rectangle }
456 property Width: Integer read GetWidth write SetWidth;
457 {** Gets or sets if it is drawn with transparency }
458 property Transparent: Boolean read GetTransparent write SetTransparent;
459 end;
460
461 { TBitmap }
462 {* Contains a bitmap }
463 TBitmap = class(TGraphic)
464 private
465 FHeight: integer;
466 FWidth: integer;
467 FInDraw: boolean;
468 FTransparent: boolean;
469 FTransparentColor: TColor;
470 FTransparentMode: TTransparentMode;
471 function GetCanvas: TCanvas;
472 function GetRawImage: TRawImage;
473 procedure SetTransparentColor(AValue: TColor);
474 procedure SetTransparentMode(AValue: TTransparentMode);
475 protected
476 FRawImage: TRawImage;
477 procedure Draw(ACanvas: TCanvas; const Rect: TRect); override;
478 procedure Changed(Sender: TObject); virtual;
479 function GetHeight: Integer; override;
480 function GetWidth: Integer; override;
481 procedure SetHeight(Value: Integer); override;
482 procedure SetWidth(Value: Integer); override;
483 function GetEmpty: Boolean; override;
484 function GetTransparent: Boolean; override;
485 procedure SetTransparent({%H-}Value: Boolean); override;
486 function GetMimeType: string; override;
487 public
488 constructor Create; override;
489 destructor Destroy; override;
490 procedure LoadFromStream({%H-}Stream: TStream); override;
491 procedure SaveToStream({%H-}Stream: TStream); override;
492 {** Width of the bitmap in pixels }
493 property Width: integer read GetWidth write SetWidth;
494 {** Height of the bitmap in pixels }
495 property Height: integer read GetHeight write SetHeight;
496 property RawImage: TRawImage read GetRawImage;
497 property Canvas: TCanvas read GetCanvas;
498 property TransparentColor: TColor read FTransparentColor
499 write SetTransparentColor default clDefault;
500 property TransparentMode: TTransparentMode read FTransparentMode
501 write SetTransparentMode default tmAuto;
502 end;
503
504 TRasterImage = TBitmap;
505
506 {* Available font styles }
507 TFontStyle = (
508 {** Font is bold }
509 fsBold,
510 {** Font is italic }
511 fsItalic,
512 {** An horizontal line is drawn in the middle of the text }
513 fsStrikeOut,
514 {** Text is underlined }
515 fsUnderline);
516 {** A combination of font styles }
517 TFontStyles = set of TFontStyle;
518 {* Quality to use when font is rendered by the system }
519 TFontQuality = (fqDefault, fqDraft, fqProof, fqNonAntialiased, fqAntialiased, fqCleartype, fqCleartypeNatural);
520
521 { TFont }
522 {* Contains the description of a font }
523 TFont = class(TFPCustomFont)
524 private
525 FPixelsPerInch, FHeight: Integer;
526 FQuality: TFontQuality;
527 FStyle: TFontStyles;
528 function GetColor: TColor;
529 function GetHeight: Integer;
530 function GetSize: Integer;
531 function GetStyle: TFontStyles;
532 procedure SetColor(AValue: TColor);
533 procedure SetHeight(AValue: Integer);
534 procedure SetQuality(AValue: TFontQuality);
535 procedure SetStyle(AValue: TFontStyles);
536 protected
537 procedure SetSize(AValue: Integer); override;
538 public
539 constructor Create; override;
540 {** Pixels per inches }
541 property PixelsPerInch: Integer read FPixelsPerInch write FPixelsPerInch;
542 {** Color of the font }
543 property Color: TColor read GetColor write SetColor;
544 {** Height of the font in pixels. When the number is negative, it indicates a size in pixels }
545 property Height: Integer read GetHeight write SetHeight;
546 {** Size of the font in inches. When the number is negative, it indicates a height in inches }
547 property Size: Integer read GetSize write SetSize;
548 {** Quality of the font rendering }
549 property Quality: TFontQuality read FQuality write SetQuality;
550 {** Style to apply to the text }
551 property Style: TFontStyles read GetStyle write SetStyle;
552 end;
553
554{* Multiply and divide the number allowing big intermediate number and rounding the result }
555function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
556{* Round the number using math convention }
557function MathRound(AValue: ValReal): Int64; inline;
558
559implementation
560
561uses sysutils, BGRAUTF8;
562
563{$DEFINE INCLUDE_IMPLEMENTATION}
564{$IFDEF BGRABITMAP_USE_FPGUI}
565 {$i bgrafpgui.inc}
566{$ELSE}
567 {$i bgranogui.inc}
568{$ENDIF}
569
570function MathRound(AValue: ValReal): Int64; inline;
571begin
572 if AValue >= 0 then
573 Result := Trunc(AValue + 0.5)
574 else
575 Result := Trunc(AValue - 0.5);
576end;
577
578function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
579begin
580 if nDenominator = 0 then
581 Result := -1
582 else
583 Result := MathRound(int64(nNumber) * int64(nNumerator) / nDenominator);
584end;
585
586function FPColorToTColor(const FPColor: TFPColor): TColor;
587begin
588 {$IFDEF BGRABITMAP_USE_FPGUI}
589 Result:=((FPColor.Blue shr 8) and $ff)
590 or (FPColor.Green and $ff00)
591 or ((FPColor.Red shl 8) and $ff0000);
592 {$ELSE}
593 Result:=((FPColor.Red shr 8) and $ff)
594 or (FPColor.Green and $ff00)
595 or ((FPColor.Blue shl 8) and $ff0000);
596 {$ENDIF}
597end;
598
599function TColorToFPColor(const c: TColor): TFPColor;
600begin
601 {$IFDEF BGRABITMAP_USE_FPGUI}
602 Result.Blue:=(c and $ff);
603 Result.Blue:=Result.Blue+(Result.Blue shl 8);
604 Result.Green:=(c and $ff00);
605 Result.Green:=Result.Green+(Result.Green shr 8);
606 Result.Red:=(c and $ff0000) shr 8;
607 Result.Red:=Result.Red+(Result.Red shr 8);
608 {$ELSE}
609 Result.Red:=(c and $ff);
610 Result.Red:=Result.Red+(Result.Red shl 8);
611 Result.Green:=(c and $ff00);
612 Result.Green:=Result.Green+(Result.Green shr 8);
613 Result.Blue:=(c and $ff0000) shr 8;
614 Result.Blue:=Result.Blue+(Result.Blue shr 8);
615 {$ENDIF}
616 Result.Alpha:=FPImage.alphaOpaque;
617end;
618
619{ TGraphic }
620
621function TGraphic.GetMimeType: string;
622begin
623 result := '';
624end;
625
626constructor TGraphic.Create;
627begin
628 //nothing
629end;
630
631procedure TGraphic.LoadFromFile(const Filename: string);
632var
633 Stream: TStream;
634begin
635 Stream := TFileStreamUTF8.Create(Filename, fmOpenRead or fmShareDenyWrite);
636 try
637 LoadFromStream(Stream);
638 finally
639 Stream.Free;
640 end;
641end;
642
643procedure TGraphic.SaveToFile(const Filename: string);
644var
645 Stream: TStream;
646begin
647 Stream := TFileStreamUTF8.Create(Filename, fmCreate);
648 try
649 SaveToStream(Stream);
650 finally
651 Stream.Free;
652 end;
653end;
654
655class function TGraphic.GetFileExtensions: string;
656begin
657 result := '';
658end;
659
660procedure TGraphic.Clear;
661begin
662 //nothing
663end;
664
665{ TCanvas }
666
667constructor TCanvas.Create(ACanvas: TGUICanvas);
668begin
669 FCanvas := ACanvas;
670end;
671
672procedure TCanvas.Draw(x, y: integer; AImage: TGraphic);
673begin
674 if AImage is TBitmap then
675 FCanvas.DrawImage(x,y, TBitmap(AImage).RawImage)
676 else
677 AImage.Draw(self, rect(x,y,x+AImage.Width,y+AImage.Height));
678end;
679
680procedure TCanvas.StretchDraw(ARect: TRect; AImage: TGraphic);
681begin
682 if AImage is TBitmap then
683 FCanvas.StretchDraw(ARect.Left,ARect.Top,ARect.Right-ARect.Left,ARect.Bottom-ARect.Top, TBitmap(AImage).RawImage)
684 else
685 AImage.Draw(self, ARect);
686end;
687
688{ TPen }
689
690procedure TPen.SetColor(AValue: TColor);
691begin
692 FPColor := TColorToFPColor(AValue);
693end;
694
695function TPen.GetColor: TColor;
696begin
697 result := FPColorToTColor(FPColor);
698end;
699
700constructor TPen.Create;
701begin
702 inherited Create;
703 Mode := pmCopy;
704 Style := psSolid;
705 Width := 1;
706 FPColor := colBlack;
707 FEndCap:= pecRound;
708 FJoinStyle:= pjsRound;
709end;
710
711{ TBrush }
712
713function TBrush.GetColor: TColor;
714begin
715 result := FPColorToTColor(FPColor);
716end;
717
718procedure TBrush.SetColor(AValue: TColor);
719begin
720 FPColor := TColorToFPColor(AValue);
721end;
722
723constructor TBrush.Create;
724begin
725 inherited Create;
726 FPColor := colWhite;
727end;
728
729{ TFont }
730
731function TFont.GetColor: TColor;
732begin
733 result := FPColorToTColor(FPColor);
734end;
735
736function TFont.GetHeight: Integer;
737begin
738 result := FHeight;
739end;
740
741function TFont.GetSize: Integer;
742begin
743 Result := inherited Size;
744end;
745
746function TFont.GetStyle: TFontStyles;
747begin
748 result := FStyle;
749end;
750
751procedure TFont.SetColor(AValue: TColor);
752begin
753 FPColor := TColorToFPColor(AValue);
754end;
755
756procedure TFont.SetHeight(AValue: Integer);
757begin
758 if Height <> AValue then
759 begin
760 FHeight := AValue;
761 inherited SetSize(-MulDiv(AValue, 72, FPixelsPerInch));
762 end;
763end;
764
765procedure TFont.SetQuality(AValue: TFontQuality);
766begin
767 if FQuality=AValue then Exit;
768 FQuality:=AValue;
769end;
770
771procedure TFont.SetSize(AValue: Integer);
772begin
773 if Size <> AValue then
774 begin
775 inherited SetSize(AValue);
776 FHeight := -MulDiv(AValue, FPixelsPerInch, 72);
777 end;
778end;
779
780procedure TFont.SetStyle(AValue: TFontStyles);
781begin
782 if FStyle <> AValue then
783 begin
784 FStyle := AValue;
785 inherited SetFlags(5, fsBold in FStyle);
786 inherited SetFlags(6, fsItalic in FStyle);
787 inherited SetFlags(7, fsUnderline in FStyle);
788 inherited SetFlags(8, fsStrikeOut in FStyle);
789 end;
790end;
791
792constructor TFont.Create;
793begin
794 FPixelsPerInch := GetScreenDPIY;
795 FQuality := fqDefault;
796 FPColor := colBlack;
797end;
798
799{ TBitmap }
800
801procedure TBitmap.SetWidth(Value: Integer);
802begin
803 if FWidth=Value then Exit;
804 FWidth:=Value;
805end;
806
807function TBitmap.GetEmpty: Boolean;
808begin
809 result := (Width = 0) or (Height = 0);
810end;
811
812function TBitmap.GetTransparent: Boolean;
813begin
814 result := FTransparent;
815end;
816
817procedure TBitmap.SetTransparent(Value: Boolean);
818begin
819 if Value = FTransparent then exit;
820 FTransparent:= Value;
821end;
822
823procedure TBitmap.SetTransparentColor(AValue: TColor);
824begin
825 if FTransparentColor = AValue then exit;
826 FTransparentColor := AValue;
827
828 if AValue = clDefault
829 then FTransparentMode := tmAuto
830 else FTransparentMode := tmFixed;
831end;
832
833procedure TBitmap.SetTransparentMode(AValue: TTransparentMode);
834begin
835 if AValue = TransparentMode then exit;
836 FTransparentMode := AValue;
837
838 if AValue = tmAuto
839 then TransparentColor := clDefault
840end;
841
842function TBitmap.GetMimeType: string;
843begin
844 Result:= 'image/bmp';
845end;
846
847procedure TBitmap.Changed(Sender: TObject);
848begin
849 //nothing
850end;
851
852procedure TBitmap.LoadFromStream(Stream: TStream);
853begin
854 raise exception.Create('Not implemented');
855end;
856
857procedure TBitmap.SaveToStream(Stream: TStream);
858begin
859 raise exception.Create('Not implemented');
860end;
861
862procedure TBitmap.SetHeight(Value: Integer);
863begin
864 if FHeight=Value then Exit;
865 FHeight:=Value;
866end;
867
868function TBitmap.GetRawImage: TRawImage;
869begin
870 FRawImage.BGRASetSizeAndTransparency(FWidth, FHeight, FTransparent);
871 result := FRawImage;
872end;
873
874procedure TBitmap.Draw(ACanvas: TCanvas; const Rect: TRect);
875begin
876 if FInDraw then exit;
877 FInDraw := true;
878 ACanvas.StretchDraw(Rect, self);
879 FInDraw := false;
880end;
881
882function TBitmap.GetHeight: Integer;
883begin
884 result := FHeight;
885end;
886
887function TBitmap.GetWidth: Integer;
888begin
889 result := FWidth;
890end;
891
892function TBitmap.GetCanvas: TCanvas;
893begin
894 result := nil;
895 raise exception.Create('Canvas not available');
896end;
897
898constructor TBitmap.Create;
899begin
900 FRawImage := TRawImage.Create;
901 FTransparent:= false;
902end;
903
904destructor TBitmap.Destroy;
905begin
906 FRawImage.Free;
907 inherited Destroy;
908end;
909
910{$ENDIF}
911
912end.
913
Note: See TracBrowser for help on using the repository browser.