{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Animations.Gallery;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, FMXTee.Tools.Gallery, FMX.ListBox, FMX.TabControl, FMX.Layouts,
  FMX.Memo, FMX.Objects, FMXTee.Animations.Tools;

type
  TTeeAnimationToolClass=class of TTeeAnimationTool;

  TAnimationsGallery = class(TToolsGallery)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  protected
    IAnimType : TTeeToolType;

    function FilterTool(Index:Integer):Boolean; override;
    procedure FillTools; override;
  public
    { Public declarations }
    class var GalleryHook : TToolsGalleryHook;

    class function Choose(const AOwner:TComponent; out ASelected:String):TTeeAnimationToolClass;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Chart, FMXTee.Engine, FMXTee.Animate;

{ TAnimationsGallery }

class function TAnimationsGallery.Choose(
  const AOwner: TComponent; out ASelected:String): TTeeAnimationToolClass;
begin
  with TAnimationsGallery.CreateEditor(AOwner) do
  try
    if ShowModal=mrOk then
    begin
      result:=TTeeAnimationToolClass(SelectedTool);
      ASelected:=LBTool.Selected.Text;
    end
    else
      result:=nil;
  finally
    Free;
  end;
end;

procedure TAnimationsGallery.FillTools;
var tmp : TTeeCustomToolClass;
    t   : Integer;
    tmpClass : TTeeAnimationClass;
begin
  DontAddTools:=True; // <-- Special, to avoid adding Tools

  inherited;

  tmp:=TeeAnimationTypes[TeeAnimationTypes.IndexOf(TTeeAnimationTool)];

  if not Assigned(IAnimType) then
  begin
    IAnimType:=TTeeToolType.Create;
    IAnimType.ToolClass:=tmp;
  end;

  for t:=0 to TeeAnimationClasses.Count-1 do
  begin
    tmpClass:=TTeeAnimationClass(GetClass(TeeAnimationClasses[t]));
    AddTool(tmpClass.Description,IAnimType);
  end;
end;

function TAnimationsGallery.FilterTool(Index: Integer): Boolean;
begin
  result:=True;
end;

procedure TAnimationsGallery.FormCreate(Sender: TObject);
begin
  inherited;

  TabItem2.Visible:=False;
  TabItem3.Visible:=False;

  FillTypes(TeeAnimationTypes);
  TheGalleryHook:=GalleryHook;

  //  AllowEditButton:=False;
end;

initialization
  TAnimationsGallery.GalleryHook:=nil;
end.
