-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathAsciiImage.RenderContext.Factory.pas
55 lines (45 loc) · 1.31 KB
/
AsciiImage.RenderContext.Factory.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
unit AsciiImage.RenderContext.Factory;
interface
uses
Graphics,
AsciiImage.RenderContext.Intf;
type
TCreateRenderContextHook = reference to function(ACanvas: TCanvas; AWidth, AHeight: Single): IRenderContext;
TRenderContextFactory = class
private
class var FHook: TCreateRenderContextHook;
public
class function CreateDefaultRenderContext(ACanvas: TCanvas; AWidth, AHeight: Single): IRenderContext;
class procedure SetHookCreateDefaultRenderContext(const AHook: TCreateRenderContextHook);
end;
implementation
uses
AsciiImage.RenderContext.Types,
{$if Framework = 'VCL'}
AsciiImage.RenderContext.GDI;
{$Else}
AsciiImage.RenderContext.FM;
{$IfEnd}
{ TRenderContextFactory }
class function TRenderContextFactory.CreateDefaultRenderContext(
ACanvas: TCanvas; AWidth, AHeight: Single): IRenderContext;
begin
if Assigned(FHook) then
begin
Result := FHook(ACanvas, AWidth, AHeight);
end
else
begin
{$if Framework = 'VCL'}
Result := TGDIRenderContext.Create(ACanvas, AWidth, AHeight);
{$Else}
Result := TFMRenderContext.Create(ACanvas);
{$IfEnd}
end;
end;
class procedure TRenderContextFactory.SetHookCreateDefaultRenderContext(
const AHook: TCreateRenderContextHook);
begin
FHook := AHook;
end;
end.