Einzelnen Beitrag anzeigen

Glados
(Gast)

n/a Beiträge
 
#15

AW: Panel geschmeidig ein- und ausblenden?

  Alt 16. Sep 2017, 23:09
Ich habe dir hier mal ein Beispiel gebastelt. Einfach in einen Button packen (Form sollte initial ~500 hoch sein) und die Caption beobachten.

Delphi-Quellcode:
function QuintEasing(TimePassed, Duration: DWord): Single;
var
 P: Double;
begin
 P := TimePassed / (Duration / 2);
 if (P < 1) then
  begin
   Result := 1 / 2 * P * P * P * P * P;
  end
 else
  begin
   P := P - 2;
   Result := 1 / 2 * (P * P * P * P * P + 2);
  end;
end;


Button
var
 C, D: Cardinal;
const
 Duration = 3000;
 POS_START = 200; // Größe eingeklappt
 POS_END = 500; // Größe ausgeklappt
begin
 C := GetTickCount;
 D := 0;
 if Height >= POS_END then
  begin
   // EDIT
   // Mit diesem Spagetti-Code funktioniert es auch. Aber das ist sicherlich alles mehr als falsch
   // POS_END := POS_END - POS_START - (POS_END - Height);
   // POS_START := Height;

   while (D < Duration) do
    begin
     Height := POS_START - Round(POS_END * QuintEasing(D, Duration));
     Application.ProcessMessages;
     D := GetTickCount - C;
    end;

   Caption := '1. ' + Height.ToString;

   // Formular wird beim ersten Klick erst einmalig 700px hoch eingestellt (falsch) und fährt dann auf 200px runter (richtig)
  end
 else
  begin
   // POS_START := Height;
   // POS_END := POS_END - POS_START;
   // Diese beiden Zeilen reparieren dieses If-Statement. Oben verstehe ich die umgekehrte Logik aber nicht und finde keine Lösung.

   while (D < Duration) do
    begin
     Height := POS_START + Round(POS_END * QuintEasing(D, Duration));
     Application.ProcessMessages;
     D := GetTickCount - C;
    end;

   Caption := '2. ' + Height.ToString;

   // Ein anschließender Klick hier stellt das Formular 700px hoch ein (falsch)
  end;
Edit: siehe Kommentar bei Height >= POS_END

Geändert von Glados (16. Sep 2017 um 23:37 Uhr)
  Mit Zitat antworten Zitat