{********************************************}
{ TSeriesAnimationTool Editor Dialog         }
{ Copyright (c) 2002-2020 by Steema Software }
{********************************************}
unit TeeSeriesAnimEdit;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,

  Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, Buttons, ExtCtrls,

  TeCanvas, TeeProcs, TeEngine, TeeAnimations;

type
  TSeriesAnimationEditor = class(TForm)
    CBStartMin: TCheckBox;
    Label4: TLabel;
    EStart: TEdit;
    Label5: TLabel;
    Edit1: TEdit;
    UDEvery: TUpDown;
    Label6: TLabel;
    CBLoop: TComboFlat;
    Label1: TLabel;
    CBSeries: TComboFlat;
    procedure FormShow(Sender: TObject);
    procedure CBStartMinClick(Sender: TObject);
    procedure EStartChange(Sender: TObject);
    procedure CBSeriesChange(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure CBLoopChange(Sender: TObject);
  private
    { Private declarations }
    Animation : TSeriesAnimation;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  TeeConst, TeeProCo;

procedure TSeriesAnimationEditor.FormShow(Sender: TObject);
var tmp : TCustomAxisPanel;
begin
  inherited;

  Animation:=TSeriesAnimation(Tag);

  if Assigned(Animation) then
  With Animation do
  begin
    CBStartMin.Checked:=StartAtMin;
    EStart.Text:=FloatToStr(StartValue);
    EStart.Enabled:=not CBStartMin.Checked;
    UDEvery.Position:=DrawEvery;

    if Loop=salNo then
       CBLoop.ItemIndex:=0
    else
    if Loop=salOneWay then
       CBLoop.ItemIndex:=1
    else
       CBLoop.ItemIndex:=2;

    CBSeries.Items.Clear;
    CBSeries.Items.Add(TeeMsg_All);

    tmp:=Animation.Chart;
    if not Assigned(tmp) then
       if Assigned(Animation.Series) then
          tmp:=Animation.Series.ParentChart;

    if Assigned(tmp) then
       FillSeriesItems(CBSeries.Items,tmp.SeriesList);

    CBSeries.ItemIndex:=CBSeries.Items.IndexOfObject(Animation.Series);
  end;
end;

procedure TSeriesAnimationEditor.CBStartMinClick(Sender: TObject);
begin
  Animation.StartAtMin:=CBStartMin.Checked;
  EStart.Enabled:=not CBStartMin.Checked;
end;

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

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

procedure TSeriesAnimationEditor.Edit1Change(Sender: TObject);
begin
  if Showing then
     Animation.DrawEvery:=UDEvery.Position;
end;

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

initialization
  RegisterClass(TSeriesAnimationEditor);
end.
