{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Series.Area;
{$I TeeDefs.inc}

interface

uses
  SysUtils, Types, Classes, Variants, FMX.Types, FMX.Controls, FMX.Forms,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMX.Edit, FMX.ListBox, FMX.Dialogs, FMX.TabControl, FMXTee.Series,
  FMXTee.RadioGroup, FMX.Colors, FMXTee.Editor.Brush, FMXTee.Editor.Stroke,
  FMXTee.Editor.Series.Pointer;

type
  TAreaSeriesEditor = class(TForm)
    PageControl1: TTabControl;
    TabSheet1: TTabItem;
    GroupBox2: TGroupBox;
    CBStairs: TCheckBox;
    CBInvStairs: TCheckBox;
    CBSmoothed: TCheckBox;
    GroupBox5: TGroupBox;
    GroupBox1: TGroupBox;
    CBColorEach: TCheckBox;
    GroupBox4: TGroupBox;
    CBNulls: TComboBox;
    TabSheet2: TTabItem;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    CBUseOrigin: TCheckBox;
    UDOrigin: TSpinBox;
    GroupBox6: TGroupBox;
    UDGroup: TSpinBox;
    RGMultiArea: TRadioGroup;
    TabBorder: TTabItem;
    TabPattern: TTabItem;
    TabAreaLines: TTabItem;
    TabAreaTop: TTabItem;
    CBDefColor: TCheckBox;
    BAreaColor: TComboColorBox;
    CBDark3D: TCheckBox;
    TBTransp: TTrackBar;
    GroupBox7: TGroupBox;
    CBDrawStyle: TComboBox;
    TabPointer: TTabItem;
    procedure CBNullsChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure CBDark3DChange(Sender: TObject);
    procedure CBSmoothedChange(Sender: TObject);
    procedure CBInvStairsChange(Sender: TObject);
    procedure CBStairsChange(Sender: TObject);
    procedure CBUseOriginChange(Sender: TObject);
    procedure UDOriginChange(Sender: TObject);
    procedure UDGroupChange(Sender: TObject);
    procedure RGMultiAreaChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBDefColorChange(Sender: TObject);
    procedure BAreaColorChange(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure CBDrawStyleChange(Sender: TObject);
  private
   { Private declarations }
    Area : TAreaSeries;

    IBorder : TStrokeEditor;
    ILines  : TStrokeEditor;
    IBrush  : TBrushEditor;
    ITop    : TBrushEditor;
    IPointer : TSeriesPointerEditor;

    procedure RefreshArea(const AArea:TAreaSeries);
    procedure RefreshShape;
  public
   { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Procs, FMXTee.Canvas, FMXTee.Engine;

procedure TAreaSeriesEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Area) then
     RefreshArea(TAreaSeries(TagObject));
end;

procedure TAreaSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActiveTab=TabBorder) and (not Assigned(IBorder)) then
     IBorder:=TStrokeEditor.InsertForm(Area.LinePen,TabBorder)
  else
  if (PageControl1.ActiveTab=TabAreaLines) and (not Assigned(ILines)) then
     ILines:=TStrokeEditor.InsertForm(Area.AreaLinesPen,TabAreaLines)
  else
  if (PageControl1.ActiveTab=TabPattern) and (not Assigned(IBrush)) then
     IBrush:=TBrushEditor.InsertForm(Area.AreaChartBrush,TabPattern)
  else
  if (PageControl1.ActiveTab=TabAreaTop) and (not Assigned(ITop)) then
     ITop:=TBrushEditor.InsertForm(Area.Brush,TabAreaTop)
  else
  if (PageControl1.ActiveTab=TabPointer) and (not Assigned(IPointer)) then
     IPointer:=TSeriesPointerEditor.InsertForm(Area.Pointer,TabPointer);
end;

procedure TAreaSeriesEditor.CBStairsChange(Sender: TObject);
begin
  Area.Stairs:=CBStairs.IsChecked;
end;

procedure TAreaSeriesEditor.CBInvStairsChange(Sender: TObject);
begin
  Area.InvertedStairs:=CBInvStairs.IsChecked;
end;

procedure TAreaSeriesEditor.CBSmoothedChange(Sender: TObject);
begin
  {$IFNDEF TEELITEEMB}
  Area.Smoothed:=CBSmoothed.IsChecked;
  {$ENDIF}
end;

procedure TAreaSeriesEditor.CBDark3DChange(Sender: TObject);
begin
  Area.Dark3D:=CBDark3D.IsChecked;
end;

procedure TAreaSeriesEditor.RefreshShape;
begin
  BAreaColor.Enabled:=not Area.ColorEachPoint;
end;

procedure TAreaSeriesEditor.CBDefColorChange(Sender: TObject);
begin
  if CBDefColor.IsChecked then
  begin
    Area.ResetBrush;
    RefreshShape;
    CBDefColor.Enabled:=False;
  end;
end;

procedure TAreaSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  Area.ColorEachPoint:=CBColorEach.IsChecked;
end;

procedure TAreaSeriesEditor.CBNullsChange(Sender: TObject);
begin
  Area.TreatNulls:=TTreatNullsStyle(CBNulls.ItemIndex);
end;

procedure TAreaSeriesEditor.RefreshArea(const AArea: TAreaSeries);
begin
  Area:=AArea;

  CBStairs.IsChecked:=Area.Stairs;
  CBInvStairs.IsChecked:=Area.InvertedStairs;

  {$IFDEF TEELITEEMB}
  CBSmoothed.Visible:=False;
  {$ELSE}
  CBSmoothed.IsChecked:=Area.Smoothed;
  {$ENDIF}

  CBDark3D.IsChecked:=Area.Dark3D;
  CBColorEach.IsChecked:=Area.ColorEachPoint;
  CBUseOrigin.IsChecked:=Area.UseYOrigin;
  CBNulls.ItemIndex:=Ord(Area.TreatNulls);

  TBTransp.Value:=Area.Transparency;
  UDGroup.Value:=Area.StackGroup;
  UDOrigin.Value:=Area.YOrigin;

  CBDrawStyle.ItemIndex:=Ord(Area.DrawStyle);

  RGMultiArea.ItemIndex:=Ord(Area.MultiArea);

  BAreaColor.Color:=Area.SeriesColor;
  BAreaColorChange(Self);
end;

procedure TAreaSeriesEditor.RGMultiAreaChange(Sender: TObject);
begin
  Area.MultiArea:=TMultiArea(RGMultiArea.ItemIndex);
end;

procedure TAreaSeriesEditor.TBTranspChange(Sender: TObject);
begin
  Area.Transparency:=Round(TBTransp.Value);
end;

procedure TAreaSeriesEditor.UDGroupChange(Sender: TObject);
begin
  Area.StackGroup:=Round(UDGroup.Value);
end;

procedure TAreaSeriesEditor.UDOriginChange(Sender: TObject);
begin
  Area.YOrigin:=UDOrigin.Value;
end;

procedure TAreaSeriesEditor.CBUseOriginChange(Sender: TObject);
begin
  Area.UseYOrigin:=CBUseOrigin.IsChecked;
end;

procedure TAreaSeriesEditor.CBDrawStyleChange(Sender: TObject);
begin
  case CBDrawStyle.ItemIndex of
    0: Area.DrawStyle:=dsSegments;
    1: Area.DrawStyle:=dsAll;
  else
    Area.DrawStyle:=dsCurve;
  end;
end;

type
  TSeriesAccess=class(TChartSeries);

procedure TAreaSeriesEditor.BAreaColorChange(Sender: TObject);
begin
  Area.Color:=BAreaColor.Color;

  CBDefColor.IsChecked:=not TSeriesAccess(Area).IsColorStored;
  CBDefColor.Enabled:=not CBDefColor.IsChecked;
end;

initialization
  RegisterSeriesEditor(TAreaSeriesEditor);
end.
