unit FMXTee.Editor.Series.HighLow;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMXTee.Series.Error, FMXTee.Canvas, FMXTee.Editor.Stroke, FMXTee.Procs,
  FMX.Edit, FMX.Colors, FMX.TabControl, FMXTee.Editor.Brush;

type
  THighLowSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabHigh: TTabItem;
    TabLow: TTabItem;
    TabLines: TTabItem;
    BColor: TComboColorBox;
    CBColorEach: TCheckBox;
    UDTransp: TSpinBox;
    Label1: TLabel;
    PageHigh: TTabControl;
    TabHighBorder: TTabItem;
    TabHighPattern: TTabItem;
    PageLow: TTabControl;
    TabLowBorder: TTabItem;
    TabLowPattern: TTabItem;
    procedure FormActivate(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure UDTranspChange(Sender: TObject);
    procedure PageLowChange(Sender: TObject);
    procedure PageHighChange(Sender: TObject);
  private
    { Private declarations }
    HighLow    : THighLowSeries;
    FHighPen   : TStrokeEditor;
    FHighBrush : TBrushEditor;
    FLowPen   : TStrokeEditor;
    FLowBrush : TBrushEditor;
    FPen   : TStrokeEditor;
  public
    { Public declarations }
  end;

var
  HighLowSeriesEditor: THighLowSeriesEditor;

implementation

{$R *.fmx}

procedure THighLowSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  HighLow.ColorEachPoint:=CBColorEach.IsChecked;
end;

procedure THighLowSeriesEditor.FormActivate(Sender: TObject);
begin
  HighLow:=THighLowSeries(TagObject);

  if Assigned(HighLow) then
  begin
    with HighLow do
    begin
      CBColorEach.IsChecked:=ColorEachPoint;
      UDTransp.Value:=Transparency;
    end;

    BColor.Color:= HighLow.SeriesColor; // Do not localize
  end;

end;

procedure THighLowSeriesEditor.PageHighChange(Sender: TObject);
begin
  if (PageHigh.ActiveTab=TabHighBorder) and (not assigned(FHighPen)) then
     FHighPen:=TStrokeEditor.InsertForm(HighLow.HighPen,TabHighBorder)
  else
  if (PageHigh.ActiveTab=TabHighPattern) and (not assigned(FHighBrush)) then
     FHighBrush:=TBrushEditor.InsertForm(HighLow.HighBrush,TabHighPattern);
end;

procedure THighLowSeriesEditor.PageLowChange(Sender: TObject);
begin
  if (PageLow.ActiveTab=TabLowBorder) and (not assigned(FLowPen)) then
     FLowPen:=TStrokeEditor.InsertForm(HighLow.LowPen,TabLowBorder)
  else
  if (PageLow.ActiveTab=TabLowPattern) and (not assigned(FLowBrush)) then
     FLowBrush:=TBrushEditor.InsertForm(HighLow.LowBrush,TabLowPattern);
end;

procedure THighLowSeriesEditor.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabLines) and (not assigned(FPen)) then
     FPen:=TStrokeEditor.InsertForm(HighLow.Pen,TabLines)
  else
  if TabControl1.Activetab=TabHigh then
     PageHighChange(Self)
  else
  if TabControl1.ActiveTab=TabLow then
     PageLowChange(Self);
end;

procedure THighLowSeriesEditor.UDTranspChange(Sender: TObject);
begin
    HighLow.Transparency:=Round(UDTransp.Value);
end;

initialization
  RegisterClass(THighLowSeriesEditor);
end.
