-
Notifications
You must be signed in to change notification settings - Fork 14
/
AsciiImage.RenderContext.FM.pas
117 lines (101 loc) · 2.68 KB
/
AsciiImage.RenderContext.FM.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
unit AsciiImage.RenderContext.FM;
interface
uses
FMX.Graphics,
System.Math.Vectors,
AsciiImage.RenderContext.Types,
AsciiImage.RenderContext;
type
TFMRenderContext = class(TRenderContext)
private
FCanvas: TCanvas;
protected
procedure BrushChanged; override;
procedure PenChanged; override;
public
constructor Create(ACanvas: TCanvas);
procedure Clear(AColor: TColorValue); override;
procedure DrawEllipsis(const ARect: TRectF); override;
procedure DrawLine(const AFrom: TPointF; const ATo: TPointF); override;
procedure DrawPolygon(const APoints: array of TPointF); override;
procedure FillRectangle(const ARect: TRectF); override;
procedure BeginScene(const ARect: TRect); override;
procedure EndScene(); override;
end;
implementation
{ TFMRenderContext }
procedure TFMRenderContext.BeginScene;
var
LMoveMatrix: TMatrix;
begin
inherited;
FCanvas.BeginScene();
LMoveMatrix := TMatrix.CreateTranslation(ARect.Left, ARect.Top);
FCanvas.SetMatrix(FCanvas.Matrix * LMoveMatrix);
end;
procedure TFMRenderContext.BrushChanged;
begin
inherited;
FCanvas.Fill.Color := Brush.Color;
if Brush.Visible then
FCanvas.Fill.Kind := TBrushKind.Solid
else
FCanvas.Fill.Kind := TbrushKind.None;
end;
procedure TFMRenderContext.Clear(AColor: TColorValue);
begin
inherited;
FCanvas.Clear(AColor);
end;
constructor TFMRenderContext.Create(ACanvas: TCanvas);
begin
inherited Create();
FCanvas := ACanvas;
end;
procedure TFMRenderContext.DrawEllipsis(const ARect: TRectF);
begin
inherited;
FCanvas.FillEllipse(ARect, 1);
FCanvas.DrawEllipse(ARect, 1);
end;
procedure TFMRenderContext.DrawLine(const AFrom, ATo: TPointF);
begin
inherited;
FCanvas.DrawLine(AFrom, ATo, 1);
end;
procedure TFMRenderContext.DrawPolygon(const APoints: array of TPointF);
var
LPolygon: TPolygon;
i: Integer;
begin
inherited;
SetLength(LPolygon, Length(APoints) + 1);
for i := 0 to Length(APoints) - 1 do
begin
LPolygon[i] := APoints[i];
end;
LPolygon[High(LPolygon)] := LPolygon[0];
FCanvas.FillPolygon(LPolygon, 1);
FCanvas.DrawPolygon(LPolygon, 1);
end;
procedure TFMRenderContext.EndScene;
begin
inherited;
FCanvas.EndScene();
end;
procedure TFMRenderContext.FillRectangle(const ARect: TRectF);
begin
inherited;
FCanvas.FillRect(ARect, 1, 1, [], 1);
end;
procedure TFMRenderContext.PenChanged;
begin
inherited;
FCanvas.Stroke.Color := Pen.Color;
FCanvas.Stroke.Thickness := Pen.Size;
if Pen.Visible then
FCanvas.Stroke.Kind := TBrushKind.Solid
else
FCanvas.Stroke.Kind := TBrushKind.None;
end;
end.