source: branches/Xvcl/Xvcl.Graphics.pas

Last change on this file was 24, checked in by chronos, 12 years ago
  • Fixed: Make only one form focused at once.
  • Modified: Enhanced TList generic class to support more methods.
File size: 4.3 KB
Line 
1unit Xvcl.Graphics;
2
3interface
4
5uses
6 Xvcl.Classes;
7
8type
9
10 TColor = (clNone, clBlack, clWhite, clGray, clSilver, clBlue, clGreen, clRed,
11 clLightBlue, clLightRed, clLightGreen, clBrown, clYellow, clMagenta, clCyan);
12
13 TPen = class
14 Position: TPoint;
15 Color: TColor;
16 end;
17
18 TBrush = class
19 Color: TColor;
20 end;
21
22 TFont = class
23
24 end;
25
26 TVideoDevice = class
27 Size: TPoint;
28 procedure FillRect(Rect: TRectangle; Color: TColor); virtual;
29 procedure Line(Pos1, Pos2: TPoint; Color: TColor); virtual;
30 procedure SetPixel(Position: TPoint; Color: TColor); virtual;
31 function GetPixel(Position: TPoint): TColor; virtual;
32 procedure TextOut(Position: TPoint; Text: string); virtual;
33 function GetTextSize(Text: string): TPoint; virtual;
34 end;
35
36 TCanvas = class
37 private
38 FPen: TPen;
39 FBrush: TBrush;
40 FFont: TFont;
41 protected
42 function GetVideoDevice: TVideoDevice; virtual;
43 public
44 Parent: TCanvas;
45 function AdjustPos(Position: TPoint): TPoint; virtual;
46 procedure TextOut(Position: TPoint; Text: string);
47 function GetTextSize(Text: string): TPoint;
48 procedure MoveTo(Position: TPoint);
49 procedure LineTo(Position: TPoint);
50 procedure Line(StartPos, EndPos: TPoint; Color: TColor);
51 procedure SetPixel(Position: TPoint; Color: TColor);
52 function GetPixel(Position: TPoint): TColor;
53 procedure FillRect(Rect: TRectangle);
54 constructor Create;
55 destructor Destroy; override;
56 property Pen: TPen read FPen;
57 property Brush: TBrush read FBrush;
58 property Font: TFont read FFont;
59 property VideoDevice: TVideoDevice read GetVideoDevice;
60 end;
61
62 TBitmap = class
63 private
64 function GetPixel(X, Y: Integer): TColor;
65 procedure SetPixel(X, Y: Integer; const Value: TColor);
66 public
67 property Pixels[X, Y: Integer]: TColor read GetPixel write SetPixel;
68 end;
69
70
71implementation
72
73{ TPen }
74
75{ TCanvas }
76
77function TCanvas.AdjustPos(Position: TPoint): TPoint;
78begin
79 Result := Position;
80end;
81
82constructor TCanvas.Create;
83begin
84 FPen := TPen.Create;
85 FBrush := TBrush.Create;
86 FFont := TFont.Create;
87end;
88
89destructor TCanvas.Destroy;
90begin
91 FFont.Destroy;
92 FBrush.Destroy;
93 FPen.Destroy;
94 inherited;
95end;
96
97procedure TCanvas.FillRect(Rect: TRectangle);
98begin
99 Rect.TopLeft := AdjustPos(Rect.TopLeft);
100 if Assigned(VideoDevice) then VideoDevice.FillRect(Rect, Brush.Color);
101end;
102
103function TCanvas.GetPixel(Position: TPoint): TColor;
104begin
105 if Assigned(VideoDevice) then Result := VideoDevice.GetPixel(Position)
106 else Result := clNone;
107end;
108
109function TCanvas.GetTextSize(Text: string): TPoint;
110begin
111 if Assigned(VideoDevice) then
112 Result := VideoDevice.GetTextSize(Text)
113 else Result := TPoint.Create(0, 0);
114end;
115
116function TCanvas.GetVideoDevice: TVideoDevice;
117begin
118 Result := nil;
119end;
120
121procedure TCanvas.Line(StartPos, EndPos: TPoint; Color: TColor);
122begin
123 if Assigned(Parent) then Parent.Line(StartPos, EndPos, Color);
124end;
125
126procedure TCanvas.LineTo(Position: TPoint);
127begin
128 if Assigned(VideoDevice) then
129 VideoDevice.Line(AdjustPos(Pen.Position), AdjustPos(Position), Pen.Color);
130 MoveTo(Position);
131end;
132
133procedure TCanvas.MoveTo(Position: TPoint);
134begin
135 Pen.Position := Position;
136end;
137
138procedure TCanvas.SetPixel(Position: TPoint; Color: TColor);
139begin
140 if Assigned(VideoDevice) then VideoDevice.SetPixel(Position, Color);
141end;
142
143procedure TCanvas.TextOut(Position: TPoint; Text: string);
144begin
145 if Assigned(VideoDevice) then VideoDevice.TextOut(AdjustPos(Position), Text);
146end;
147
148{ TBitmap }
149
150function TBitmap.GetPixel(X, Y: Integer): TColor;
151begin
152
153end;
154
155procedure TBitmap.SetPixel(X, Y: Integer; const Value: TColor);
156begin
157
158end;
159
160
161{ TVideoDevice }
162
163procedure TVideoDevice.FillRect(Rect: TRectangle; Color: TColor);
164begin
165
166end;
167
168function TVideoDevice.GetPixel(Position: TPoint): TColor;
169begin
170 Result := clNone;
171end;
172
173function TVideoDevice.GetTextSize(Text: string): TPoint;
174begin
175 Result := TPoint.Create(0, 0);
176end;
177
178procedure TVideoDevice.Line(Pos1, Pos2: TPoint; Color: TColor);
179begin
180
181end;
182
183procedure TVideoDevice.SetPixel(Position: TPoint; Color: TColor);
184begin
185
186end;
187
188procedure TVideoDevice.TextOut(Position: TPoint; Text: string);
189begin
190end;
191
192end.
Note: See TracBrowser for help on using the repository browser.