unit FMXTee.Editor.Panel;

interface

uses
  System.SysUtils, System.Types, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms,
  FMX.Edit, FMX.ListBox, FMX.Dialogs, FMX.TabControl, FMX.Ani, FMXTee.Chart,
  FMX.Colors, FMXTee.Editor.Gradient;

type
  TPanelEditor = class(TForm)
    PageControl1: TTabControl;
    TabBack: TTabItem;
    BPanelColor: TComboColorBox;
    CBColorDef: TCheckBox;
    CBImageInside: TCheckBox;
    TabBorders: TTabItem;
    L19: TLabel;
    L2: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    UDPanelWi: TSpinBox;
    UDPanelBor: TSpinBox;
    UDRound: TSpinBox;
    CBInner: TComboBox;
    CBOuter: TComboBox;
    BBorder: TButton;
    TabMargins: TTabItem;
    GBMargins: TGroupBox;
    Label5: TLabel;
    UDTopMa: TSpinBox;
    UDRightMa: TSpinBox;
    UDLeftMa: TSpinBox;
    UDBotMa: TSpinBox;
    CBMarUnits: TComboBox;
    TabGradient: TTabItem;
    TabShadow: TTabItem;
    TabEmboss: TTabItem;
    TabImage: TTabItem;
    procedure FormCreate(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBInnerChange(Sender: TObject);
    procedure CBOuterChange(Sender: TObject);
    procedure CBMarUnitsChange(Sender: TObject);
    procedure BBorderClick(Sender: TObject);
    procedure CBImageInsideChange(Sender: TObject);
    procedure CBColorDefChange(Sender: TObject);
    procedure UDPanelWiChange(Sender: TObject);
    procedure UDPanelBorChange(Sender: TObject);
    procedure UDRoundChange(Sender: TObject);
    procedure UDTopMaChange(Sender: TObject);
    procedure UDBotMaChange(Sender: TObject);
    procedure UDLeftMaChange(Sender: TObject);
    procedure UDRightMaChange(Sender: TObject);
    procedure BPanelColorChange(Sender: TObject);
  private
   { Private declarations }
    Chart : TCustomChart;

    IPicture,
    IShadow,
    IEmboss,
    IGradient : TForm;

    procedure RefreshChart(AChart:TCustomChart);
  public
   { Public declarations }
    class function CreateEditor(AOwner:TComponent; AChart:TCustomChart):TForm;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Canvas, FMXTee.Procs, FMXTee.Editor.Stroke, FMXTee.Editor.Shadow,
  FMXTee.Editor.Picture;

procedure TPanelEditor.FormCreate(Sender: TObject);
begin
end;

procedure TPanelEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActiveTab=TabGradient) and (not Assigned(IGradient)) then
    IGradient:=TGradientEditor.CreateEmbedd(Self, Chart.Gradient, TabGradient)
  else
  if (PageControl1.ActiveTab=TabShadow) and (not Assigned(IShadow)) then
    IShadow:=TShadowEditor.CreateEmbedd(Self, Chart.Shadow, TabShadow)
  else
  if (PageControl1.ActiveTab=TabEmboss) and (not Assigned(IEmboss)) then
    IEmboss:=TShadowEditor.CreateEmbedd(Self, Chart.Emboss, TabEmboss)
  else
  if (PageControl1.ActiveTab=TabImage) and (not Assigned(IPicture)) then
    IPicture:=TBackImageEditor.CreateEmbedd(Self, Chart.BackImage, TabImage)
end;

procedure TPanelEditor.RefreshChart(AChart: TCustomChart);
begin
  Chart:=AChart;

  BPanelColor.Color:=Chart.Color;

  CBImageInside.IsChecked:=Chart.BackImage.Inside;
  CBColorDef.IsChecked:=Chart.Color=clNone;

  CBInner.ItemIndex:=Ord(Chart.BevelInner);
  CBOuter.ItemIndex:=Ord(Chart.BevelOuter);
  CBMarUnits.ItemIndex:=Ord(Chart.MarginUnits);
  UDPanelWi.Value:=Chart.BevelWidth;
  UDPanelBor.Value:=Chart.BorderWidth;
  UDRound.Value:=Chart.BorderRound;
  UDTopMa.Value:=Chart.MarginTop;
  UDRightMa.Value:=Chart.MarginRight;
  UDLeftMa.Value:=Chart.MarginLeft;
  UDBotMa.Value:=Chart.MarginBottom;
end;

procedure TPanelEditor.BBorderClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Chart.Border);
end;

procedure TPanelEditor.BPanelColorChange(Sender: TObject);
begin
  Chart.Color:=BPanelColor.Color;
  CBColorDef.IsChecked:=Chart.Color=clNone;

  if Chart.Owner is TCustomTeePanel then
     TCustomTeePanel(Chart.Owner).Repaint;
end;

procedure TPanelEditor.CBColorDefChange(Sender: TObject);
begin
  if CBColorDef.IsChecked then
  begin
    Chart.Color:=clNone;
    BPanelColor.Color:=Chart.Color;
  end;
end;

procedure TPanelEditor.CBImageInsideChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BackImageInside:=CBImageInside.IsChecked;
end;

class function TPanelEditor.CreateEditor(AOwner: TComponent; AChart: TCustomChart):TForm;
begin
  result:=TPanelEditor.Create(AOwner);
  TPanelEditor(result).RefreshChart(AChart);
end;

procedure TPanelEditor.CBInnerChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BevelInner:=TPanelBevel(CBInner.ItemIndex);
end;

procedure TPanelEditor.CBOuterChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BevelOuter:=TPanelBevel(CBOuter.ItemIndex);
end;

procedure TPanelEditor.UDBotMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginBottom:=Round(UDBotMa.Value);
end;

procedure TPanelEditor.UDLeftMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginLeft:=Round(UDLeftMa.Value);
end;

procedure TPanelEditor.UDPanelBorChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BorderWidth:=Round(UDPanelBor.Value);
end;

procedure TPanelEditor.UDPanelWiChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BevelWidth:=Round(UDPanelWi.Value);
end;

procedure TPanelEditor.UDRightMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginRight:=Round(UDRightMa.Value);
end;

procedure TPanelEditor.UDRoundChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.BorderRound:=Round(UDRound.Value);
end;

procedure TPanelEditor.UDTopMaChange(Sender: TObject);
begin
  if Assigned(Chart) then
     Chart.MarginTop:=Round(UDTopMa.Value);
end;

procedure TPanelEditor.CBMarUnitsChange(Sender: TObject);
begin
  if Assigned(Chart) then
    Chart.MarginUnits:=TTeeUnits(CBMarUnits.ItemIndex);
end;

end.
