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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.TabControl,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.ComboTrackBar,
  {$ENDIF}
  FMXTee.RadioGroup, FMX.Layouts, FMX.Memo, FMX.Edit, FMX.Colors, FMX.ListBox,
  FMXTee.Procs, FMXTee.Engine, FMXTee.Editor.Font, FMXTee.Series.Shape;

type
  TChartShapeEditor = class(TForm)
    CBStyle: TComboBox;
    BShapeColor: TComboColorBox;
    Button2: TButton;
    Button3: TButton;
    CBUnits: TComboBox;
    MemoText: TMemo;
    CBRound: TCheckBox;
    CBTrans: TCheckBox;
    UDTransp: TComboTrackBar;
    SEX1: TComboTrackBar;
    SEX0: TComboTrackBar;
    SEY0: TComboTrackBar;
    SEY1: TComboTrackBar;
    RGAlign: TRadioGroup;
    RGVertAlign: TRadioGroup;
    TabFont: TTabItem;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CBUnitsChange(Sender: TObject);
    procedure CBRoundChange(Sender: TObject);
    procedure RGVertAlignChange(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBTransChange(Sender: TObject);
    procedure RGAlignChange(Sender: TObject);
    procedure MemoTextChangeTracking(Sender: TObject);
    procedure BShapeBrushClick(Sender: TObject);
    procedure BShapeColorChange(Sender: TObject);
  private
    { Private declarations }
    CreatingForm : Boolean;
    FEditFont    : TFontEditor;
    TheSeries    : TChartShape;
    procedure EnableRound;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Brush, FMXTee.Editor.Strings;


procedure TChartShapeEditor.BShapeBrushClick(Sender: TObject);
begin
  TBrushEditor.Edit(Self,TheSeries.Brush);
  BShapeColor.Color:=TheSeries.SeriesColor;
end;

procedure TChartShapeEditor.BShapeColorChange(Sender: TObject);
begin
  TheSeries.SeriesColor:=BShapeColor.Color;
end;

procedure TChartShapeEditor.Button1Click(Sender: TObject);
begin
  TStringsEditor.Edit(Self,MemoText.Lines);
end;

procedure TChartShapeEditor.CBRoundChange(Sender: TObject);
begin
  TheSeries.RoundRectangle:=CBRound.IsChecked
end;

procedure TChartShapeEditor.CBStyleChange(Sender: TObject);
begin
  TheSeries.Style:=TChartShapeStyle(CBStyle.ItemIndex);
  EnableRound;
  CBRound.Enabled:=TheSeries.Style=chasRectangle;
end;

procedure TChartShapeEditor.CBTransChange(Sender: TObject);
begin
  TheSeries.Transparent:=CBTrans.IsChecked;
end;

procedure TChartShapeEditor.CBUnitsChange(Sender: TObject);
begin
  TheSeries.XYStyle:=TChartShapeXYStyle(CBUnits.ItemIndex);
end;

procedure TChartShapeEditor.Edit1Change(Sender: TObject);
begin
  TheSeries.Transparency:=Round(UDTransp.Value);
end;

procedure TChartShapeEditor.EnableRound;
begin
  with TheSeries do
       CBRound.Enabled:=(Style=chasRectangle) and
       (Assigned(ParentChart) and (not ParentChart.View3D));
end;

procedure TChartShapeEditor.FormActivate(Sender: TObject);
begin
  TheSeries:=TChartShape(TagObject);

  if Assigned(TheSeries) then
  begin
    With TheSeries do
    begin
      CBStyle.ItemIndex:=Ord(Style);

      CBTrans.IsChecked:=Transparent;

      if TheSeries.Count=2 then
      begin
        SEX0.Text:=FloatToStr(X0);
        SEY0.Text:=FloatToStr(Y0);
        SEX1.Text:=FloatToStr(X1);
        SEY1.Text:=FloatToStr(Y1);
      end;

      MemoText.Font:=Font;
      MemoText.Lines:=Text;

      Case Alignment of
        taLeftJustify:  RGAlign.ItemIndex:=0;
        taCenter:       RGAlign.ItemIndex:=1;
        taRightJustify: RGAlign.ItemIndex:=2;
      end;

      Case VertAlign of
        vaTop:    RGVertAlign.ItemIndex:=0;
        vaCenter: RGVertAlign.ItemIndex:=1;
        vaBottom: RGVertAlign.ItemIndex:=2;
      end;

      CBRound.IsChecked:=RoundRectangle;
      EnableRound;
      CBUnits.ItemIndex:=Ord(XYStyle);
      //BShapePen.LinkPen(Pen);
      FEditFont.RefreshFont(Font);

      //BGradient.Gradient:=Gradient;

      UDTransp.Value:=Transparency;

      BShapeColor.Color:=SeriesColor;
    end;
  end;

  CreatingForm:=False;
end;

procedure TChartShapeEditor.FormCreate(Sender: TObject);
begin
  CreatingForm:=True;
  FEditFont:=TFontEditor.Embedd(Self,nil,TabFont);
end;

procedure TChartShapeEditor.MemoTextChangeTracking(Sender: TObject);
begin
  if not CreatingForm then
     TheSeries.Text:=MemoText.Lines;
end;

procedure TChartShapeEditor.RGAlignChange(Sender: TObject);
begin
  Case RGAlign.ItemIndex of
    0: TheSeries.Alignment:=taLeftJustify;
    1: TheSeries.Alignment:=taCenter;
    2: TheSeries.Alignment:=taRightJustify;
  end;
end;

procedure TChartShapeEditor.RGVertAlignChange(Sender: TObject);
begin
  Case RGVertAlign.ItemIndex of
    0: TheSeries.VertAlign:=vaTop;
    1: TheSeries.VertAlign:=vaCenter;
    2: TheSeries.VertAlign:=vaBottom;
  end;
end;

initialization
  RegisterSeriesEditor(TChartShapeEditor);
end.
