unit FMXTee.Editor.Series.Polar;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Chart.ListBox,
  FMX.TabControl, FMXTee.Series.Polar, FMX.Edit, FMX.ListBox, FMX.Colors,
  FMX.Layouts, FMXTee.Editor.Font, FMXTee.Editor.Series.Circled,
  FMXTee.Editor.Series.Pointer, FMXTee.Engine;

type
  TPolarSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabLabels: TTabItem;
    TabFont: TTabItem;
    TabOptions: TTabItem;
    BPen: TButton;
    BBrush: TButton;
    UDTransp: TSpinBox;
    Label6: TLabel;
    CBColorEach: TCheckBox;
    CBNulls: TComboBox;
    ListBoxItem7: TListBoxItem;
    ListBoxItem8: TListBoxItem;
    ListBoxItem9: TListBoxItem;
    Label1: TLabel;
    SEAngleInc: TEdit;
    LAngleInc: TLabel;
    SERadiusInc: TEdit;
    Label4: TLabel;
    BPiePen: TButton;
    CBClose: TCheckBox;
    CBAngleLabels: TCheckBox;
    CBLabelsRot: TCheckBox;
    CBClockWise: TCheckBox;
    CBInside: TCheckBox;
    UDMargin: TSpinBox;
    Label2: TLabel;
    CBColor: TComboColorBox;
    procedure FormActivate(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure BBrushClick(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure UDTranspChange(Sender: TObject);
    procedure SEAngleIncChange(Sender: TObject);
    procedure CBNullsChange(Sender: TObject);
    procedure SERadiusIncChange(Sender: TObject);
    procedure BPiePenClick(Sender: TObject);
    procedure CBCloseChange(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
    procedure CBAngleLabelsChange(Sender: TObject);
    procedure CBLabelsRotChange(Sender: TObject);
    procedure CBClockWiseChange(Sender: TObject);
    procedure CBInsideChange(Sender: TObject);
    procedure UDMarginChange(Sender: TObject);
    procedure ComboColorBox1Change(Sender: TObject);
  private
    { Private declarations }
    // PointerForm    : TCustomForm;
    FCircledEditor : TCircledSeriesEditor;
    FPointerEditor : TSeriesPointerEditor;

    procedure EnableLabels;
  protected
    Polar : TCustomPolarSeries;
    procedure HideAngleInc; virtual;
    function CreatePolar:TCustomPolarSeries; virtual;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Series, FMXTee.Procs, FMXTee.Editor.Stroke, FMXTee.Editor.Brush,
  FMXTee.Constants;

procedure TPolarSeriesEditor.HideAngleInc;
begin
  LAngleInc.Visible:=Polar is TPolarSeries;
  SEAngleInc.Visible:=Polar is TPolarSeries;
end;

procedure TPolarSeriesEditor.CBAngleLabelsChange(Sender: TObject);
begin
  if Assigned(Polar) then
  begin
    Polar.CircleLabels:=CBAngleLabels.IsChecked;
    EnableLabels;
  end;
end;

procedure TPolarSeriesEditor.CBClockWiseChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.ClockWiseLabels:=CBClockWise.IsChecked;
end;

procedure TPolarSeriesEditor.CBCloseChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.CloseCircle:=CBClose.IsChecked;
end;

procedure TPolarSeriesEditor.CBColorChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.SeriesColor:=CBColor.Color;
end;

procedure TPolarSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.ColorEachPoint:=CBColorEach.IsChecked;
end;

procedure TPolarSeriesEditor.CBInsideChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.CircleLabelsInside:=CBInside.IsChecked;
end;

procedure TPolarSeriesEditor.CBLabelsRotChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.CircleLabelsRotated:=CBLabelsRot.IsChecked;
end;

procedure TPolarSeriesEditor.CBNullsChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.TreatNulls:=TTreatNullsStyle(CBNulls.ItemIndex);
end;

procedure TPolarSeriesEditor.ComboColorBox1Change(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.SeriesColor:=CBColor.Color;
end;

procedure TPolarSeriesEditor.SEAngleIncChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.AngleIncrement:=StrToFloatDef(SEAngleInc.Text,Polar.AngleIncrement);
end;

procedure TPolarSeriesEditor.SERadiusIncChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.RadiusIncrement:=StrToFloatDef(SERadiusInc.Text,Polar.RadiusIncrement);
end;

procedure TPolarSeriesEditor.BBrushClick(Sender: TObject);
begin
  if Assigned(Polar) then
    TBrushEditor.Edit(Self, Polar.Brush)
end;

procedure TPolarSeriesEditor.BPenClick(Sender: TObject);
begin
  if Assigned(Polar) then
  begin
    TStrokeEditor.Edit(Self, Polar.Pen);
    Polar.SeriesColor:=Polar.Pen.Color;
  end;
end;

procedure TPolarSeriesEditor.BPiePenClick(Sender: TObject);
begin
  if Assigned(Polar) then
    TStrokeEditor.Edit(Self, Polar.CirclePen);
end;

procedure TPolarSeriesEditor.EnableLabels;
begin
  EnableControls(CBAngleLabels.IsChecked,[CBLabelsRot,CBClockWise]);
end;

procedure TPolarSeriesEditor.FormActivate(Sender: TObject);
var FFontEditor : TForm;
    TabCircled,
    TabPointer  : TTabItem;
begin
  Polar:=CreatePolar;

  if Assigned(Polar) then
  begin
    With Polar do
    begin
      CBClose.IsChecked       :=CloseCircle;
      CBClockWise.IsChecked   :=ClockWiseLabels;

      SEAngleInc.Text         :=FloatToStr(AngleIncrement);
      SERadiusInc.Text        :=FloatToStr(RadiusIncrement);

      CBAngleLabels.IsChecked :=CircleLabels;
      CBLabelsRot.IsChecked   :=CircleLabelsRotated;
      CBInside.IsChecked      :=CircleLabelsInside;

      UDMargin.Value          :=LabelsMargin;
      UDTransp.Value          :=Transparency;
      CBColorEach.IsChecked   :=ColorEachPoint;
      CBNulls.ItemIndex       :=Ord(TreatNulls);
      CBColor.Color           :=SeriesColor;

      FFontEditor:=TFontEditor.CreateEditor(Self, CircleLabelsFont);
      FFontEditor.Name:=TeeGetUniqueName(Self,'FontEditor');
      EmbeddForm(FFontEditor, TabFont);
    end;

    EnableLabels;

    if not Assigned(FCircledEditor) then
    begin
      FCircledEditor:=TCircledSeriesEditor.Create(Self);

      TabCircled:=TTabItem.Create(Self);
      TabCircled.Text:=TeeMsg_GalleryCircled;
      TabControl1.AddObject(TabCircled);

      EmbeddForm(FCircledEditor,TabCircled);
    end;
    if not Assigned(FPointerEditor) then
    begin
      FPointerEditor:=TSeriesPointerEditor(TSeriesPointerEditor.CreateEditor(Self,Polar.Pointer));

      TabPointer:=TTabItem.Create(Self);
      TabPointer.Text:=TeeMsg_GalleryPoint;
      TabControl1.AddObject(TabPointer);

      EmbeddForm(FPointerEditor, TabPointer);
    end;

    FCircledEditor.RefreshCircled(Polar);
  end;
end;

procedure TPolarSeriesEditor.UDMarginChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.LabelsMargin:=Round(UDMargin.Value);
end;

procedure TPolarSeriesEditor.UDTranspChange(Sender: TObject);
begin
  if Assigned(Polar) then
    Polar.Transparency:=Round(UDTransp.Value);
end;

function TPolarSeriesEditor.CreatePolar: TCustomPolarSeries;
begin
  result:=TCustomPolarSeries(TagObject);
end;

initialization
  RegisterSeriesEditor(TPolarSeriesEditor);
end.
