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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, FMX.Colors, FMX.TabControl,
  FMXTee.Editor.Stroke, FMXTee.Editor.Brush, FMXTee.Series.Pyramid;

type
  TPyramidSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabBorder: TTabItem;
    TabPattern: TTabItem;
    CBColor: TComboColorBox;
    CBDefColor: TCheckBox;
    CBColorEach: TCheckBox;
    Label1: TLabel;
    TBSize: TTrackBar;
    LSize: TLabel;
    Label2: TLabel;
    TBTransp: TTrackBar;
    LTransp: TLabel;
    procedure TabControl1Change(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure TBSizeChange(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure CBDefColorChange(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
  private
    { Private declarations }
    FBorder : TStrokeEditor;
    FBrush : TBrushEditor;

    Pyramid : TPyramidSeries;

    procedure CheckDefColor;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Engine;

procedure TPyramidSeriesEditor.CBColorChange(Sender: TObject);
begin
  Pyramid.Color:=CBColor.Color;
  CheckDefColor;
end;

procedure TPyramidSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  Pyramid.ColorEachPoint:=CBColorEach.IsChecked;
end;

type
  TSeriesAccess=class(TChartSeries);

procedure TPyramidSeriesEditor.CheckDefColor;
begin
  CBDefColor.IsChecked:=Pyramid.Color=clTeeColor;
  CBDefColor.Enabled:=not CBDefColor.IsChecked;
end;

procedure TPyramidSeriesEditor.CBDefColorChange(Sender: TObject);
begin
  if CBDefColor.IsChecked then
  begin
    TSeriesAccess(Pyramid).SetDefaultColor;
    CBDefColor.Enabled:=False;
  end;
end;

procedure TPyramidSeriesEditor.FormActivate(Sender: TObject);
begin
  Pyramid:=TPyramidSeries(TagObject);

  if Assigned(Pyramid) then
  begin
    CBColor.Color:=Pyramid.Color;
    CheckDefColor;

    CBColorEach.IsChecked:=Pyramid.ColorEachPoint;

    TBSize.Value:=Pyramid.SizePercent;
    LSize.Text:=IntToStr(Pyramid.SizePercent);

    TBTransp.Value:=Pyramid.Transparency;
    LTransp.Text:=IntToStr(Pyramid.Transparency);
  end;
end;

procedure TPyramidSeriesEditor.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabBorder) and (not Assigned(FBorder)) then
     FBorder:=TStrokeEditor.InsertForm(Pyramid.Pen,TabBorder)
  else
  if (TabControl1.ActiveTab=TabPattern) and (not Assigned(FBrush)) then
     FBrush:=TBrushEditor.InsertForm(Pyramid.Brush,TabPattern);
end;

procedure TPyramidSeriesEditor.TBSizeChange(Sender: TObject);
begin
  Pyramid.SizePercent:=Round(TBSize.Value);
  LSize.Text:=IntToStr(Pyramid.SizePercent);
end;

procedure TPyramidSeriesEditor.TBTranspChange(Sender: TObject);
begin
  Pyramid.Transparency:=Round(TBTransp.Value);
  LTransp.Text:=IntToStr(Pyramid.Transparency);
end;

initialization
  RegisterClass(TPyramidSeriesEditor);
end.
