1 | unit BGRANoGUIBitmap;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | SysUtils, Classes, BGRAGraphics, BGRABitmapTypes, BGRADefaultBitmap,
|
---|
9 | BGRAFreeType, EasyLazFreeType, LazFreeTypeFontCollection,
|
---|
10 | BGRACanvas;
|
---|
11 |
|
---|
12 | type
|
---|
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 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | { TBGRANoGUIBitmap }
|
---|
50 |
|
---|
51 | function TBGRANoGUIBitmap.GetPseudoCanvas: TBGRACanvas;
|
---|
52 | begin
|
---|
53 | if FPseudoCanvas = nil then
|
---|
54 | begin
|
---|
55 | FPseudoCanvas := TBGRACanvas.Create(self);
|
---|
56 | FPseudoCanvas.AntialiasingMode := amOff;
|
---|
57 | end;
|
---|
58 | result := FPseudoCanvas;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | procedure TBGRANoGUIBitmap.RebuildBitmap;
|
---|
62 | begin
|
---|
63 | //nothing
|
---|
64 | end;
|
---|
65 |
|
---|
66 | function TBGRANoGUIBitmap.CreateDefaultFontRenderer: TBGRACustomFontRenderer;
|
---|
67 | begin
|
---|
68 | result := TBGRAFreeTypeFontRenderer.Create;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | function TBGRANoGUIBitmap.LoadFromRawImage(ARawImage: TRawImage;
|
---|
72 | DefaultOpacity: byte; AlwaysReplaceAlpha: boolean;
|
---|
73 | RaiseErrorOnInvalidPixelFormat: boolean): boolean;
|
---|
74 | begin
|
---|
75 | NotAvailable;
|
---|
76 | result := false;
|
---|
77 | end;
|
---|
78 |
|
---|
79 | procedure TBGRANoGUIBitmap.Init;
|
---|
80 | begin
|
---|
81 | inherited Init;
|
---|
82 | FontAntialias:= true;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TBGRANoGUIBitmap.FreeBitmap;
|
---|
86 | begin
|
---|
87 | //nothing
|
---|
88 | end;
|
---|
89 |
|
---|
90 | procedure TBGRANoGUIBitmap.NotAvailable;
|
---|
91 | begin
|
---|
92 | raise exception.Create('Function not available without GUI');
|
---|
93 | end;
|
---|
94 |
|
---|
95 | destructor TBGRANoGUIBitmap.Destroy;
|
---|
96 | begin
|
---|
97 | FreeAndNil(FPseudoCanvas);
|
---|
98 | inherited Destroy;
|
---|
99 | end;
|
---|
100 |
|
---|
101 | class procedure TBGRANoGUIBitmap.AddFreeTypeFontFolder(ADirectory: string; AUTF8: boolean);
|
---|
102 | begin
|
---|
103 | if AUTF8 then ADirectory:= Utf8ToAnsi(ADirectory);
|
---|
104 | EasyLazFreeType.FontCollection.AddFolder(ADirectory);
|
---|
105 | end;
|
---|
106 |
|
---|
107 | class procedure TBGRANoGUIBitmap.AddFreeTypeFontFile(AFilename: string; AUTF8: boolean);
|
---|
108 | begin
|
---|
109 | if AUTF8 then AFilename:= Utf8ToAnsi(AFilename);
|
---|
110 | EasyLazFreeType.FontCollection.AddFile(AFilename);
|
---|
111 | end;
|
---|
112 |
|
---|
113 | procedure TBGRANoGUIBitmap.Draw(ACanvas: TCanvas; x, y: integer; Opaque: boolean);
|
---|
114 | begin
|
---|
115 | ACanvas.GUICanvas.Draw(x,y,self);
|
---|
116 | end;
|
---|
117 |
|
---|
118 | procedure TBGRANoGUIBitmap.Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean);
|
---|
119 | begin
|
---|
120 | ACanvas.GUICanvas.StretchDraw(Rect.Left,Rect.Top,Rect.Right-Rect.Left,Rect.Bottom-Rect.Top,self);
|
---|
121 | end;
|
---|
122 |
|
---|
123 | procedure TBGRANoGUIBitmap.GetImageFromCanvas(CanvasSource: TCanvas; x,
|
---|
124 | y: integer);
|
---|
125 | begin
|
---|
126 | NotAvailable;
|
---|
127 | end;
|
---|
128 |
|
---|
129 | procedure TBGRANoGUIBitmap.DataDrawTransparent(ACanvas: TCanvas; Rect: TRect;
|
---|
130 | AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
|
---|
131 | begin
|
---|
132 | NotAvailable;
|
---|
133 | end;
|
---|
134 |
|
---|
135 | procedure TBGRANoGUIBitmap.DataDrawOpaque(ACanvas: TCanvas; Rect: TRect;
|
---|
136 | AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
|
---|
137 | begin
|
---|
138 | NotAvailable;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | procedure TBGRANoGUIBitmap.TakeScreenshot(ARect: TRect);
|
---|
142 | begin
|
---|
143 | NotAvailable;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TBGRANoGUIBitmap.TakeScreenshotOfPrimaryMonitor;
|
---|
147 | begin
|
---|
148 | NotAvailable;
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TBGRANoGUIBitmap.LoadFromDevice(DC: HDC);
|
---|
152 | begin
|
---|
153 | NotAvailable;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | procedure TBGRANoGUIBitmap.LoadFromDevice(DC: HDC; ARect: TRect);
|
---|
157 | begin
|
---|
158 | NotAvailable;
|
---|
159 | end;
|
---|
160 |
|
---|
161 | end.
|
---|
162 |
|
---|