| 1 | unit Kernel.API;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | SysUtils, Kernel.List, DateUtils, Kernel.Memory, Kernel.Graphics, Kernel.Device,
|
|---|
| 7 | Kernel.IPC, Kernel.Scheduler, Kernel.Screen;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 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 |
|
|---|
| 76 | implementation
|
|---|
| 77 |
|
|---|
| 78 | uses
|
|---|
| 79 | Kernel.Core;
|
|---|
| 80 |
|
|---|
| 81 | { TUserApi }
|
|---|
| 82 |
|
|---|
| 83 | function TUserApi.Call(Command: TApiCommand; Data: Pointer
|
|---|
| 84 | ): Pointer;
|
|---|
| 85 | begin
|
|---|
| 86 | Result := KernelApiCallback(Command, Data);
|
|---|
| 87 | end;
|
|---|
| 88 |
|
|---|
| 89 | procedure TUserApi.WriteText(Text: string);
|
|---|
| 90 | begin
|
|---|
| 91 | Call(acWriteText, Pointer(Text));
|
|---|
| 92 | end;
|
|---|
| 93 |
|
|---|
| 94 | procedure TUserApi.DrawText(CanvasId: Integer; P: TPoint; Text: string; Color: TColor);
|
|---|
| 95 | var
|
|---|
| 96 | Params: TDrawTextParams;
|
|---|
| 97 | begin
|
|---|
| 98 | Params.CanvasId := CanvasId;
|
|---|
| 99 | Params.P := P;
|
|---|
| 100 | Params.Text := Text;
|
|---|
| 101 | Params.Color := Color;
|
|---|
| 102 | Call(acDrawText, @Params);
|
|---|
| 103 | end;
|
|---|
| 104 |
|
|---|
| 105 | procedure TUserApi.DrawLine(CanvasId: Integer; P1, P2: TPoint; Color: TColor);
|
|---|
| 106 | var
|
|---|
| 107 | Params: TDrawLineParams;
|
|---|
| 108 | begin
|
|---|
| 109 | Params.CanvasId := CanvasId;
|
|---|
| 110 | Params.P1 := P1;
|
|---|
| 111 | Params.P2 := P2;
|
|---|
| 112 | Params.Color := Color;
|
|---|
| 113 | Call(acDrawLine, @Params);
|
|---|
| 114 | end;
|
|---|
| 115 |
|
|---|
| 116 | procedure TUserApi.DrawRect(CanvasId: Integer; Rect: TRectangle; Color: TColor);
|
|---|
| 117 | var
|
|---|
| 118 | Params: TDrawRectParams;
|
|---|
| 119 | begin
|
|---|
| 120 | Params.CanvasId := CanvasId;
|
|---|
| 121 | Params.Rect := Rect;
|
|---|
| 122 | Params.Color := Color;
|
|---|
| 123 | Call(acDrawRect, @Params);
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | procedure TUserApi.DrawFrame(CanvasId: Integer; Rect: TRectangle; Color: TColor
|
|---|
| 127 | );
|
|---|
| 128 | var
|
|---|
| 129 | Params: TDrawRectParams;
|
|---|
| 130 | begin
|
|---|
| 131 | Params.CanvasId := CanvasId;
|
|---|
| 132 | Params.Rect := Rect;
|
|---|
| 133 | Params.Color := Color;
|
|---|
| 134 | Call(acDrawFrame, @Params);
|
|---|
| 135 | end;
|
|---|
| 136 |
|
|---|
| 137 | procedure TUserApi.Sleep(Time: TDateTime);
|
|---|
| 138 | begin
|
|---|
| 139 | Call(acSleep, @Time);
|
|---|
| 140 | end;
|
|---|
| 141 |
|
|---|
| 142 | procedure TUserApi.ReadMessage(Message: TIPCMessage);
|
|---|
| 143 | begin
|
|---|
| 144 | Call(acReadMessage, Message);
|
|---|
| 145 | end;
|
|---|
| 146 |
|
|---|
| 147 | function TUserApi.WindowCreate: Integer;
|
|---|
| 148 | begin
|
|---|
| 149 | Result := Integer(Call(acWindowCreate, nil));
|
|---|
| 150 | end;
|
|---|
| 151 |
|
|---|
| 152 | function TUserApi.GetWindowCanvas(WindowId: Integer): Integer;
|
|---|
| 153 | begin
|
|---|
| 154 | Call(acGetWindowCanvas, Pointer(WindowId));
|
|---|
| 155 | end;
|
|---|
| 156 |
|
|---|
| 157 | procedure TUserApi.WindowSetAttr(WindowId: Integer; Bounds: TRectangle; Visible: Boolean);
|
|---|
| 158 | var
|
|---|
| 159 | Params: TWindowSetAttrParams;
|
|---|
| 160 | begin
|
|---|
| 161 | Params.WindowId := WindowId;
|
|---|
| 162 | Params.Bounds := Bounds;
|
|---|
| 163 | Params.Visible := Visible;
|
|---|
| 164 | Call(acWindowSetAttr, @Params);
|
|---|
| 165 | end;
|
|---|
| 166 |
|
|---|
| 167 | end.
|
|---|
| 168 |
|
|---|