source: trunk/Packages/bgrabitmap/bgranoguibitmap.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 4.6 KB
Line 
1unit BGRANoGUIBitmap;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 SysUtils, Classes, BGRAGraphics, BGRABitmapTypes, BGRADefaultBitmap,
9 BGRAFreeType, EasyLazFreeType, LazFreeTypeFontCollection,
10 BGRACanvas;
11
12type
13
14 { TBGRANoGUIBitmap }
15
16 TBGRANoGUIBitmap = class(TBGRADefaultBitmap)
17 private
18 FPseudoCanvas: TBGRACanvas;
19 function GetPseudoCanvas: TBGRACanvas;
20 protected
21 procedure RebuildBitmap; override;
22 function CreateDefaultFontRenderer: TBGRACustomFontRenderer; override;
23 function LoadFromRawImage({%H-}ARawImage: TRawImage; {%H-}DefaultOpacity: byte;
24 {%H-}AlwaysReplaceAlpha: boolean=False; {%H-}RaiseErrorOnInvalidPixelFormat: boolean
25 =True): boolean; override;
26 procedure Init; override;
27 procedure FreeBitmap; override;
28 procedure NotAvailable;
29 public
30 destructor Destroy; override;
31 class procedure AddFreeTypeFontFolder(ADirectory: string; AUTF8: boolean = false);
32 class procedure AddFreeTypeFontFile(AFilename: string; AUTF8: boolean = false);
33 procedure Draw(ACanvas: TCanvas; x, y: integer; {%H-}Opaque: boolean=True); override;
34 procedure Draw(ACanvas: TCanvas; Rect: TRect; {%H-}Opaque: boolean=True); override;
35 procedure GetImageFromCanvas({%H-}CanvasSource: TCanvas; {%H-}x, {%H-}y: integer); override; //not available
36 procedure DataDrawTransparent({%H-}ACanvas: TCanvas; {%H-}Rect: TRect; {%H-}AData: Pointer;
37 {%H-}ALineOrder: TRawImageLineOrder; {%H-}AWidth, {%H-}AHeight: integer); override;
38 procedure DataDrawOpaque({%H-}ACanvas: TCanvas; {%H-}Rect: TRect; {%H-}AData: Pointer;
39 {%H-}ALineOrder: TRawImageLineOrder; {%H-}AWidth, {%H-}AHeight: integer); override;
40 procedure TakeScreenshot({%H-}ARect: TRect); override; //not available
41 procedure TakeScreenshotOfPrimaryMonitor; override; //not available
42 procedure LoadFromDevice({%H-}DC: HDC); override; //not available
43 procedure LoadFromDevice({%H-}DC: HDC; {%H-}ARect: TRect); override; //not available
44 property Canvas: TBGRACanvas read GetPseudoCanvas;
45 end;
46
47implementation
48
49{ TBGRANoGUIBitmap }
50
51function TBGRANoGUIBitmap.GetPseudoCanvas: TBGRACanvas;
52begin
53 if FPseudoCanvas = nil then
54 begin
55 FPseudoCanvas := TBGRACanvas.Create(self);
56 FPseudoCanvas.AntialiasingMode := amOff;
57 end;
58 result := FPseudoCanvas;
59end;
60
61procedure TBGRANoGUIBitmap.RebuildBitmap;
62begin
63 //nothing
64end;
65
66function TBGRANoGUIBitmap.CreateDefaultFontRenderer: TBGRACustomFontRenderer;
67begin
68 result := TBGRAFreeTypeFontRenderer.Create;
69end;
70
71function TBGRANoGUIBitmap.LoadFromRawImage(ARawImage: TRawImage;
72 DefaultOpacity: byte; AlwaysReplaceAlpha: boolean;
73 RaiseErrorOnInvalidPixelFormat: boolean): boolean;
74begin
75 NotAvailable;
76 result := false;
77end;
78
79procedure TBGRANoGUIBitmap.Init;
80begin
81 inherited Init;
82 FontAntialias:= true;
83end;
84
85procedure TBGRANoGUIBitmap.FreeBitmap;
86begin
87 //nothing
88end;
89
90procedure TBGRANoGUIBitmap.NotAvailable;
91begin
92 raise exception.Create('Function not available without GUI');
93end;
94
95destructor TBGRANoGUIBitmap.Destroy;
96begin
97 FreeAndNil(FPseudoCanvas);
98 inherited Destroy;
99end;
100
101class procedure TBGRANoGUIBitmap.AddFreeTypeFontFolder(ADirectory: string; AUTF8: boolean);
102begin
103 if AUTF8 then ADirectory:= Utf8ToAnsi(ADirectory);
104 EasyLazFreeType.FontCollection.AddFolder(ADirectory);
105end;
106
107class procedure TBGRANoGUIBitmap.AddFreeTypeFontFile(AFilename: string; AUTF8: boolean);
108begin
109 if AUTF8 then AFilename:= Utf8ToAnsi(AFilename);
110 EasyLazFreeType.FontCollection.AddFile(AFilename);
111end;
112
113procedure TBGRANoGUIBitmap.Draw(ACanvas: TCanvas; x, y: integer; Opaque: boolean);
114begin
115 ACanvas.GUICanvas.Draw(x,y,self);
116end;
117
118procedure TBGRANoGUIBitmap.Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean);
119begin
120 ACanvas.GUICanvas.StretchDraw(Rect.Left,Rect.Top,Rect.Right-Rect.Left,Rect.Bottom-Rect.Top,self);
121end;
122
123procedure TBGRANoGUIBitmap.GetImageFromCanvas(CanvasSource: TCanvas; x,
124 y: integer);
125begin
126 NotAvailable;
127end;
128
129procedure TBGRANoGUIBitmap.DataDrawTransparent(ACanvas: TCanvas; Rect: TRect;
130 AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
131begin
132 NotAvailable;
133end;
134
135procedure TBGRANoGUIBitmap.DataDrawOpaque(ACanvas: TCanvas; Rect: TRect;
136 AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
137begin
138 NotAvailable;
139end;
140
141procedure TBGRANoGUIBitmap.TakeScreenshot(ARect: TRect);
142begin
143 NotAvailable;
144end;
145
146procedure TBGRANoGUIBitmap.TakeScreenshotOfPrimaryMonitor;
147begin
148 NotAvailable;
149end;
150
151procedure TBGRANoGUIBitmap.LoadFromDevice(DC: HDC);
152begin
153 NotAvailable;
154end;
155
156procedure TBGRANoGUIBitmap.LoadFromDevice(DC: HDC; ARect: TRect);
157begin
158 NotAvailable;
159end;
160
161end.
162
Note: See TracBrowser for help on using the repository browser.