unit FMXTee.Editor.Series.Custom;

interface

uses
  System.SysUtils, System.Types, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms,
  FMX.ListBox, FMX.Edit, FMX.Dialogs, FMXTee.Series;

type
  TCustomSeriesEditor = class(TForm)
    Label1: TLabel;
    LHeight: TLabel;
    Label2: TLabel;
    LTransp: TLabel;
    BLineBorder: TButton;
    BLineColor: TButton;
    GBStair: TGroupBox;
    CBStairs: TCheckBox;
    CBInvStairs: TCheckBox;
    CBSmoothed: TCheckBox;
    CBColorEach: TCheckBox;
    CBDark3D: TCheckBox;
    CBStack: TComboBox;
    UDHeight: TSpinBox;
    CBClick: TCheckBox;
    BBrush: TButton;
    BOutline: TButton;
    CBColorEachLine: TCheckBox;
    Button1: TButton;
    BGradient: TButton;
    CBNulls: TComboBox;
    TBTransp: TTrackBar;
    BEmboss: TButton;
    Button2: TButton;
    procedure BLineBorderClick(Sender: TObject);
    procedure BLineColorClick(Sender: TObject);
    procedure CBStackChange(Sender: TObject);
    procedure BBrushClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CBNullsChange(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure BEmbossClick(Sender: TObject);
    procedure CBStairsChange(Sender: TObject);
    procedure CBInvStairsChange(Sender: TObject);
    procedure CBSmoothedChange(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure CBDark3DChange(Sender: TObject);
    procedure CBClickChange(Sender: TObject);
    procedure CBColorEachLineChange(Sender: TObject);
    procedure BOutlineClick(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure UDHeightChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
   { Private declarations }
    Custom : TCustomSeries;

    procedure RefreshCustom(ACustom:TCustomSeries);
  public
   { Public declarations }
    class function CreateEditor(AOwner:TComponent; ACustom:TCustomSeries):TForm;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Canvas, FMXTee.Editor.Stroke, FMXTee.Editor.Brush,
  FMXTee.Editor.Shadow, FMXTee.Editor.Gradient, FMXTee.Procs,
  FMXTee.Editor.Series.Pointer, FMXTee.Engine;

procedure TCustomSeriesEditor.FormActivate(Sender: TObject);
begin
  if Custom<>TagObject then
     RefreshCustom(TCustomSeries(TagObject));
end;

type
  TCustomAccess=class(TCustomSeries);

procedure TCustomSeriesEditor.RefreshCustom(ACustom: TCustomSeries);
begin
  Custom:=ACustom;

  CBStairs.IsChecked:=Custom.Stairs;
  CBInvStairs.IsChecked:=Custom.InvertedStairs;

  {$IFDEF TEELITEEMB}
  CBSmoothed.Visible:=False;
  {$ELSE}
  CBSmoothed.IsChecked:=Custom.Smoothed;
  {$ENDIF}

  CBColorEach.IsChecked:=Custom.ColorEachPoint;
  CBDark3D.IsChecked:=Custom.Dark3D;
  CBClick.IsChecked:=Custom.ClickableLine;
  CBColorEachLine.IsChecked:=Custom.ColorEachLine;
  TBTransp.Value:=TCustomAccess(Custom).Transparency;
  CBNulls.ItemIndex:=Ord(Custom.TreatNulls);
  CBStack.ItemIndex:=Ord(TCustomAccess(Custom).Stacked);
  UDHeight.Value:=Custom.LineHeight;
end;

procedure TCustomSeriesEditor.BLineBorderClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Custom.Pen);
end;

procedure TCustomSeriesEditor.BLineColorClick(Sender: TObject);
begin
  Custom.Color:=EditColor(Self, Custom.Color);
end;

procedure TCustomSeriesEditor.BOutlineClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Custom.OutLine);
end;

procedure TCustomSeriesEditor.CBStairsChange(Sender: TObject);
begin
  Custom.Stairs:=CBStairs.IsChecked;
end;

procedure TCustomSeriesEditor.CBInvStairsChange(Sender: TObject);
begin
  Custom.InvertedStairs:=CBInvStairs.IsChecked;
end;

procedure TCustomSeriesEditor.CBSmoothedChange(Sender: TObject);
begin
  {$IFNDEF TEELITEEMB}
  Custom.Smoothed:=CBSmoothed.IsChecked;
  {$ENDIF}
end;

procedure TCustomSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  Custom.ColorEachPoint:=CBColorEach.IsChecked;
end;

procedure TCustomSeriesEditor.CBDark3DChange(Sender: TObject);
begin
  Custom.Dark3D:=CBDark3D.IsChecked;
end;

procedure TCustomSeriesEditor.CBStackChange(Sender: TObject);
begin
  TCustomAccess(Custom).Stacked:=TCustomSeriesStack(CBStack.ItemIndex);
end;

procedure TCustomSeriesEditor.CBClickChange(Sender: TObject);
begin
  Custom.ClickableLine:=CBClick.IsChecked;
end;

procedure TCustomSeriesEditor.BBrushClick(Sender: TObject);
begin
  TBrushEditor.Edit(Self, Custom.Brush);
end;

procedure TCustomSeriesEditor.CBColorEachLineChange(Sender: TObject);
begin
  Custom.ColorEachLine:=CBColorEachLine.IsChecked;
end;

class function TCustomSeriesEditor.CreateEditor(AOwner: TComponent;
  ACustom: TCustomSeries): TForm;
begin
  result:=TCustomSeriesEditor.Create(AOwner);
  TCustomSeriesEditor(result).RefreshCustom(ACustom);
end;

procedure TCustomSeriesEditor.Button1Click(Sender: TObject);
begin
  TShadowEditor.Edit(Self, Custom.Shadow);
end;

procedure TCustomSeriesEditor.Button2Click(Sender: TObject);
begin
  TSeriesPointerEditor.Edit(Self, Custom.Pointer);
end;

procedure TCustomSeriesEditor.CBNullsChange(Sender: TObject);
begin
  Custom.TreatNulls:=TTreatNullsStyle(CBNulls.ItemIndex);
end;

procedure TCustomSeriesEditor.TBTranspChange(Sender: TObject);
begin
  TCustomAccess(Custom).Transparency:=Round(TBTransp.Value);
end;

procedure TCustomSeriesEditor.UDHeightChange(Sender: TObject);
begin
  Custom.LineHeight:=Round(UDHeight.Value);
end;

procedure TCustomSeriesEditor.BEmbossClick(Sender: TObject);
begin
  TShadowEditor.Edit(Self, Custom.Emboss);
end;

procedure TCustomSeriesEditor.BGradientClick(Sender: TObject);
begin
  TGradientEditor.Edit(Self, Custom.Brush.Gradient);
end;

initialization
  RegisterSeriesEditor(TCustomSeriesEditor);
end.
