{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Animations.Series;
{$I TeeDefs.inc}

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, 
  {$IFDEF D19}
  FMX.Graphics, 
  {$ENDIF}
  FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.Layouts, FMXTee.Chart.GalleryPanel, FMX.TabControl,
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMX.ListBox, FMXTee.Animate, FMX.StdCtrls, FMXTee.Animations.Tools, FMX.Edit;

type
  TSeriesAnimationEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    CBStartMin: TCheckBox;
    Label5: TLabel;
    CBSeries: TComboBox;
    Label1: TLabel;
    EStart: TEdit;
    Label2: TLabel;
    EDrawEvery: TSpinBox;
    Label3: TLabel;
    CBLoop: TComboBox;
    procedure CBStartMinChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CBSeriesChange(Sender: TObject);
    procedure CBLoopChange(Sender: TObject);
    procedure EDrawEveryChangeTracking(Sender: TObject);
    procedure EStartChange(Sender: TObject);
  private
    { Private declarations }

    procedure PrepareControls;
  protected
    Animation : TSeriesAnimation;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Engine, FMXTee.Constants, FMXTee.Procs, FMXTee.Series;

procedure TSeriesAnimationEditor.CBStartMinChange(Sender: TObject);
begin
  Animation.StartAtMin:=CBStartMin.IsChecked;
end;

procedure TSeriesAnimationEditor.EStartChange(Sender: TObject);
begin
  if Assigned(Animation) then
     Animation.StartValue:=StrToFloatDef(EStart.Text,Animation.StartValue);
end;

procedure TSeriesAnimationEditor.EDrawEveryChangeTracking(Sender: TObject);
begin
  if Assigned(Animation) then
     Animation.DrawEvery:=Round(EDrawEvery.Value);
end;

procedure TSeriesAnimationEditor.CBLoopChange(Sender: TObject);
begin
  if Assigned(Animation) then
  case CBLoop.ItemIndex of
    0: Animation.Loop:=salNo;
    1: Animation.Loop:=salOneWay;
  else
    Animation.Loop:=salCircular;
  end;
end;

procedure TSeriesAnimationEditor.CBSeriesChange(Sender: TObject);
begin
  Animation.Series:=TChartSeries(CBSeries.Items.Objects[CBSeries.ItemIndex]);
end;

procedure TSeriesAnimationEditor.FormShow(Sender: TObject);
begin
  Animation:=TSeriesAnimation(TagObject);

  CBSeries.Items.Clear;

  if Animation<>nil then
  begin
    CBSeries.Items.Clear;

    if Animation.Chart<>nil then
       FillSeriesItems(CBSeries.Items,Animation.Chart.SeriesList);

    CBSeries.Items.Insert(0,TeeMsg_All);

    PrepareControls;
  end;
end;

procedure TSeriesAnimationEditor.PrepareControls;
begin
  CBStartMin.IsChecked:=Animation.StartAtMin;
  CBSeries.ItemIndex:=CBSeries.Items.IndexOfObject(Animation.Series);
  EDrawEvery.Value:=Animation.DrawEvery;

  case Animation.Loop of
    salNo: CBLoop.ItemIndex:=0;
    salOneWay: CBLoop.ItemIndex:=1;
  else
    CBLoop.ItemIndex:=2;
  end;

  EStart.Text:=FloatToStr(Animation.StartValue);
end;

initialization
  RegisterClass(TSeriesAnimationEditor);
end.
