{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Series.Vector;
{$I TeeDefs.inc}

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Edit,
  FMXTee.Chart, FMXTee.Series.Surface, FMXTee.Canvas, FMXTee.Editor.Stroke,
  {$IFDEF D17}
  FMX.StdCtrls,
  System.UIConsts,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMXTee.Procs, FMX.TabControl;

type
  TVectorSeriesEditor = class(TForm)
    UDWidth: TSpinBox;
    LHeight: TLabel;
    UDHeight: TSpinBox;
    Label1: TLabel;
    BStart: TButton;
    BEnd: TButton;
    CBStart: TCheckBox;
    CBEnd: TCheckBox;
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabGrid3D: TTabItem;
    procedure FormActivate(Sender: TObject);
    procedure BStartClick(Sender: TObject);
    procedure BEndClick(Sender: TObject);
    procedure UDWidthChange(Sender: TObject);
    procedure UDHeightChange(Sender: TObject);
    procedure CBStartChange(Sender: TObject);
    procedure CBEndChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    Vector : TVector3DSeries;
    Grid3DForm : TCustomForm;
  public
    { Public declarations }
  end;

var
  VectorSeriesEditor: TVectorSeriesEditor;

implementation

{$R *.fmx}

Uses FMXTee.Editor.Brush, FMXTee.Engine, FMXTee.Editor.Series.Grid;

procedure TVectorSeriesEditor.BEndClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Vector.EndArrow);
end;

procedure TVectorSeriesEditor.BStartClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Vector.StartArrow);
end;

procedure TVectorSeriesEditor.CBEndChange(Sender: TObject);
begin
  if CBEnd.IsChecked then Vector.EndArrow.Color:=clTeeColor
                   else Vector.EndArrow.Color:=claBlack;
end;

procedure TVectorSeriesEditor.CBStartChange(Sender: TObject);
begin
  if CBStart.IsChecked then Vector.StartArrow.Color:=clTeeColor
                     else Vector.StartArrow.Color:=claBlack;
end;

procedure TVectorSeriesEditor.FormActivate(Sender: TObject);
begin
  Vector:=TVector3DSeries(TagObject);

  if Assigned(Vector) then
  begin

    With Vector do
    begin
      UDHeight.Value:=ArrowHeight;
      UDWidth.Value:=ArrowWidth;
      CBStart.IsChecked:=StartArrow.Color=clTeeColor;
      CBEnd.IsChecked:=EndArrow.Color=clTeeColor;
    end;

    if not Assigned(Grid3DForm) then
       TGrid3DSeriesEditor.CreateEmbedd(Parent,Vector,TabGrid3D);
  end;
end;

procedure TVectorSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(Grid3DForm);
end;

procedure TVectorSeriesEditor.UDHeightChange(Sender: TObject);
begin
  if Assigned(Vector) then
     Vector.ArrowWidth:=Round(UDHeight.Value);
end;

procedure TVectorSeriesEditor.UDWidthChange(Sender: TObject);
begin
  if Assigned(Vector) then
     Vector.ArrowWidth:=Round(UDWidth.Value);
end;

initialization
  RegisterClass(TVectorSeriesEditor);
end.
