unit FMXTee.Editor.Tools.ColorBand;

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
  TColorBandToolEditor = class(TAxisToolEditor)
    BBrush: TButton;
    TabControl1: TTabControl;
    TabValues: TTabItem;
    TabOptions: TTabItem;
    TabPicture: TTabItem;
    BEnd: TButton;
    CBEnd: TCheckBox;
    CBEndActive: TCheckBox;
    EEnd: TEdit;
    Label4: TLabel;
    UDTrans: TSpinBox;
    Label8: TLabel;
    Label3: TLabel;
    CBStartActive: TCheckBox;
    EStart: TEdit;
    CBStart: TCheckBox;
    BStart: TButton;
    CBDrawBehind: TCheckBox;
    CBCursor: TComboBox;
    CBBeforeAxes: TCheckBox;
    Label2: TLabel;
    CBColor: TComboColorBox;
    BGradient: TButton;
    procedure FormActivate(Sender: TObject);
    procedure CBCursorChange(Sender: TObject);
    procedure BBrushClick(Sender: TObject);
    procedure BStartClick(Sender: TObject);
    procedure BEndClick(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
    procedure EStartChange(Sender: TObject);
    procedure EEndChange(Sender: TObject);
    procedure CBStartActiveChange(Sender: TObject);
    procedure CBEndActiveChange(Sender: TObject);
    procedure CBStartChange(Sender: TObject);
    procedure CBEndChange(Sender: TObject);
    procedure CBDrawBehindChange(Sender: TObject);
    procedure CBBeforeAxesChange(Sender: TObject);
    procedure UDTransChange(Sender: TObject);
  private
    { Private declarations }
    ColorBand : TColorBandTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  System.UIConsts, FMXTee.Editor.Brush, FMXTee.Editor.Stroke,
  FMXTee.Editor.Gradient, FMXTee.Editor.Series, FMXTee.Editor.Picture;

const
  TeeCursorPrefix='cr';

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

  if not Assigned(ColorBand) then
  begin
    ColorBand:=TColorBandTool(TagObject);

    if Assigned(ColorBand) then
    With ColorBand do
    begin
      EStart.Text:=FloatToStr(StartValue);
      EEnd.Text:=FloatToStr(EndValue);
      UDTrans.Value:=Transparency;
      CBDrawBehind.IsChecked:=DrawBehind;
      CBBeforeAxes.IsChecked:=DrawBehindAxes;
      CBStart.IsChecked:=ResizeStart;
      CBEnd.IsChecked:=ResizeEnd;

      CBStartActive.IsChecked:=StartLine.Active;
      CBEndActive.IsChecked:=EndLine.Active;

      TeeFillCursors(CBCursor,Cursor);

      CBColor.Color:=ColorBand.Color;

      //TBackImageEditor.CreateEmbedd(Self,Picture,TabPicture);
    end;
  end;
end;

procedure TColorBandToolEditor.UDTransChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
    ColorBand.Transparency:=Round(UDTrans.Value);
end;

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

procedure TColorBandToolEditor.BEndClick(Sender: TObject);
begin
  if Assigned(ColorBand) then
    TStrokeEditor.Edit(Self,ColorBand.EndLinePen);
end;

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

procedure TColorBandToolEditor.BStartClick(Sender: TObject);
begin
  if Assigned(ColorBand) then
    TStrokeEditor.Edit(Self,ColorBand.StartLinePen)
end;

procedure TColorBandToolEditor.CBBeforeAxesChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
    ColorBand.DrawBehindAxes:=CBBeforeAxes.IsChecked;
end;

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

procedure TColorBandToolEditor.CBCursorChange(Sender: TObject);
  var tmp : Integer;
begin
  if Assigned(ColorBand) then
  with TColorBandTool(ColorBand) do
    if IdentToCursor(TeeCursorPrefix+CBCursor.Selected.Text,tmp) then
      Cursor:=tmp;
end;

procedure TColorBandToolEditor.CBDrawBehindChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
    ColorBand.DrawBehind:=CBDrawBehind.IsChecked;
end;

procedure TColorBandToolEditor.CBEndActiveChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
  begin
    ColorBand.EndLine.Active:=CBEndActive.IsChecked;
    ColorBand.Repaint;
  end;
end;

procedure TColorBandToolEditor.CBEndChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
    ColorBand.ResizeEnd:=CBEnd.IsChecked;
end;

procedure TColorBandToolEditor.CBStartActiveChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
  begin
    ColorBand.StartLine.Active:=CBStartActive.IsChecked;
    ColorBand.Repaint;
  end;
end;

procedure TColorBandToolEditor.CBStartChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
    ColorBand.ResizeStart:=CBStart.IsChecked;
end;

procedure TColorBandToolEditor.EEndChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
    ColorBand.EndValue:=StrToFloatDef(EEnd.Text,ColorBand.EndValue);
end;

procedure TColorBandToolEditor.EStartChange(Sender: TObject);
begin
  if Assigned(ColorBand) then
    ColorBand.StartValue:=StrToFloatDef(EStart.Text,ColorBand.StartValue);
end;

initialization
  RegisterSeriesEditor(TColorBandToolEditor);
end.
