source: branches/Xvcl/Xvcl.Kernel.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: 5.4 KB
Line 
1unit Xvcl.Kernel;
2
3interface
4
5uses
6 Xvcl.Generics, Xvcl.Classes, Xvcl.Forms, Xvcl.Controls, Xvcl.Graphics;
7
8type
9 TKernel = class;
10 TScreen = class;
11
12 TProcessState = (psReady, psRunning, psWaiting, psFinished);
13
14 TProcess = class
15 Id: Integer;
16 Name: string;
17 Priority: Integer;
18 State: TProcessState;
19 procedure Execute; virtual;
20 end;
21
22 TDriver = class
23 Name: string;
24 Kernel: TKernel;
25 procedure Initialize; virtual;
26 procedure Finalize; virtual;
27 end;
28
29 TScreenCanvas = class(TCanvas)
30 Screen: TScreen;
31 function GetVideoDevice: TVideoDevice; override;
32 end;
33
34 TScreen = class(TComponent)
35 Canvas: TScreenCanvas;
36 Size: TPoint;
37 Forms: TList<TForm>;
38 VideoDevice: TVideoDevice;
39 procedure Paint;
40 procedure FocusForm(Form: TForm);
41 constructor Create; override;
42 destructor Destroy; override;
43 end;
44
45 TKeyboard = class
46 Kernel: TKernel;
47 KeysState: array[Word] of Boolean;
48 function ReadKey: Char;
49 function KeyPressed: Boolean;
50 end;
51
52 TMouse = class
53 Kernel: TKernel;
54 procedure HandleMove(Position: TPoint);
55 procedure HandleDown(Position: TPoint);
56 procedure HandleUp(Position: TPoint);
57 end;
58
59 TScheduler = class
60 Kernel: TKernel;
61 procedure Reschedule;
62 end;
63
64 TKernel = class
65 private
66 FOnAfterDriverInit: TNotifyEvent;
67 FOnTick: TNotifyEvent;
68 public
69 Processes: TList<TProcess>;
70 Drivers: TList<TDriver>;
71 StartOnBoot: TList<TApplication>;
72 Screen: TScreen;
73 Keyboard: TKeyboard;
74 Mouse: TMouse;
75 Scheduler: TScheduler;
76 Terminated: Boolean;
77 procedure Boot;
78 procedure PowerOff;
79 procedure Reboot;
80 constructor Create;
81 destructor Destroy; override;
82 property OnAfterDriverInit: TNotifyEvent read FOnAfterDriverInit
83 write FOnAfterDriverInit;
84 property OnTick: TNotifyEvent read FOnTick write FOnTick;
85 end;
86
87
88implementation
89
90{ TKernel }
91
92procedure TKernel.Boot;
93var
94 Driver: TDriver;
95 App: TApplication;
96begin
97 for Driver in Drivers do
98 Driver.Initialize;
99
100 for App in StartOnBoot do
101 App.Run;
102
103 repeat
104 Scheduler.Reschedule;
105 if Assigned(FOnTick) then FOnTick(Self);
106 until Terminated;
107
108 for Driver in Drivers do
109 Driver.Finalize;
110end;
111
112constructor TKernel.Create;
113begin
114 Processes := TList<TProcess>.Create;
115 Drivers := TList<TDriver>.Create;
116 Screen := TScreen.Create;
117 StartOnBoot := TList<TApplication>.Create;
118 Scheduler := TScheduler.Create;
119 Keyboard := TKeyboard.Create;
120 Keyboard.Kernel := Self;
121 Mouse := TMouse.Create;
122 Mouse.Kernel := Self;
123end;
124
125destructor TKernel.Destroy;
126begin
127 Mouse.Destroy;
128 Keyboard.Destroy;
129 Scheduler.Destroy;
130 StartOnBoot.Destroy;
131 Screen.Destroy;
132 Drivers.Destroy;
133 Processes.Destroy;
134 inherited;
135end;
136
137
138procedure TKernel.PowerOff;
139begin
140
141end;
142
143procedure TKernel.Reboot;
144begin
145
146end;
147
148{ TScreen }
149
150constructor TScreen.Create;
151begin
152 inherited;
153 Forms := TList<TForm>.Create;
154 Canvas := TScreenCanvas.Create;
155 Canvas.Screen := Self;
156end;
157
158destructor TScreen.Destroy;
159begin
160 Canvas.Destroy;
161 Forms.Destroy;
162 inherited;
163end;
164
165procedure TScreen.FocusForm(Form: TForm);
166var
167 I: Integer;
168 FormIndex: Integer;
169begin
170 FormIndex := Forms.IndexOf(Form);
171 for I := 0 to Forms.Count - 1 do
172 Forms[I].Focused := I = FormIndex;
173
174 Forms.Move(FormsIndex, Forms.Count - 1);
175 Paint;
176end;
177
178procedure TScreen.Paint;
179var
180 Form: TForm;
181begin
182 Canvas.Brush.Color := clWhite;
183 Canvas.FillRect(TRectangle.Create(0, 0, Size.X, Size.Y));
184 for Form in Forms do Form.Paint;
185end;
186
187{ TDriver }
188
189procedure TDriver.Finalize;
190begin
191
192end;
193
194procedure TDriver.Initialize;
195begin
196
197end;
198
199{ TScheduler }
200
201procedure TScheduler.Reschedule;
202begin
203
204end;
205
206{ TKeyboard }
207
208function TKeyboard.KeyPressed: Boolean;
209begin
210end;
211
212function TKeyboard.ReadKey: Char;
213begin
214
215end;
216
217{ TProcess }
218
219procedure TProcess.Execute;
220begin
221
222end;
223
224{ TMouse }
225
226procedure TMouse.HandleDown(Position: TPoint);
227var
228 Form: TForm;
229 NewMessage: TMessageMouseDown;
230begin
231 NewMessage := TMessageMouseDown.Create;
232 NewMessage.Position := Position;
233 try
234 for Form in Kernel.Screen.Forms do
235 if Form.Bounds.Contains(Position) then begin
236 if Form.HandleMessage(NewMessage) then begin
237 Break;
238 end;
239 end;
240 finally
241 NewMessage.Destroy;
242 end;
243end;
244
245procedure TMouse.HandleMove(Position: TPoint);
246var
247 Form: TForm;
248 NewMessage: TMessageMouseMove;
249begin
250 NewMessage := TMessageMouseMove.Create;
251 NewMessage.Position := Position;
252 try
253 for Form in Kernel.Screen.Forms do
254 if Form.Bounds.Contains(Position) then begin
255 if Form.HandleMessage(NewMessage) then begin
256 Break;
257 end;
258 end;
259 finally
260 NewMessage.Destroy;
261 end;
262end;
263
264procedure TMouse.HandleUp(Position: TPoint);
265var
266 Form: TForm;
267 NewMessage: TMessageMouseUp;
268begin
269 NewMessage := TMessageMouseUp.Create;
270 NewMessage.Position := Position;
271 try
272 for Form in Kernel.Screen.Forms do
273 if Form.Bounds.Contains(Position) then begin
274 if Form.HandleMessage(NewMessage) then begin
275 Break;
276 end;
277 end;
278 finally
279 NewMessage.Destroy;
280 end;
281end;
282
283{ TScrenCanvas }
284
285function TScreenCanvas.GetVideoDevice: TVideoDevice;
286begin
287 if Assigned(Screen) then Result := Screen.VideoDevice
288 else Result := nil;
289end;
290
291end.
Note: See TracBrowser for help on using the repository browser.