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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Colors, FMX.TabControl,
  FMX.StdCtrls,
  FMX.ListBox, FMXTee.Series.ErrorPoint, FMXTee.Editor.Stroke, FMX.Layouts,
  FMXTee.Canvas, FMXTee.Series.Error, FMXTee.Editor.Series.Pointer,
  FMXTee.Constants, FMXTee.Procs;

type
  TErrorPoint3DSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    CBColorEach: TCheckBox;
    Label1: TLabel;
    UDBarWidth: TTrackBar;
    LErrorWidth: TLabel;
    Label3: TLabel;
    CBWidthUnits: TComboBox;
    percent: TListBoxItem;
    pixels: TListBoxItem;
    TabBorder: TTabItem;
    LBBorders: TListBox;
    LBLeft: TListBoxItem;
    LBTop: TListBoxItem;
    LBRight: TListBoxItem;
    LBBottom: TListBoxItem;
    TabPointer: TTabItem;
    LBFront: TListBoxItem;
    LBBack: TListBoxItem;
    procedure FormActivate(Sender: TObject);
    procedure CBWidthUnitsChange(Sender: TObject);
    procedure UDBarWidthChange(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure LBBordersClick(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
  private
    { Private declarations }
    ErrorPoint3DSeries : TCustomErrorPoint3DSeries;
    FPointForm : TCustomForm;
    IPenEditor : TStrokeEditor;
  public
    { Public declarations }
  end;

var
  ErrorPoint3DSeriesEditor: TErrorPoint3DSeriesEditor;

implementation

{$R *.fmx}

procedure TErrorPoint3DSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  ErrorPoint3DSeries.ColorEachPoint:=CBColorEach.IsChecked;
end;

procedure TErrorPoint3DSeriesEditor.CBWidthUnitsChange(Sender: TObject);
begin
  ErrorPoint3DSeries.Errors.SizeUnits:=TErrorWidthUnits(CBWidthUnits.ItemIndex);
end;

procedure TErrorPoint3DSeriesEditor.FormActivate(Sender: TObject);
begin
  ErrorPoint3DSeries:=TCustomErrorPoint3DSeries(TagObject);

  if Assigned(ErrorPoint3DSeries) then
  With ErrorPoint3DSeries do
  begin
    UDBarWidth.Value:=Errors.Size;

    if Errors.SizeUnits=ewuPercent then CBWidthUnits.ItemIndex:=0
                                  else CBWidthUnits.ItemIndex:=1;

    CBColorEach.IsChecked:=ColorEachPoint;

    if not Assigned(FPointForm) then
       FPointForm:=TSeriesPointerEditor.InsertForm(Pointer,TabPointer);
  end;
end;

procedure TErrorPoint3DSeriesEditor.FormCreate(Sender: TObject);
begin
  LBBorders.ItemIndex:=0;
end;

procedure TErrorPoint3DSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FPointForm);
end;

procedure TErrorPoint3DSeriesEditor.LBBordersClick(Sender: TObject);
var tmp : TTeePen;
begin
  if Assigned(IPenEditor) then
  begin
    with ErrorPoint3DSeries.Errors.Format do
    case LBBorders.ItemIndex of
      0: tmp:=Left;
      1: tmp:=Top;
      2: tmp:=Right;
      3: tmp:=Bottom;
      4: tmp:=Front;
    else
      tmp:=Back;
    end;

    IPenEditor.RefreshPen(tmp);
  end;
end;

procedure TErrorPoint3DSeriesEditor.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabBorder) and (not assigned(IPenEditor)) then
  begin
    IPenEditor:=TStrokeEditor.InsertForm(ErrorPoint3DSeries.Errors.Format.Left,TabBorder);
    LBBordersClick(Self);
  end;
end;

procedure TErrorPoint3DSeriesEditor.UDBarWidthChange(Sender: TObject);
begin
   ErrorPoint3DSeries.Errors.Size:=round(UDBarWidth.Value);
end;

initialization
  RegisterClass(TErrorPoint3DSeriesEditor);
end.
