unit Unit8;
interface
uses
SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, vg_scene, vg_objects, vg_effects, vg_layouts, vg_ani,
vg_controls, ImgList, vg_actions;
type
TSelectedEvent =
procedure (aHoover : Boolean = True)
of object;
TMySelectBtn =
class(TvgBitmapButton)
private
FSelecting : Boolean;
FSelected : Boolean;
FSelectEvent : TSelectedEvent;
FResetEvent : TNotifyEvent;
FPaddingOut : TvgRectAnimation;
FWidthOut : TvgFloatAnimation;
FBmpSizeOut : TvgFloatAnimation;
procedure DoOnClick(aSender : TObject);
procedure DoPaddingAnimation;
procedure DoWidthAnimation;
procedure DoBmpSizeAnimation;
procedure SetHoover(
const Value: Boolean);
procedure DoSelect;
public
constructor Create(aOwner : TComponent; aParent : TvgObject);
reintroduce;
property SelectEvent : TSelectedEvent
read FSelectEvent
write FSelectEvent;
property ResetEvent : TNotifyEvent
read FResetEvent
write FResetEvent;
property Selected : Boolean
read FSelected
write SetHoover;
end;
TForm8 =
class(TForm)
vgScene1 : TvgScene;
Root1 : TvgBackground;
Rectangle1 : TvgRectangle;
Rectangle2 : TvgRectangle;
Rectangle3 : TvgRectangle;
Image1 : TvgImage;
Text1 : TvgText;
Text2 : TvgText;
Layout1 : TvgLayout;
Layout2 : TvgLayout;
Layout3 : TvgLayout;
Rectangle5 : TvgRectangle;
Text3 : TvgText;
Text4 : TvgText;
Text5 : TvgText;
Text6 : TvgText;
vgResources1 : TvgResources;
Container : TvgLayout;
containerOut : TvgFloatAnimation;
Resources1 : TvgResources;
BitmapButton1 : TvgBitmapButton;
vgImageList2 : TvgImageList;
procedure DoContainerAnimation(aIsButtonSelected : Boolean = True);
procedure DoReset(aSender : TObject);
private
BtnYellow : TMySelectBtn;
BtnBlue : TMySelectBtn;
BtnGreen : TMySelectBtn;
BtnRed : TMySelectBtn;
public
constructor Create(aOwner : TComponent);
override;
procedure ResetAllButtons;
end;
var
Form8: TForm8;
implementation
{$R *.dfm}
procedure TForm8.ResetAllButtons;
/// Im Setter der Property wird die Animation ausgelöst.
begin
BtnGreen.Selected := False;
BtnRed.Selected := False;
BtnBlue.Selected := False;
BtnYellow.Selected := False;
Container.Width := 450;
end;
procedure TForm8.DoContainerAnimation(aIsButtonSelected: Boolean);
/// Diese Animation macht den Container breiter, so das ein
/// (breiter) Selected-Button hineipasst. Da alle Nuttons Left-Aligned sind
/// gibt es einen schönen Verschiebe- Effekt.
begin
containerOut.Inverse :=
not aIsButtonSelected;
containerOut.Start;
end;
constructor TForm8.Create(aOwner : TComponent);
/// 4 Buttons für unseren Container, denen mitgegeben wird
/// welche Prozedur beim Resetten und Selected aufzurufen ist.
begin
inherited;
BtnYellow := TMySelectBtn.Create(Self, Container);
if vgImageList2.Count > 0
then
BtnYellow.Bitmap := vgImageList2.Images[0];
BtnYellow.Text := '
Yellow';
BtnYellow.SelectEvent := DoContainerAnimation;
BtnYellow.ResetEvent := DoReset;
BtnBlue := TMySelectBtn.Create(Self, Container);
if vgImageList2.Count > 1
then
BtnBlue.Bitmap := vgImageList2.Images[1];
BtnBlue.Text := '
Blue';
BtnBlue.SelectEvent := DoContainerAnimation;
BtnBlue.ResetEvent := DoReset;
BtnGreen := TMySelectBtn.Create(Self, Container);
if vgImageList2.Count > 2
then
BtnGreen.Bitmap := vgImageList2.Images[2];
BtnGreen.Text := '
Green';
BtnGreen.SelectEvent := DoContainerAnimation;
BtnGreen.ResetEvent := DoReset;
BtnRed := TMySelectBtn.Create(Self, Container);
if vgImageList2.Count > 3
then
BtnRed.Bitmap := vgImageList2.Images[3];
BtnRed.Text := '
Red';
BtnRed.SelectEvent := DoContainerAnimation;
BtnRed.ResetEvent := DoReset;
end;
procedure TForm8.DoReset(aSender: TObject);
/// Zurück auf Anfang.
begin
ResetAllButtons;
end;
{ TMySelectBtn }
constructor TMySelectBtn.Create(aOwner : TComponent; aParent : TvgObject);
begin
inherited Create(aOwner);
FSelected := False;
Parent := aParent;
Position.X := 1000;
// entspricht Left
Align := vaLeft;
Resource := '
acroButton';
// Definition im DFM
Width := 110;
BitmapLayout := vgGlyphTop;
BitmapSize := 64;
BitmapPadding := 13;
Font.Size := 14;
OnClick := DoOnClick;
// 1. Animation für das "Oversizen"
FPaddingOut := TvgRectAnimation.Create(aOwner);
FPaddingOut.Parent := Self;
FPaddingOut.PropertyName := '
Padding';
FPaddingOut.Duration := 0.2;
FPaddingOut.StartValue := TvgBounds.Create(vgRect(0, 0, 0, 0));
FPaddingOut.StopValue := TvgBounds.Create(vgRect(0, -60, 0, -30));
// 2. Animation für das Vergrößern/Verkleiner beim Selektieren/Klicken
FWidthOut := TvgFloatAnimation.Create(aOwner);
FWidthOut.Parent := Self;
FWidthOut.PropertyName := '
Width';
FWidthOut.Duration := 0.2;
FWidthOut.StartValue := 110;
FWidthOut.StopValue := 260;
// 3. Animation für das Zoomen der Button-Grafik
FBmpSizeOut := TvgFloatAnimation.Create(aOwner);
FBmpSizeOut.Parent := Self;
FBmpSizeOut.PropertyName := '
BitmapSize';
FBmpSizeOut.Duration := 0.2;
FBmpSizeOut.StartValue := 64;
FBmpSizeOut.StopValue := 120;
end;
procedure TMySelectBtn.DoSelect;
/// Gleichzeitiges Starten der Animationen, dadurch ist die Reihenfolge egal.
begin
if FSelecting
then
Exit;
FSelecting := True;
try
FSelected :=
not FSelected;
if Assigned(FResetEvent)
then
FResetEvent(Self);
DoPaddingAnimation;
DoWidthAnimation;
DoBmpSizeAnimation;
if Assigned(FSelectEvent)
then
FSelectEvent(FSelected);
finally
FSelecting := False;
end;
end;
procedure TMySelectBtn.DoOnClick(aSender: TObject);
begin
DoSelect;
end;
procedure TMySelectBtn.DoPaddingAnimation;
begin
FPaddingOut.Inverse :=
not FSelected;
FPaddingOut.Start;
end;
procedure TMySelectBtn.SetHoover(
const Value: Boolean);
begin
if FSelected <> Value
then
DoSelect;
end;
procedure TMySelectBtn.DoWidthAnimation;
begin
FWidthOut.Inverse :=
not FSelected;
FWidthOut.Start;
end;
procedure TMySelectBtn.DoBmpSizeAnimation;
begin
FBmpSizeOut.Inverse :=
not FSelected;
FBmpSizeOut.Start;
end;
end.