unit FMXTee.Editor.Series.ErrorPoint;

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.ListBox, FMXTee.Series.ErrorPoint, FMXTee.Editor.Stroke, FMX.Layouts,
  FMXTee.Canvas, FMXTee.Series.Error, FMXTee.Editor.Series.Pointer,
  FMXTee.Constants, FMXTee.Procs;

type
  TErrorPointSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    CBColorEach: TCheckBox;
    Label1: TLabel;
    UDBarWidth: TTrackBar;
    LErrorWidth: TLabel;
    Label3: TLabel;
    TabBorder: TTabItem;
    CBWidthUnits: TComboBox;
    percent: TListBoxItem;
    pixels: TListBoxItem;
    LBBorders: TListBox;
    LBLeft: TListBoxItem;
    LBTop: TListBoxItem;
    LBRight: TListBoxItem;
    LBBottom: TListBoxItem;
    TabPointer: TTabItem;
    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 }
    ErrorPointSeries : TCustomErrorPointSeries;
    FPointForm : TCustomForm;
    IPenEditor : TStrokeEditor;
  public
    { Public declarations }
  end;

var
  ErrorPointSeriesEditor: TErrorPointSeriesEditor;

implementation

{$R *.fmx}

procedure TErrorPointSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  ErrorPointSeries.ColorEachPoint:=CBColorEach.IsChecked;
end;

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

procedure TErrorPointSeriesEditor.FormActivate(Sender: TObject);
begin
  ErrorPointSeries:=TCustomErrorPointSeries(TagObject);

  if Assigned(ErrorPointSeries) then
  With ErrorPointSeries 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 TErrorPointSeriesEditor.FormCreate(Sender: TObject);
begin
  LBBorders.ItemIndex:=0;
end;

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

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

    IPenEditor.RefreshPen(tmp);
  end;
end;

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

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

initialization
  RegisterClass(TErrorPointSeriesEditor);
end.
