{********************************************}
{    TCircledSeries Editor Dialog            }
{ Copyright (c) 2000-2020 by Steema Software }
{********************************************}
unit TeeCircledEdit;
{$I TeeDefs.inc}

interface

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

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

     Chart, Series, TeEngine, TeeProcs, TeCanvas, TeePenDlg, TeeBrushDlg;

type
  TCircledSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabOptions: TTabSheet;
    TabRadius: TTabSheet;
    TabShadow: TTabSheet;
    Label1: TLabel;
    CBCircled: TCheckBox;
    CB3D: TCheckBox;
    GroupBox2: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Edit2: TEdit;
    CBAutoXR: TCheckBox;
    Edit3: TEdit;
    CBAutoYR: TCheckBox;
    UDY: TUpDown;
    UDX: TUpDown;
    TabEmboss: TTabSheet;
    TBRotation: TTrackBar;
    LRotation: TLabel;
    CBUniqueRadius: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure CBCircledClick(Sender: TObject);
    procedure SEXRadiusChange(Sender: TObject);
    procedure SEYRadiusChange(Sender: TObject);
    procedure CBAutoXRClick(Sender: TObject);
    procedure CBAutoYRClick(Sender: TObject);
    procedure CB3DClick(Sender: TObject);
    procedure TBRotationChange(Sender: TObject);
    procedure CBUniqueRadiusClick(Sender: TObject);
  private
    { Private declarations }
    Circled      : TCircledSeries;
    CreatingForm : Boolean;
  public
    { Public declarations }
    class function CreateForm(AForm:TCustomForm;
                              const Circled:TCircledSeries):TCircledSeriesEditor;
  end;

implementation

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

uses
  TeeConst, TeeEdiSeri, TeeShadowEditor;

procedure TCircledSeriesEditor.FormShow(Sender: TObject);
begin
  CreatingForm:=True;
  Circled:=TCircledSeries(Tag);

  if Assigned(Circled) then
  begin
    With Circled do
    begin
      CBCircled.Checked:=Circled;

      CB3D.Enabled:=ParentChart<>nil;

      if CB3D.Enabled then
         CB3D.Checked:=ParentChart.View3D;

      TBRotation.Position:=RotationAngle;

      UDX.Position     :=CustomXRadius;
      UDY.Position     :=CustomYRadius;

      CBAutoXR.Checked:=CustomXRadius=0;
      CBAutoYR.Checked:=CustomYRadius=0;

      CBUniqueRadius.Checked:=UniqueCustomRadius;
    end;

    TTeeShadowEditor.InsertForm(Circled.Shadow,TabShadow);
    TTeeShadowEditor.InsertForm(Circled.Emboss,TabEmboss);
  end;

  CreatingForm:=False;
end;

procedure TCircledSeriesEditor.CBCircledClick(Sender: TObject);
begin
  // Avoid setting Circled, as it'll set Custom radius to zero:
  if not CreatingForm then
     Circled.Circled:=CBCircled.Checked;
end;

procedure TCircledSeriesEditor.SEXRadiusChange(Sender: TObject);
begin
  if Showing then
  begin
    Circled.CustomXRadius:=UDX.Position;
    CBAutoXR.Checked:=UDX.Position=0;
  end;
end;

procedure TCircledSeriesEditor.SEYRadiusChange(Sender: TObject);
begin
  if Showing then
  begin
    Circled.CustomYRadius:=UDY.Position;
    CBAutoYR.Checked:=UDY.Position=0;
  end;
end;

procedure TCircledSeriesEditor.CBAutoXRClick(Sender: TObject);
begin
  if (not CreatingForm) and CBAutoXR.Checked then
     UDX.Position:=0;
end;

procedure TCircledSeriesEditor.CBAutoYRClick(Sender: TObject);
begin
  if (not CreatingForm) and CBAutoYR.Checked then
     UDY.Position:=0;
end;

procedure TCircledSeriesEditor.CB3DClick(Sender: TObject);
begin
  Circled.ParentChart.View3D:=CB3D.Checked
end;

class function TCircledSeriesEditor.CreateForm(AForm:TCustomForm;
                             const Circled:TCircledSeries):TCircledSeriesEditor;
begin
  result:=TCircledSeriesEditor(
              TFormTeeSeries.InsertSeriesForm(AForm.Parent,TCircledSeriesEditor,
                                              1,TeeMsg_GalleryCircled,Circled));
end;

procedure TCircledSeriesEditor.TBRotationChange(Sender: TObject);
begin
  if Showing then
  begin
    Circled.RotationAngle:=TBRotation.Position;
    LRotation.Caption:=IntToStr(TBRotation.Position);
  end;
end;

procedure TCircledSeriesEditor.CBUniqueRadiusClick(Sender: TObject);
begin
  if Showing then
     Circled.UniqueCustomRadius:=CBUniqueRadius.Checked;
end;

initialization
  RegisterClass(TCircledSeriesEditor);
end.
