unit FMXTee.Editor.Tools.LegendPalette;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  FMX.ListBox, FMX.Edit, FMXTee.Tools.LegendPalette, FMX.TabControl, FMX.Colors;

type
  TLegendPaletteEditor = class(TSeriesToolEditor)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabPosition: TTabItem;
    TabPanel: TTabItem;
    BPen: TButton;
    CBVertical: TCheckBox;
    CBInverted: TCheckBox;
    CBTransparent: TCheckBox;
    CBSmooth: TCheckBox;
    BBorder: TButton;
    GBAxis: TGroupBox;
    RBDefault: TRadioButton;
    RBOther: TRadioButton;
    RBBoth: TRadioButton;
    CBUnits: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    UDLeft: TSpinBox;
    UDTop: TSpinBox;
    UDWidth: TSpinBox;
    UDHeight: TSpinBox;
    TabAxes: TTabItem;
    procedure FormActivate(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure BBorderClick(Sender: TObject);
    procedure CBVerticalChange(Sender: TObject);
    procedure CBInvertedChange(Sender: TObject);
    procedure CBTransparentChange(Sender: TObject);
    procedure CBSmoothChange(Sender: TObject);
    procedure RBDefaultChange(Sender: TObject);
    procedure RBOtherChange(Sender: TObject);
    procedure RBBothChange(Sender: TObject);
    procedure UDLeftChange(Sender: TObject);
    procedure UDTopChange(Sender: TObject);
    procedure UDWidthChange(Sender: TObject);
    procedure UDHeightChange(Sender: TObject);
    procedure CBUnitsChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
  private
    { Private declarations }
    LegendPalette : TLegendPaletteTool;

    IAxes  : TForm;
    IPanel : TForm;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Series.Surface, FMXTee.Series.PolarGrid,
  FMXTee.Canvas, FMXTee.Procs, FMXTee.Editor.Series, FMXTee.Editor.Panel,
  FMXTee.Editor.Axis;

procedure TLegendPaletteEditor.UDHeightChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
     LegendPalette.Height:=Round(UDHeight.Value);
end;

procedure TLegendPaletteEditor.UDLeftChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
     LegendPalette.Left:=Round(UDLeft.Value);
end;

procedure TLegendPaletteEditor.UDTopChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
     LegendPalette.Top:=Round(UDTop.Value);
end;

procedure TLegendPaletteEditor.UDWidthChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
     LegendPalette.Width:=Round(UDWidth.Value);
end;

procedure TLegendPaletteEditor.FormActivate(Sender: TObject);
begin
  inherited;

  if not Assigned(LegendPalette) then
  begin
    LegendPalette:=TLegendPaletteTool(TagObject);

    if Assigned(LegendPalette) then
    With LegendPalette do
    begin
      FillSeries(CBSeries,TCustom3DPaletteSeries,Series);
      FillSeries(CBSeries,TPolarGridSeries,Series,False);

      RBDefault.IsChecked:=Axis=laDefault;
      RBOther.IsChecked:=Axis=laOther;
      RBBoth.IsChecked:=Axis=laBoth;

      CBSmooth.IsChecked:=Smooth;
      CBVertical.IsChecked:=Vertical;
      CBTransparent.IsChecked:=Chart.Color=clNone;
      CBInverted.IsChecked:=Inverted;

      if PositionUnits=muPercent then CBUnits.ItemIndex:=0
                                 else CBUnits.ItemIndex:=1;

      UDLeft.Value:=Left;
      UDTop.Value:=Top;
      UDWidth.Value:=Width;
      UDHeight.Value:=Height;
    end;
  end;
end;

procedure TLegendPaletteEditor.RBOtherChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
     LegendPalette.Axis:=laOther;
end;

procedure TLegendPaletteEditor.TabControl1Change(Sender: TObject);
begin
  if TabControl1.TabIndex=2 then  //TabPanel
  begin
    if not Assigned(IPanel) then
    begin
      IPanel:=TPanelEditor.CreateEditor(Self, LegendPalette.Chart);
      IPanel.Name:=TeeGetUniqueName(Self,'PanelEditor');
      EmbeddForm(IPanel, TabPanel);
    end;
  end
  else
  if TabControl1.TabIndex=3 then  //TabAxes
  begin
    if not Assigned(IAxes) then
    begin
      IAxes:=TAxisEditor.CreateEditor(Self, LegendPalette.Chart.Axes);
      IAxes.Name:=TeeGetUniqueName(Self,'AxisEditor');
      EmbeddForm(IAxes, TabAxes);
    end;
  end;
end;

procedure TLegendPaletteEditor.BBorderClick(Sender: TObject);
begin
  if Assigned(LegendPalette) then
    TStrokeEditor.Edit(Self, LegendPalette.Border);
end;

procedure TLegendPaletteEditor.RBBothChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
     LegendPalette.Axis:=laBoth;
end;

procedure TLegendPaletteEditor.BPenClick(Sender: TObject);
begin
  if Assigned(LegendPalette) then
    TStrokeEditor.Edit(Self, LegendPalette.Pen);
end;

procedure TLegendPaletteEditor.CBInvertedChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
    LegendPalette.Inverted:=CBInverted.IsChecked;
end;

procedure TLegendPaletteEditor.CBSmoothChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
    LegendPalette.Smooth:=CBSmooth.IsChecked;
end;

procedure TLegendPaletteEditor.CBTransparentChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
    LegendPalette.Transparent:=CBTransparent.IsChecked;
end;

procedure TLegendPaletteEditor.CBUnitsChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
    if CBUnits.ItemIndex=0 then
    begin
      LegendPalette.PositionUnits:=muPercent;

      if UDLeft.Value>100 then UDLeft.Value:=100;
      if UDTop.Value>100 then UDTop.Value:=100;
    end
    else
      LegendPalette.PositionUnits:=muPixels;
end;

procedure TLegendPaletteEditor.CBVerticalChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
    LegendPalette.Vertical:=CBVertical.IsChecked;
end;

procedure TLegendPaletteEditor.RBDefaultChange(Sender: TObject);
begin
  if Assigned(LegendPalette) then
     LegendPalette.Axis:=laDefault;
end;

initialization
  RegisterSeriesEditor(TLegendPaletteEditor);
end.
