Changeset 61


Ignore:
Timestamp:
Apr 7, 2024, 11:50:48 PM (8 months ago)
Author:
chronos
Message:
  • Modified: Kernel API class definition improvement.
Location:
trunk/Packages/Kernel
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Kernel/Kernel.API.pas

    r60 r61  
    3838  end;
    3939
    40   { TKernelApi }
     40  { TSystemApi }
    4141
    42   TKernelApi = class
    43     Kernel: TObject; //TKernel;
    44     function Call(Command: TApiCommand; Data: Pointer): Pointer;
    45     procedure WriteText(Text: string);
    46     procedure DrawText(CanvasId: Integer; P: TPoint; Text: string; Color: TColor);
    47     procedure DrawLine(CanvasId: Integer; P1, P2: TPoint; Color: TColor);
    48     procedure DrawRect(CanvasId: Integer; Rect: TRectangle; Color: TColor);
    49     procedure DrawFrame(CanvasId: Integer; Rect: TRectangle; Color: TColor);
    50     procedure Sleep(Time: TDateTime);
    51     procedure ReadMessage(Message: TIPCMessage);
    52     function WindowCreate: Integer;
    53     function GetWindowCanvas(WindowId: Integer): Integer;
    54     procedure WindowSetAttr(WindowId: Integer; Bounds: TRectangle; Visible: Boolean);
     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;
    5554  end;
    5655
     
    166165end;
    167166
    168 { TKernelApi }
    169 
    170 function TKernelApi.Call(Command: TApiCommand; Data: Pointer
    171   ): Pointer;
    172 begin
    173   case Command of
    174     acDrawLine: DrawLine(TDrawLineParams(Data^).CanvasId, TDrawLineParams(Data^).P1,
    175       TDrawLineParams(Data^).P2, TDrawLineParams(Data^).Color);
    176     acDrawRect: DrawRect(TDrawRectParams(Data^).CanvasId, TDrawRectParams(Data^).Rect,
    177       TDrawRectParams(Data^).Color);
    178     acDrawFrame: DrawFrame(TDrawRectParams(Data^).CanvasId, TDrawRectParams(Data^).Rect,
    179       TDrawRectParams(Data^).Color);
    180     acDrawText: DrawText(TDrawTextParams(Data^).CanvasId, TDrawTextParams(Data^).P,
    181       TDrawTextParams(Data^).Text, TDrawTextParams(Data^).Color);
    182     acSleep: Sleep(TDateTime(Data^));
    183     acWindowCreate: Result := Pointer(WindowCreate);
    184     acWindowSetAttr: WindowSetAttr(TWindowSetAttrParams(Data^).WindowId,
    185       TWindowSetAttrParams(Data^).Bounds, TWindowSetAttrParams(Data^).Visible);
    186     acWriteText: WriteText(string(Data));
    187     acReadMessage: ReadMessage(Data);
    188     acGetWindowCanvas: Result := Pointer(GetWindowCanvas(Integer(Data)));
    189   end;
    190 end;
    191 
    192 procedure TKernelApi.WriteText(Text: string);
    193 var
    194   Device: TDeviceSerial;
    195 begin
    196   Device := TDeviceSerial(TKernel(Kernel).Devices.FindByName('Serial0'));
    197   if Assigned(Device) then begin
    198     Device.WriteText(Text);
    199   end else raise Exception.Create('Device Serial0 not found');
    200 end;
    201 
    202 procedure TKernelApi.DrawText(CanvasId: Integer; P: TPoint; Text: string; Color: TColor);
    203 var
    204   Screen: TScreen;
    205   Canvas: TCanvas;
    206 begin
    207   Canvas := TKernel(Kernel).Desktop.FindCanvasById(CanvasId);
    208   if Assigned(Canvas) then begin
    209     Canvas.DrawText(P, Text, Color);
    210   end;
    211 end;
    212 
    213 procedure TKernelApi.DrawLine(CanvasId: Integer; P1, P2: TPoint; Color: TColor);
    214 var
    215   Screen: TScreen;
    216   Canvas: TCanvas;
    217 begin
    218   Canvas := TKernel(Kernel).Desktop.FindCanvasById(CanvasId);
    219   if Assigned(Canvas) then begin
    220     Canvas.DrawLine(P1.Add(Canvas.Position), P2.Add(Canvas.Position), Color);
    221   end;
    222 end;
    223 
    224 procedure TKernelApi.DrawRect(CanvasId: Integer; Rect: TRectangle; Color: TColor);
    225 var
    226   Canvas: TCanvas;
    227 begin
    228   Canvas := TKernel(Kernel).Desktop.FindCanvasById(CanvasId);
    229   if Assigned(Canvas) then begin
    230     Canvas.DrawRect(Rect, Color);
    231   end;
    232 end;
    233 
    234 procedure TKernelApi.DrawFrame(CanvasId: Integer; Rect: TRectangle;
    235   Color: TColor);
    236 var
    237   Canvas: TCanvas;
    238 begin
    239   Canvas := TKernel(Kernel).Desktop.FindCanvasById(CanvasId);
    240   if Assigned(Canvas) then begin
    241     Canvas.DrawFrame(Rect, Color);
    242   end;
    243 end;
    244 
    245 procedure TKernelApi.Sleep(Time: TDateTime);
    246 var
    247   Task: TTask;
    248 begin
    249   Task := TKernel(Kernel).Scheduler.GetCurrentTask;
    250   Task.Sleep(Time);
    251 end;
    252 
    253 procedure TKernelApi.ReadMessage(Message: TIPCMessage);
    254 var
    255   Task: TTask;
    256 begin
    257   Task := TKernel(Kernel).Scheduler.GetCurrentTask;
    258   while Task.Messages.List.Count = 0 do Task.WaitForMessage;
    259 end;
    260 
    261 function TKernelApi.WindowCreate: Integer;
    262 var
    263   Window: TWindow;
    264 begin
    265   Window := TKernel(Kernel).Desktop.CreateWindow;
    266   Window.Desktop := TKernel(Kernel).Desktop;
    267   Result := Window.Id;
    268 end;
    269 
    270 function TKernelApi.GetWindowCanvas(WindowId: Integer): Integer;
    271 var
    272   Window: TWindow;
    273   Canvas: TCanvas;
    274 begin
    275   Window := TWindow(TKernel(Kernel).Desktop.FindObjectById(WindowId));
    276   if Assigned(Window) then begin
    277     Canvas := Window.Canvas;
    278     Result := Canvas.Id;
    279   end else Result := -1;
    280 end;
    281 
    282 procedure TKernelApi.WindowSetAttr(WindowId: Integer; Bounds: TRectangle; Visible: Boolean);
    283 var
    284   Window: TWindow;
    285 begin
    286   Window := TWindow(TKernel(Kernel).Desktop.FindObjectById(WindowId));
    287   if Assigned(Window) then begin
    288     Window.Bounds := Bounds;
    289     Window.Canvas.Position := Bounds.Position;
    290     Window.Visible := Visible;
    291     Window.Desktop.Paint;
    292   end;
    293 end;
    294 
    295 
    296167end.
    297168
  • trunk/Packages/Kernel/Kernel.Core.pas

    r60 r61  
    66  Classes, SysUtils, Kernel.List, Kernel.FileSystem, Kernel.Memory,
    77  Kernel.Screen, Kernel.Device, Kernel.App, Kernel.Scheduler, Kernel.Api,
    8   Kernel.Graphics, Generics.Collections;
     8  Kernel.Graphics, Generics.Collections, Kernel.IPC;
    99
    1010type
     
    2525  TKernel = class
    2626  private
    27     Api: TKernelApi;
     27    Api: TSystemApi;
    2828    procedure InitVideo;
    2929    function KernelApiExecute(Command: TApiCommand; Data: Pointer): Pointer;
     
    4747
    4848implementation
     49
     50uses
     51  Kernel.KernelAPI;
    4952
    5053{ TDrive }
     
    162165  Screens := TObjectList<TScreen>.Create;
    163166  Api := TKernelApi.Create;
    164   Api.Kernel := Self;
     167  TKernelApi(Api).Kernel := Self;
    165168  Desktop := TDesktop.Create;
    166169end;
  • trunk/Packages/Kernel/Kernel.Screen.pas

    r60 r61  
    44
    55uses
    6   SysUtils, Math, Kernel.Graphics;
     6  SysUtils, Math, Kernel.Graphics, Kernel.Device;
    77
    88type
     
    3131    function GetVideoMemory: PByte;
    3232  public
    33     Device: TObject; // TDeviceVideo;
     33    Device: TDeviceVideo;
    3434    Size: TPoint;
    3535    DPI: Integer;
     
    4444
    4545implementation
    46 
    47 uses
    48   Kernel.Device;
    4946
    5047{ TScreenCanvas }
  • trunk/Packages/Kernel/Kernel.lpk

    r60 r61  
    2424      </Other>
    2525    </CompilerOptions>
    26     <Files Count="13">
     26    <Files Count="14">
    2727      <Item1>
    2828        <Filename Value="Kernel.API.pas"/>
     
    7878        <UnitName Value="KernelPackage"/>
    7979      </Item13>
     80      <Item14>
     81        <Filename Value="Kernel.KernelAPI.pas"/>
     82        <UnitName Value="Kernel.KernelAPI"/>
     83      </Item14>
    8084    </Files>
    8185    <CompatibilityMode Value="True"/>
  • trunk/Packages/Kernel/KernelPackage.pas

    r60 r61  
    1111  Kernel.API, Kernel.App, Kernel.Classes, Kernel.FileSystem, Kernel.Graphics,
    1212  Kernel.Core, Kernel.List, Kernel.Memory, Kernel.Device, Kernel.Screen,
    13   Kernel.IPC, Kernel.Scheduler, LazarusPackageIntf;
     13  Kernel.IPC, Kernel.Scheduler, Kernel.KernelAPI, LazarusPackageIntf;
    1414
    1515implementation
Note: See TracChangeset for help on using the changeset viewer.