Changeset 8 for trunk/Forms


Ignore:
Timestamp:
May 9, 2015, 1:32:38 AM (10 years ago)
Author:
chronos
Message:
  • Moved: Kernel related files moved to separate lazarus package named Kernel.
  • Modified: Implemented simple graphic device driver and drawin example.
Location:
trunk/Forms
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r7 r8  
    2020    Align = alClient
    2121    OnClick = PaintBox1Click
     22    OnPaint = PaintBox1Paint
    2223    OnResize = PaintBox1Resize
    2324  end
  • trunk/Forms/UFormMain.pas

    r7 r8  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ExtCtrls, Menus, ActnList, UKernel, UMemory;
     9  ExtCtrls, Menus, ActnList, UKernel, UMemory, UDevice, UPlatformBase, LCLType;
    1010
    1111type
     
    3232    procedure FormShow(Sender: TObject);
    3333    procedure PaintBox1Click(Sender: TObject);
     34    procedure PaintBox1Paint(Sender: TObject);
    3435    procedure PaintBox1Resize(Sender: TObject);
    3536  private
     37    VideoDevice: TDeviceVideoBase;
     38    SerialDevice: TBaseSerialDevice;
    3639    SerialText: string;
    3740    OriginalBounds: TRect;
     
    3942    ScreenBounds: TRect;
    4043    procedure SerialDeviceReceiveDataSync;
    41     procedure SerialDeviceReceiveData(Data: TMemory);
     44    procedure SerialDeviceReceiveData(Text: string);
    4245    procedure VideoDeviceRedraw(Sender: TObject);
     46    procedure VideoDeviceRedrawSync;
    4347    procedure SwitchFullScreen;
     48    procedure EraseBackground(DC: HDC); override;
    4449  public
    4550    Kernel: TKernel;
     
    5257
    5358uses
    54   UList, UApp, UAPI, UClock, UPlatformBase, UThreadEx, UFormTerminal;
     59  UList, UApp, UAPI, UClock, UThreadEx, UFormTerminal;
    5560
    5661{$R *.lfm}
     
    6166var
    6267  NewApp: TApp;
    63   SerialDevice: TBaseSerialDevice;
    64   VideoDevice: TBaseVideoDevice;
    65 begin
     68begin
     69  PaintBox1.ControlStyle := PaintBox1.ControlStyle + [csOpaque];
     70
    6671  Kernel := TKernel.Create;
    6772  Kernel.SchedulerClass := TBaseScheduler;
    6873  Kernel.FileSystemClass := TBaseFileSystem;
     74
    6975  SerialDevice := TBaseSerialDevice.Create;
    7076  SerialDevice.Name := 'Serial0';
     
    7379  Kernel.Devices.Add(SerialDevice);
    7480
    75   VideoDevice := TBaseVideoDevice.Create;
     81  VideoDevice := TDeviceVideoBase.Create;
    7682  VideoDevice.Name := 'Video0';
    7783  VideoDevice.ClassName := 'Graphic card';
    7884  VideoDevice.OnRedraw := VideoDeviceRedraw;
    7985  VideoDevice.DPI := Screen.PixelsPerInch;
    80   VideoDevice.VideoMemorySize := Point(PaintBox1.Width, PaintBox1.Height);;
     86  VideoDevice.VideoMemorySize := Point(PaintBox1.Width, PaintBox1.Height);
     87  VideoDevice.OnModeChanged := VideoDeviceRedraw;
    8188  Kernel.Devices.Add(VideoDevice);
    8289
     
    135142end;
    136143
     144procedure TFormMain.EraseBackground(DC: HDC);
     145begin
     146  //inherited EraseBackground(DC);
     147end;
     148
    137149procedure TFormMain.FormDestroy(Sender: TObject);
    138150begin
     
    156168end;
    157169
     170procedure TFormMain.PaintBox1Paint(Sender: TObject);
     171var
     172  X, Y: Integer;
     173  Bitmap: TBitmap;
     174begin
     175  try
     176    Bitmap := TBitmap.Create;
     177    Bitmap.BeginUpdate;
     178    Bitmap.SetSize(PaintBox1.Width, PaintBox1.Height);
     179
     180    if Assigned(VideoDevice.VideoMemory) then begin
     181      for Y := 0 to VideoDevice.VideoMode.Size.Y - 1 do
     182      for X := 0 to VideoDevice.VideoMode.Size.X - 1 do begin
     183        Bitmap.Canvas.Pixels[X, Y] := PInteger(VideoDevice.VideoMemory + X * VideoDevice.VideoMode.GetBytesPerPixel +
     184        Y * VideoDevice.VideoMode.GetBytesPerLine)^ and $ffffff;
     185      end;
     186    end;
     187  finally
     188    PaintBox1.Canvas.Draw(0, 0, Bitmap);
     189    Bitmap.EndUpdate;
     190    Bitmap.Free;
     191  end;
     192end;
     193
    158194procedure TFormMain.PaintBox1Resize(Sender: TObject);
    159195begin
     
    165201end;
    166202
    167 procedure TFormMain.SerialDeviceReceiveData(Data: TMemory);
    168 begin
    169   SetLength(SerialText, Data.Size);
    170   Move(Data.Data^, SerialText[1], Data.Size);
     203procedure TFormMain.SerialDeviceReceiveData(Text: string);
     204begin
     205  SerialText := Text;
    171206  TThreadEx.Synchronize(TThreadEx.CurrentThread, SerialDeviceReceiveDataSync);
    172207end;
     
    174209procedure TFormMain.VideoDeviceRedraw(Sender: TObject);
    175210begin
    176 
     211  TThreadEx.Synchronize(TThreadEx.CurrentThread, VideoDeviceRedrawSync);
     212end;
     213
     214procedure TFormMain.VideoDeviceRedrawSync;
     215begin
     216  PaintBox1.Refresh;
    177217end;
    178218
  • trunk/Forms/UFormTerminal.lfm

    r7 r8  
    1414    Width = 320
    1515    Align = alClient
     16    ReadOnly = True
     17    ScrollBars = ssAutoBoth
    1618    TabOrder = 0
    1719  end
Note: See TracChangeset for help on using the changeset viewer.