-
Notifications
You must be signed in to change notification settings - Fork 14
/
AsciiImage.RenderContext.pas
165 lines (138 loc) · 3.69 KB
/
AsciiImage.RenderContext.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
unit AsciiImage.RenderContext;
interface
uses
Classes,
Types,
Graphics,
AsciiImage.RenderContext.Types,
AsciiImage.RenderContext.Intf;
type
TProperties = class(TInterfacedObject, IProperties)
private
FOnChanged: TPropertyChangedEvent;
function GetOnChanged: TPropertyChangedEvent;
procedure SetOnChanged(const Value: TPropertyChangedEvent);
protected
procedure Changed(); virtual;
public
property OnChanged: TPropertyChangedEvent read GetOnChanged write SetOnChanged;
end;
TBrushProperties = class(TProperties, IBrushProperties)
private
FColor: TColorValue;
FVisible: Boolean;
function GetColor: TColorValue;
procedure SetColor(const Value: TColorValue);
function GetVisible: Boolean;
procedure SetVisible(const Value: Boolean);
public
property Color: TColorValue read GetColor write SetColor;
property Visible: Boolean read GetVisible write SetVisible;
end;
TPenProperties = class(TBrushProperties, IPenProperties)
private
FSize: Integer;
function GetSize: Integer;
procedure SetSize(const Value: Integer);
public
property Size: Integer read GetSize write SetSize;
end;
TRenderContext = class(TInterfacedObject, IRenderContext)
private
FBrush: IBrushProperties;
FPen: IPenProperties;
function GetBrush: IBrushProperties;
function GetPen: IPenProperties;
protected
procedure BrushChanged; virtual; abstract;
procedure PenChanged; virtual; abstract;
public
procedure Clear(AColor: TColorValue); virtual; abstract;
procedure DrawPolygon(const APoints: array of TPointF); virtual; abstract;
procedure DrawLine(const AFrom, ATo: TPointF); virtual; abstract;
procedure DrawEllipsis(const ARect: TRectF); virtual; abstract;
procedure FillRectangle(const ARect: TRectF); virtual; abstract;
procedure BeginScene(const ARect: TRect); virtual;
procedure EndScene(); virtual;
property Brush: IBrushProperties read GetBrush;
property Pen: IPenProperties read GetPen;
end;
implementation
{ TProperties }
procedure TProperties.Changed;
begin
if Assigned(FOnChanged) then
FOnChanged();
end;
function TProperties.GetOnChanged: TPropertyChangedEvent;
begin
Result := FOnChanged;
end;
procedure TProperties.SetOnChanged(const Value: TPropertyChangedEvent);
begin
FOnChanged := Value;
end;
{ TBrushProperties }
function TBrushProperties.GetColor: TColorValue;
begin
Result := FColor;
end;
function TBrushProperties.GetVisible: Boolean;
begin
Result := FVisible;
end;
procedure TBrushProperties.SetColor(const Value: TColorValue);
begin
if FColor <> Value then
begin
FColor := Value;
Changed();
end;
end;
procedure TBrushProperties.SetVisible(const Value: Boolean);
begin
if FVisible <> Value then
begin
FVisible := Value;
Changed();
end;
end;
{ TPenProperties }
function TPenProperties.GetSize: Integer;
begin
Result := FSize;
end;
procedure TPenProperties.SetSize(const Value: Integer);
begin
if FSize <> Value then
begin
FSize := Value;
Changed();
end;
end;
{ TRenderContext }
procedure TRenderContext.BeginScene;
begin
end;
procedure TRenderContext.EndScene;
begin
end;
function TRenderContext.GetBrush: IBrushProperties;
begin
if not Assigned(FBrush) then
begin
FBrush := TBrushProperties.Create();
FBrush.OnChanged := BrushChanged;
end;
Result := FBrush;
end;
function TRenderContext.GetPen: IPenProperties;
begin
if not Assigned(FPen) then
begin
FPen := TPenProperties.Create();
FPen.OnChanged := PenChanged;
end;
Result := FPen;
end;
end.