Einzelnen Beitrag anzeigen

Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#7

AW: MouseMove verzögern

  Alt 23. Mär 2016, 10:42
Ich habs jetzt anders. So wollte ichs eigentlich lassen. Soll so eine Art dynamischer Timer sein (Basiert auf DeddyH’s TWaitCounter).
Delphi-Quellcode:
  TWaitCounterEx = class
  private
    FStart, FStop, FFrequency: Int64;
    FStartTime, FStopTime, FWaitTime: double;
    FSuccess: boolean;
    function GetCanWaitTimer: boolean;
  public
    procedure Start;
    procedure Stop;
    property WaitTime: double read FWaitTime;
    property CanWaitTimer: boolean read GetCanWaitTimer;
    constructor Create;
  end;

..

{ TWaitCounterEx }

constructor TWaitCounterEx.Create;
begin
  FSuccess := QueryPerformanceFrequency(FFrequency);
end;

procedure TWaitCounterEx.Start;
begin
  if FSuccess and QueryPerformanceCounter(FStart) then
    FStartTime := FStart / FFrequency;
end;

procedure TWaitCounterEx.Stop;
begin
  if FSuccess and QueryPerformanceCounter(FStop) then
  begin
    FStopTime := FStop / FFrequency;
    FWaitTime := (FStop - FStart) / FFrequency;
  end;
end;

function TWaitCounterEx.GetCanWaitTimer: boolean;
begin
  // NewStartTime - OldStopTime >= OldWaitTime;
  Result := not FSuccess or (CompareValue(FStartTime - FStopTime, FWaitTime, 1E-8) >= 0);
end;

(*
procedure TSomeForm.PaintBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  FWaitCounter.Start;
  try
    if FWaitCounter.CanWaitTimer then
    begin
      ..
    end;
  finally
    FWaitCounter.Stop;
  end;
end;
*)

Geändert von Bjoerk (23. Mär 2016 um 10:55 Uhr) Grund: Umformuliert
  Mit Zitat antworten Zitat