unit FMXTee.Editor.Tools.GridBand;

interface

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

type
  TGridBandToolEdit = class(TAxisToolEditor)
    TabControl1: TTabControl;
    BGradient: TButton;
    CBColor: TComboColorBox;
    BBand: TButton;
    Label8: TLabel;
    UDTrans: TSpinBox;
    Label2: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure BBandClick(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
    procedure UDTransChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
  private
    { Private declarations }
    GridBand : TGridBandTool;

    function Band:TGridBandBrush;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

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

function TGridBandToolEdit.Band:TGridBandBrush;
begin
  if TabControl1.TabIndex=0 then result:=GridBand.Band1
                            else result:=GridBand.Band2;
end;

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

  if not Assigned(GridBand) then
  begin
    GridBand:=TGridBandTool(TagObject);

    TabControl1.TabIndex:=0;
    TabControl1Change(Self);
  end;
end;

procedure TGridBandToolEdit.FormCreate(Sender: TObject);
var
  TabItemBand1, TabItemBand2: TTabItem;
begin
  inherited;
  BPen.Visible:=False;
  TabItemBand1:=TTabItem.Create(Self);
  TabItemBand1.Text:='Band 1';
  TabItemBand2:=TTabItem.Create(Self);
  TabItemBand2.Text:='Band 2';
  TabControl1.AddObject(TabItemBand1);
  TabControl1.AddObject(TabItemBand2);

  TabControl1.Align:=TAlignLayout.alClient;
end;

procedure TGridBandToolEdit.TabControl1Change(Sender: TObject);
begin
  if Assigned(GridBand) then
    UDTrans.Value:=Band.Transparency;
end;

procedure TGridBandToolEdit.UDTransChange(Sender: TObject);
begin
  if Assigned(GridBand) then
    Band.Transparency:=Round(UDTrans.Value);
end;

procedure TGridBandToolEdit.BBandClick(Sender: TObject);
begin
  if Assigned(GridBand) then
    TBrushEditor.Edit(Self,Band);
end;

procedure TGridBandToolEdit.BGradientClick(Sender: TObject);
begin
  if Assigned(GridBand) then
    TGradientEditor.Edit(Self, Band.Gradient);
end;

procedure TGridBandToolEdit.CBColorChange(Sender: TObject);
begin
  if Assigned(GridBand) then
    Band.Color:=CBColor.Color;
end;

initialization
  RegisterSeriesEditor(TGridBandToolEdit);
end.
