{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Symbol;
{$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, FMXTee.Chart, FMX.TabControl,
  FMXTee.Editor.Gradient, FMXTee.Editor.Stroke, FMXTee.Editor.Shadow;

type
  TSymbolEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabBorder: TTabItem;
    TabGradient: TTabItem;
    TabShadow: TTabItem;
    TabEmboss: TTabItem;
    L11: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    CBColWUnits: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    CBSymbolPos: TComboBox;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    CBContinuous: TCheckBox;
    CBVisible: TCheckBox;
    CBSymPen: TCheckBox;
    CBSquared: TCheckBox;
    UDWidth: TSpinBox;
    CBImages: TCheckBox;
    procedure CBColWUnitsChange(Sender: TObject);
    procedure CBSymbolPosChange(Sender: TObject);
    procedure CBVisibleChange(Sender: TObject);
    procedure CBContinuousChange(Sender: TObject);
    procedure CBSquaredChange(Sender: TObject);
    procedure UDWidthChange(Sender: TObject);
    procedure CBSymPenChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure CBImagesChange(Sender: TObject);
  private
   { Private declarations }
    Symbol : TLegendSymbol;

    IBorder : TStrokeEditor;
    IGradient : TGradientEditor;
    IShadow : TShadowEditor;
    IEmboss : TShadowEditor;
  public
   { Public declarations }
    class function CreateEditor(const AOwner:TComponent; const ASymbol:TLegendSymbol):TSymbolEditor;
    procedure RefreshSymbol(const ASymbol:TLegendSymbol);
  end;

implementation

{$R *.fmx}

class function TSymbolEditor.CreateEditor(const AOwner: TComponent;
  const ASymbol:TLegendSymbol): TSymbolEditor;
begin
  result:=TSymbolEditor.Create(AOwner);
  result.RefreshSymbol(ASymbol);
end;

procedure TSymbolEditor.RefreshSymbol(const ASymbol: TLegendSymbol);
begin
  Symbol:=ASymbol;

  CBColWUnits.ItemIndex:=Ord(Symbol.WidthUnits);
  CBSymbolPos.ItemIndex:=Ord(Symbol.Position);
  CBContinuous.IsChecked:=Symbol.Continuous;
  CBVisible.IsChecked:=Symbol.Visible;
  CBSymPen.IsChecked:=Symbol.DefaultPen;
  CBSquared.IsChecked:=Symbol.Squared;
  CBImages.IsChecked:=Symbol.UseImages;

  UDWidth.Value:=Symbol.Width;

  if Assigned(IBorder) then
     IBorder.RefreshPen(Symbol.Pen);

  if Assigned(IGradient) then
     IGradient.RefreshGradient(Symbol.Gradient);

  if Assigned(IShadow) then
     IShadow.RefreshShadow(Symbol.Shadow);

  if Assigned(IEmboss) then
     IEmboss.RefreshShadow(Symbol.Emboss);
end;

procedure TSymbolEditor.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabBorder) and (not Assigned(IBorder)) then
     IBorder:=TStrokeEditor.InsertForm(Symbol.Pen,TabBorder)
  else
  if (TabControl1.ActiveTab=TabGradient) and (not Assigned(IGradient)) then
     IGradient:=TGradientEditor.InsertForm(Symbol.Gradient,TabGradient)
  else
  if (TabControl1.ActiveTab=TabShadow) and (not Assigned(IShadow)) then
     IShadow:=TShadowEditor.InsertForm(Symbol.Shadow,TabShadow)
  else
  if (TabControl1.ActiveTab=TabEmboss) and (not Assigned(IEmboss)) then
     IEmboss:=TShadowEditor.InsertForm(Symbol.Emboss,TabEmboss);
end;

procedure TSymbolEditor.UDWidthChange(Sender: TObject);
begin
  Symbol.Width:=Round(UDWidth.Value);
end;

procedure TSymbolEditor.CBColWUnitsChange(Sender: TObject);
begin
  Symbol.WidthUnits:=TLegendSymbolSize(CBColWUnits.ItemIndex);
end;

procedure TSymbolEditor.CBSymbolPosChange(Sender: TObject);
begin
  Symbol.Position:=TLegendSymbolPosition(CBSymbolPos.ItemIndex);
end;

procedure TSymbolEditor.CBContinuousChange(Sender: TObject);
begin
  Symbol.Continuous:=CBContinuous.IsChecked;
end;

procedure TSymbolEditor.CBImagesChange(Sender: TObject);
begin
  Symbol.UseImages:=CBImages.IsChecked;
end;

procedure TSymbolEditor.CBVisibleChange(Sender: TObject);
begin
  Symbol.Visible:=CBVisible.IsChecked;
end;

procedure TSymbolEditor.CBSymPenChange(Sender: TObject);
begin
  Symbol.DefaultPen:=CBSymPen.IsChecked;
end;

procedure TSymbolEditor.CBSquaredChange(Sender: TObject);
begin
  Symbol.Squared:=CBSquared.IsChecked;
end;

end.
