source: trunk/Packages/Kernel/Kernel.API.pas

Last change on this file was 61, checked in by chronos, 8 months ago
  • Modified: Kernel API class definition improvement.
File size: 4.4 KB
Line 
1unit Kernel.API;
2
3interface
4
5uses
6 SysUtils, Kernel.List, DateUtils, Kernel.Memory, Kernel.Graphics, Kernel.Device,
7 Kernel.IPC, Kernel.Scheduler, Kernel.Screen;
8
9type
10 TApiCommand = (acNone, acWriteText, acDrawText, acDrawLine, acDrawRect, acSleep,
11 acReadMessage, acWindowCreate, acWindowSetAttr, acGetWindowCanvas,
12 acDrawFrame);
13
14 TDrawTextParams = record
15 CanvasId: Integer;
16 P: TPoint;
17 Text: string;
18 Color: TColor;
19 end;
20
21 TDrawLineParams = record
22 CanvasId: Integer;
23 P1: TPoint;
24 P2: TPoint;
25 Color: TColor;
26 end;
27
28 TWindowSetAttrParams = record
29 WindowId: Integer;
30 Bounds: TRectangle;
31 Visible: Boolean;
32 end;
33
34 TDrawRectParams = record
35 CanvasId: Integer;
36 Rect: TRectangle;
37 Color: TColor;
38 end;
39
40 { TSystemApi }
41
42 TSystemApi = class
43 function Call(Command: TApiCommand; Data: Pointer): Pointer; virtual; abstract;
44 procedure WriteText(Text: string); virtual; abstract;
45 procedure DrawText(CanvasId: Integer; P: TPoint; Text: string; Color: TColor); virtual; abstract;
46 procedure DrawLine(CanvasId: Integer; P1, P2: TPoint; Color: TColor); virtual; abstract;
47 procedure DrawRect(CanvasId: Integer; Rect: TRectangle; Color: TColor); virtual; abstract;
48 procedure DrawFrame(CanvasId: Integer; Rect: TRectangle; Color: TColor); virtual; abstract;
49 procedure Sleep(Time: TDateTime); virtual; abstract;
50 procedure ReadMessage(Message: TIPCMessage); virtual; abstract;
51 function WindowCreate: Integer; virtual; abstract;
52 function GetWindowCanvas(WindowId: Integer): Integer; virtual; abstract;
53 procedure WindowSetAttr(WindowId: Integer; Bounds: TRectangle; Visible: Boolean); virtual; abstract;
54 end;
55
56 TApiCall = function (Command: TApiCommand; Data: Pointer): Pointer of object;
57
58 { TUserApi }
59
60 TUserApi = class
61 KernelApiCallback: TApiCall;
62 function Call(Command: TApiCommand; Data: Pointer): Pointer;
63 procedure WriteText(Text: string);
64 procedure DrawText(CanvasId: Integer; P: TPoint; Text: string; Color: TColor);
65 procedure DrawLine(CanvasId: Integer; P1, P2: TPoint; Color: TColor);
66 procedure DrawRect(CanvasId: Integer; Rect: TRectangle; Color: TColor);
67 procedure DrawFrame(CanvasId: Integer; Rect: TRectangle; Color: TColor);
68 procedure Sleep(Time: TDateTime);
69 procedure ReadMessage(Message: TIPCMessage);
70 function WindowCreate: Integer;
71 function GetWindowCanvas(WindowId: Integer): Integer;
72 procedure WindowSetAttr(WindowId: Integer; Bounds: TRectangle; Visible: Boolean);
73 end;
74
75
76implementation
77
78uses
79 Kernel.Core;
80
81{ TUserApi }
82
83function TUserApi.Call(Command: TApiCommand; Data: Pointer
84 ): Pointer;
85begin
86 Result := KernelApiCallback(Command, Data);
87end;
88
89procedure TUserApi.WriteText(Text: string);
90begin
91 Call(acWriteText, Pointer(Text));
92end;
93
94procedure TUserApi.DrawText(CanvasId: Integer; P: TPoint; Text: string; Color: TColor);
95var
96 Params: TDrawTextParams;
97begin
98 Params.CanvasId := CanvasId;
99 Params.P := P;
100 Params.Text := Text;
101 Params.Color := Color;
102 Call(acDrawText, @Params);
103end;
104
105procedure TUserApi.DrawLine(CanvasId: Integer; P1, P2: TPoint; Color: TColor);
106var
107 Params: TDrawLineParams;
108begin
109 Params.CanvasId := CanvasId;
110 Params.P1 := P1;
111 Params.P2 := P2;
112 Params.Color := Color;
113 Call(acDrawLine, @Params);
114end;
115
116procedure TUserApi.DrawRect(CanvasId: Integer; Rect: TRectangle; Color: TColor);
117var
118 Params: TDrawRectParams;
119begin
120 Params.CanvasId := CanvasId;
121 Params.Rect := Rect;
122 Params.Color := Color;
123 Call(acDrawRect, @Params);
124end;
125
126procedure TUserApi.DrawFrame(CanvasId: Integer; Rect: TRectangle; Color: TColor
127 );
128var
129 Params: TDrawRectParams;
130begin
131 Params.CanvasId := CanvasId;
132 Params.Rect := Rect;
133 Params.Color := Color;
134 Call(acDrawFrame, @Params);
135end;
136
137procedure TUserApi.Sleep(Time: TDateTime);
138begin
139 Call(acSleep, @Time);
140end;
141
142procedure TUserApi.ReadMessage(Message: TIPCMessage);
143begin
144 Call(acReadMessage, Message);
145end;
146
147function TUserApi.WindowCreate: Integer;
148begin
149 Result := Integer(Call(acWindowCreate, nil));
150end;
151
152function TUserApi.GetWindowCanvas(WindowId: Integer): Integer;
153begin
154 Call(acGetWindowCanvas, Pointer(WindowId));
155end;
156
157procedure TUserApi.WindowSetAttr(WindowId: Integer; Bounds: TRectangle; Visible: Boolean);
158var
159 Params: TWindowSetAttrParams;
160begin
161 Params.WindowId := WindowId;
162 Params.Bounds := Bounds;
163 Params.Visible := Visible;
164 Call(acWindowSetAttr, @Params);
165end;
166
167end.
168
Note: See TracBrowser for help on using the repository browser.