Delphi-PRAXiS
Seite 3 von 6     123 45     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Panel geschmeidig ein- und ausblenden? (https://www.delphipraxis.net/193860-panel-geschmeidig-ein-und-ausblenden.html)

Headbucket 18. Sep 2017 07:01

AW: Panel geschmeidig ein- und ausblenden?
 
Guten Morgen,

mich wundert sehr, dass hier noch niemand TSplitView genannt hat. Dieser ist ja genau für deinen Zweck gemacht und es wurde bereits eine Animation für das Ein- und Ausblenden implementiert.

Er ist allerdings erst ab den neueren Delphi-Versionen enthalten.

Grüße
Headbucket

Glados 20. Sep 2017 00:33

AW: Panel geschmeidig ein- und ausblenden?
 
Zacherl, ich habe mit deinen neuen Codes zwei Units für mich erstellt. Jetzt kann ich die Animationen gut verwenden.

Darf ich die hier reinstellen und teilen?

Zacherl 20. Sep 2017 01:11

AW: Panel geschmeidig ein- und ausblenden?
 
Zitat:

Zitat von Glados (Beitrag 1381678)
Darf ich die hier reinstellen und teilen?

Aber gerne doch :thumb:

Glados 20. Sep 2017 11:03

AW: Panel geschmeidig ein- und ausblenden?
 
Hier die zwei Units. ich packe das in Delphi-Tags, damit jeder Zugriff hat. Es sind circa 200 Zeilen Code.
Delphi-Quellcode:
// Ein Aufruf, Um ButtonY auf FormX horizontal von Position 20 zu 200 und umgekehrt zu animieren, könnte so aussehen
TUtilsEasingAnimations.AnimateControl(FormX.ButtonY, 20, 200, TAnimationDirection.adHorizontal, TAnimationType.adChangeLeftTop);

// Wenn man den Button in der Breite von 20 zu 200 und umgekehrt animieren möchte so
TUtilsEasingAnimations.AnimateControl(FormX.ButtonY, 20, 200, TAnimationDirection.adHorizontal, TAnimationType.adChangeWidthHeight);
Selbes gilt für adVertical statt adHorizontal.

Speziell AnimateControl hat Optimierungsbedarf. Für mich aber funktioniert es. Kritik gerne willkommen.

### 99% von diesem Code wurde von Zacherl erstellt ###

Core Unit
Delphi-Quellcode:
unit Utils.Easing.Core;

interface

uses Math;

type
 TUtilsEasingCore = class
 public
  class function EaseInQuart(T, B, C, D: Integer): Integer; static;
  class function EaseOutQuart(T, B, C, D: Integer): Integer; static;
  class function EaseInQuint(T, B, C, D: Integer): Integer; static;
  class function EaseOutQuint(T, B, C, D: Integer): Integer; static;
  class function EaseOutBounce(T, B, C, D: Integer): Integer; static;
  class function EaseOutElastic(T, B, C, D: Integer): Integer; static;
 end;

implementation

// Quart easing
// ==============================================================================================================================================
class function TUtilsEasingCore.EaseInQuart(T, B, C, D: Integer): Integer;
var
 T2: Single;
begin
 T2 := T / D;
 Result := Round(C * T2 * T2 * T2 * T2) + B;
end;

class function TUtilsEasingCore.EaseOutQuart(T, B, C, D: Integer): Integer;
var
 T2: Single;
begin
 T2 := T / D - 1;
 Result := Round(-C * (T2 * T2 * T2 * T2 - 1)) + B;
end;
// ==============================================================================================================================================

// Quint easing
// ==============================================================================================================================================
class function TUtilsEasingCore.EaseInQuint(T, B, C, D: Integer): Integer;
var
 T2: Single;
begin
 T2 := T / D;
 Result := Round(C * T2 * T2 * T2 * T2 * T2) + B;
end;

class function TUtilsEasingCore.EaseOutQuint(T, B, C, D: Integer): Integer;
var
 T2: Single;
begin
 T2 := T / D - 1;
 Result := Round(C * (T2 * T2 * T2 * T2 * T2 + 1)) + B;
end;
// ==============================================================================================================================================

// Bounce/elastic easing
// ==============================================================================================================================================
class function TUtilsEasingCore.EaseOutBounce(T, B, C, D: Integer): Integer;
var
 T2: Single;
begin
 T2 := T / D;
 if (T2 < (1.0 / 2.75)) then
  begin
   Result := Round(C * (7.5625 * T2 * T2)) + B;
  end
 else if (T2 < (2.0 / 2.75)) then
  begin
   T2 := T2 - (1.5 / 2.75);
   Result := Round(C * (7.5625 * T2 * T2 + 0.75)) + B;
  end
 else if (T2 < (2.5 / 2.75)) then
  begin
   T2 := T2 - (2.25 / 2.75);
   Result := Round(C * (7.5625 * T2 * T2 + 0.9375)) + B;
  end
 else
  begin
   T2 := T2 - (2.625 / 2.75);
   Result := Round(C * (7.5625 * T2 * T2 + 0.984375)) + B;
  end;
end;

class function TUtilsEasingCore.EaseOutElastic(T, B, C, D: Integer): Integer;
var
 S, P, A, T2: Double;
begin
 if (T = 0) then
  begin
   Exit(B);
  end;
 T2 := T / D;
 if (T2 = 1) then
  begin
   Exit(B + C);
  end;
 P := D * 0.3;
 A := C;
 if (A < Abs(C)) then
  begin
   S := P / 4;
  end
 else
  begin
   S := P / (2 * PI) * ArcSin(C / A);
  end;
 Result := Round(A * Power(2, -10 * T2) * Sin((T2 * D - S) * (2 * PI) / P)) + C + B;
end;
// ==============================================================================================================================================

end.
Unit, welche für die Animation zuständig ist
Delphi-Quellcode:
unit Utils.Easing.Animations;

interface

uses Winapi.Windows, Vcl.Controls, Vcl.Forms, SysUtils;

type
 TAnimationDirection = (adHorizontal, adVertical);
 TAnimationType = (adChangeWidthHeight, adChangeLeftTop);

type
 TUtilsEasingAnimations = class
 private const
  AnimateDuration = 300;
 public
  class procedure AnimateControl(Control: TWinControl; iStart, iEnd: Integer; aAnimationDirection: TAnimationDirection; aAnimationType: TAnimationType); static;
 end;

implementation

uses Utils.Easing.Core;

// Main animation controller
// ==============================================================================================================================================
// Example call:
// TUtilsEasingAnimations.AnimateControl(FormX.ButtonY, 20, 200, TAnimationDirection.adHorizontal, TAnimationType.adChangeLeftTop);
class procedure TUtilsEasingAnimations.AnimateControl(Control: TWinControl; iStart, iEnd: Integer; aAnimationDirection: TAnimationDirection; aAnimationType: TAnimationType);
var
 C, D: Cardinal;
 iTmpControlDimension, iTmp, iStartTmp, iEndTmp: Integer;
 procedure setControlDimension(iDimension: Integer);
 begin
  if aAnimationDirection = TAnimationDirection.adHorizontal then
   begin
    if aAnimationType = TAnimationType.adChangeWidthHeight then
     Control.Width := iDimension
    else if aAnimationType = TAnimationType.adChangeLeftTop then
     Control.Left := iDimension
   end
  else if aAnimationDirection = TAnimationDirection.adVertical then
   begin
    if aAnimationType = TAnimationType.adChangeWidthHeight then
     Control.Height := iDimension
    else if aAnimationType = TAnimationType.adChangeLeftTop then
     Control.Top := iDimension;
   end;
 end;

begin
 // Prepare needed data
 // ==============================================================================================================================================
 C := GetTickCount;
 D := 0;
 iTmpControlDimension := 0;

 if aAnimationDirection = TAnimationDirection.adHorizontal then
  begin
   if aAnimationType = TAnimationType.adChangeWidthHeight then
    iTmpControlDimension := Control.Width
   else if aAnimationType = TAnimationType.adChangeLeftTop then
    iTmpControlDimension := Control.Left;
  end
 else if aAnimationDirection = TAnimationDirection.adVertical then
  begin
   if aAnimationType = TAnimationType.adChangeWidthHeight then
    iTmpControlDimension := Control.Height
   else if aAnimationType = TAnimationType.adChangeLeftTop then
    iTmpControlDimension := Control.Top;
  end;

 if iTmpControlDimension = 0 then
  Exit;

 iStartTmp := iTmpControlDimension;
 iEndTmp := iEnd;
 if iStartTmp >= iEndTmp then
  begin
   iTmp := iStart;
   iStart := iEnd;
   iEnd := iTmp;
  end;
 // ============================================================================================================================================== end;

 // Display the animation
 // ==============================================================================================================================================
 while (D <= TUtilsEasingAnimations.AnimateDuration) do
  begin
   setControlDimension(TUtilsEasingCore.EaseOutQuint(D, iStart, iEnd - iStart, TUtilsEasingAnimations.AnimateDuration));

   Application.ProcessMessages;
   D := GetTickCount - C;
  end;
 setControlDimension(iEnd);
 // ==============================================================================================================================================
end;
// ==============================================================================================================================================

end.

EWeiss 20. Sep 2017 11:21

AW: Panel geschmeidig ein- und ausblenden?
 
Ich würde mal die Namensgebung überdenken in 5 Jahren weist selbst du nicht mehr für was "T, B, C, D" überhaupt steht.
Ob das sinnvoll ist das gesamte Alphabet in seinem Code zu implementieren mag dahin gestellt sein.

gruss

Der schöne Günther 20. Sep 2017 11:26

AW: Panel geschmeidig ein- und ausblenden?
 
Zitat:

Zitat von Headbucket (Beitrag 1381414)
dass hier noch niemand TSplitView genannt hat. Dieser ist ja genau für deinen Zweck gemacht und es wurde bereits eine Animation für das Ein- und Ausblenden implementiert.

Haben wir auch seit 1, 2 Jahren in Verwendung. Macht keine Mucken, läuft flüssig, alles ok :thumb:

Glados 20. Sep 2017 12:01

AW: Panel geschmeidig ein- und ausblenden?
 
Zitat:

Ich würde mal die Namensgebung überdenken in 5 Jahren weist selbst du nicht mehr für was "T, B, C, D" überhaupt steht.
Wie erwähnt sind 99% des Codes nicht von mir sondern von Zacherl.

Zitat:

dass hier noch niemand TSplitView genannt hat. Dieser ist ja genau für deinen Zweck gemacht und es wurde bereits eine Animation für das Ein- und Ausblenden implementiert.
Das kann man nicht vergleichen. Versuche mal mit TSplitView einen Button von oben nach unten "easen" zu lassen.

EWeiss 20. Sep 2017 12:27

AW: Panel geschmeidig ein- und ausblenden?
 
Zitat:

Wie erwähnt sind 99% des Codes nicht von mir sondern von Zacherl.
Na ja es könnte ja nicht schaden einen Vermerk hinzuzuschreiben wofür T, B, C, D denn steht.
Es gibt immer so viele unnütze Kommentare im Code, hier wäre es angebracht ;)

Ist nur ein Ratschlag.
Zacherl hat es drauf keine frage :)

Ich sehe gerade Zacherl hat es zum Code addiert.. das solltest du unbedingt berichtigen.
Als Kommentar hinzufügen.

Zitat:

T = Vergangene Zeit
B = Startwert
C = Änderung
D = Dauer der Animation
gruss

Glados 20. Sep 2017 12:40

AW: Panel geschmeidig ein- und ausblenden?
 
Abgesehen davon, dass ich diese Prefix-Gebung hier unten mag, so sieht es etwas einleuchtender aus denke ic h
Delphi-Quellcode:
  class function EaseInQuart(iTimeElapsed, iValueStart, iValueEnd, iAnimationTime: Integer): Integer;
  ...

EWeiss 20. Sep 2017 12:44

AW: Panel geschmeidig ein- und ausblenden?
 
Zitat:

Zitat von Glados (Beitrag 1381712)
Abgesehen davon, dass ich diese Prefix-Gebung hier unten mag, so sieht es etwas einleuchtender aus denke ic h
Delphi-Quellcode:
  class function EaseInQuart(iTimeElapsed, iValueStart, iValueEnd, iAnimationTime: Integer): Integer;
  ...

Dito! :)

gruss


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:54 Uhr.
Seite 3 von 6     123 45     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz