unit FMXTee.Editor.Tools.SeriesRegion;

interface

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

type
  TSeriesRegionEditor = class(TSeriesToolEditor)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabFormat: TTabItem;
    BPen: TButton;
    GroupBox1: TGroupBox;
    CBUseOrigin: TCheckBox;
    EOrigin: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    UDTransp: TSpinBox;
    GroupBox2: TGroupBox;
    CBAutoBounds: TCheckBox;
    ELower: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    EUpper: TEdit;
    CBBehind: TCheckBox;
    CBColor: TComboColorBox;
    BBrush: TButton;
    Label4: TLabel;
    BGradient: TButton;
    procedure FormActivate(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure UDTranspChange(Sender: TObject);
    procedure EOriginChange(Sender: TObject);
    procedure CBUseOriginChange(Sender: TObject);
    procedure CBAutoBoundsChange(Sender: TObject);
    procedure ELowerChange(Sender: TObject);
    procedure EUpperChange(Sender: TObject);
    procedure CBBehindChange(Sender: TObject);
    procedure BBrushClick(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
  private
    { Private declarations }
    SeriesRegion : TSeriesRegionTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Editor.Brush, FMXTee.Editor.Gradient;

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

  if not Assigned(SeriesRegion) then
  begin
    SeriesRegion:=TSeriesRegionTool(TagObject);

    if Assigned(SeriesRegion) then
    With SeriesRegion do
    begin
      EOrigin.Text:=FloatToStr(Origin);
      CBUseOrigin.IsChecked:=UseOrigin;
      CBBehind.IsChecked:=DrawBehindSeries;
      CBAutoBounds.IsChecked:=AutoBounds;
      UDTransp.Value:=Transparency;
      CBColor.Color:=Color;

      ELower.Text := FloatToStr(LowerBound);
      EUpper.Text := FloatToStr(UpperBound);

      ELower.Enabled:=not CBAutoBounds.IsChecked;
      EUpper.Enabled:=not CBAutoBounds.IsChecked;
    end;
  end;
end;

procedure TSeriesRegionEditor.BBrushClick(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
     TBrushEditor.Edit(Self, SeriesRegion.Brush);
end;

procedure TSeriesRegionEditor.BGradientClick(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
    TGradientEditor.Edit(Self, SeriesRegion.Gradient);
end;

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

procedure TSeriesRegionEditor.CBAutoBoundsChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
  begin
     SeriesRegion.AutoBounds:=CBUseOrigin.IsChecked;
     ELower.Enabled:=not CBAutoBounds.IsChecked;
     EUpper.Enabled:=not CBAutoBounds.IsChecked;
  end;
end;

procedure TSeriesRegionEditor.CBBehindChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
     SeriesRegion.DrawBehindSeries:=CBBehind.IsChecked;
end;

procedure TSeriesRegionEditor.CBColorChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
    SeriesRegion.Color:=CBColor.Color;
end;

procedure TSeriesRegionEditor.CBUseOriginChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
     SeriesRegion.UseOrigin:=CBUseOrigin.IsChecked;
end;

procedure TSeriesRegionEditor.ELowerChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
    SeriesRegion.LowerBound:=StrToFloatDef(ELower.Text,SeriesRegion.LowerBound);
end;

procedure TSeriesRegionEditor.EOriginChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
    SeriesRegion.Origin:=StrToFloatDef(EOrigin.Text,SeriesRegion.Origin);
end;

procedure TSeriesRegionEditor.EUpperChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
    SeriesRegion.UpperBound:=StrToFloatDef(EUpper.Text,SeriesRegion.UpperBound);
end;

procedure TSeriesRegionEditor.UDTranspChange(Sender: TObject);
begin
  if Assigned(SeriesRegion) then
     SeriesRegion.Transparency:=Round(UDTransp.Value);
end;

initialization
  RegisterSeriesEditor(TSeriesRegionEditor);
end.
