Changeset 10


Ignore:
Timestamp:
Aug 29, 2016, 5:35:21 PM (8 years ago)
Author:
chronos
Message:
  • Added: Second clock task running in parallel.
  • Modified: Redraw screen only with maximum defined period. Not after each graphic operation.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Apps/UClock.pas

    r9 r10  
    1313
    1414  TAppClock = class(TApp)
     15    procedure Run(Task: TTask); override;
     16    constructor Create; override;
     17  end;
     18
     19  { TAppClock2 }
     20
     21  TAppClock2 = class(TApp)
    1522    procedure Run(Task: TTask); override;
    1623    constructor Create; override;
     
    3643    Angle := Frac(Now / (10 * OneSecond)) * 2 * Pi;
    3744    API.DrawLine(Point(120, 120), Point(Trunc(120 + Cos(Angle) * 60), Trunc(120 + Sin(Angle) * 60)), 0);
    38     API.Sleep(OneMillisecond * 100);
     45    API.Sleep(OneMillisecond * 50);
    3946    //API.ReadMessage(Message);
    4047  end;
     
    4855end;
    4956
     57{ TAppClock2 }
     58
     59procedure TAppClock2.Run(Task: TTask);
     60var
     61  Message: TIPCMessage;
     62  WindowId: Integer;
     63  Angle: Double;
     64begin
     65  Message := TIPCMessage.Create;
     66  WindowId := API.WindowCreate;
     67  API.WindowSetAttr(300, 200, True);
     68  while not Task.Terminated do begin
     69    API.WriteText('test2');
     70    API.DrawRect(Rect(260, 160, 380, 280), $ffff80);
     71    API.DrawText(Point(210, 110), 'Text', 0);
     72    Angle := Frac(Now / (10 * OneSecond)) * 2 * Pi;
     73    API.DrawLine(Point(320, 220), Point(Trunc(320 + Cos(Angle) * 60), Trunc(220 + Sin(Angle) * 60)), 0);
     74    API.Sleep(OneMillisecond * 300);
     75    //API.ReadMessage(Message);
     76  end;
     77  Message.Free;
     78end;
     79
     80constructor TAppClock2.Create;
     81begin
     82  inherited Create;
     83  Name := 'Clock2';
     84end;
     85
    5086end.
    5187
  • trunk/Forms/UFormMain.lfm

    r9 r10  
    5555    end
    5656  end
     57  object Timer1: TTimer
     58    Interval = 50
     59    OnTimer = Timer1Timer
     60    left = 180
     61    top = 281
     62  end
    5763end
  • trunk/Forms/UFormMain.pas

    r9 r10  
    2424    MenuItem4: TMenuItem;
    2525    PaintBox1: TPaintBox;
     26    Timer1: TTimer;
    2627    procedure AExitExecute(Sender: TObject);
    2728    procedure AFullscreenExecute(Sender: TObject);
     
    3435    procedure PaintBox1Paint(Sender: TObject);
    3536    procedure PaintBox1Resize(Sender: TObject);
     37    procedure Timer1Timer(Sender: TObject);
    3638  private
     39    RedrawPending: Boolean;
    3740    VideoDevice: TDeviceVideoBase;
    3841    SerialDevice: TBaseSerialDevice;
     
    6669var
    6770  NewApp: TApp;
     71  NewApp2: TApp;
    6872begin
    6973  PaintBox1.ControlStyle := PaintBox1.ControlStyle + [csOpaque];
     
    9094  NewApp := TAppClock.Create;
    9195  Kernel.Apps.Add(NewApp);
     96
     97  NewApp2 := TAppClock2.Create;
     98  Kernel.Apps.Add(NewApp2);
    9299end;
    93100
     
    196203end;
    197204
     205procedure TFormMain.Timer1Timer(Sender: TObject);
     206begin
     207  if RedrawPending then begin
     208    PaintBox1.Refresh;
     209    RedrawPending := False;
     210  end;
     211end;
     212
    198213procedure TFormMain.SerialDeviceReceiveDataSync;
    199214begin
     
    214229procedure TFormMain.VideoDeviceRedrawSync;
    215230begin
    216   PaintBox1.Refresh;
     231  RedrawPending := True;
    217232end;
    218233
  • trunk/Packages/Kernel/UKernel.pas

    r9 r10  
    1818  end;
    1919
    20   TTimer = class
    21     Period: TDateTime;
    22   end;
     20//  TTimer = class
     21//    Period: TDateTime;
     22//  end;
    2323
    2424  { TKernel }
     
    115115  NewFile.Name := 'Clock';
    116116  NewDrive.FileSystem.TopDirectory.Items.Add(NewFile);
    117   InitVideo;
     117
     118  NewFile := TFile.Create;
     119  NewFile.Name := 'Clock2';
     120  NewDrive.FileSystem.TopDirectory.Items.Add(NewFile);
     121InitVideo;
    118122end;
    119123
     
    129133    SystemFileSystem := SystemDrive.FileSystem;
    130134    AppFile := TFile(SystemFileSystem.TopDirectory.Items.FindByName('Clock'));
     135    if Assigned(AppFile) then AppExecute(AppFile)
     136      else raise Exception.Create('Cannot start first application');
     137    AppFile := TFile(SystemFileSystem.TopDirectory.Items.FindByName('Clock2'));
    131138    if Assigned(AppFile) then AppExecute(AppFile)
    132139      else raise Exception.Create('Cannot start first application');
Note: See TracChangeset for help on using the changeset viewer.