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

interface

uses
  System.SysUtils, System.Types, System.Classes, System.Variants, FMX.Types,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  FMX.Controls, FMX.Forms,
  FMX.Edit, FMX.Dialogs, FMX.TabControl, FMX.ListBox, FMXTee.Chart, FMX.Colors,
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMXTee.Editor.CustomShape;

type
  TWallEditor = class(TForm)
    Panel1: TPanel;
    Label2: TLabel;
    CBView3dWalls: TCheckBox;
    UDAllSize: TSpinBox;
    TabControl1: TTabControl;
    TabItem1: TTabItem;
    TabItem2: TTabItem;
    TabItem3: TTabItem;
    TabItem4: TTabItem;
    TabSubWalls: TPanel;
    TabControl2: TTabControl;
    TabOptions: TTabItem;
    CBVisible: TCheckBox;
    CBDark3D: TCheckBox;
    CBAutoHide: TCheckBox;
    GroupBox1: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    UDStart: TSpinBox;
    UDEnd: TSpinBox;
    L33: TLabel;
    UDWallSize: TSpinBox;
    procedure BImageClick(Sender: TObject);
    procedure CBView3dWallsChange(Sender: TObject);
    procedure UDAllSizeChange(Sender: TObject);
    procedure CBVisibleChange(Sender: TObject);
    procedure CBDark3DChange(Sender: TObject);
    procedure CBAutoHideChange(Sender: TObject);
    procedure UDWallSizeChange(Sender: TObject);
    procedure UDStartChange(Sender: TObject);
    procedure UDEndChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure TabControl2Change(Sender: TObject);
  private
   { Private declarations }
    Walls : TChartWalls;

    IShapeForm : TTeeShapeEditor;

    function Wall:TChartWall;
    procedure RefreshWall(const AWall:TChartWall);
    procedure RefreshWalls(const AWalls:TChartWalls; const AWall:TChartWall=nil);
  public
   { Public declarations }
    class function CreateEditor(const AOwner:TComponent; const AWalls:TChartWalls):TWallEditor; overload;
    class function CreateEditor(const AOwner:TComponent; const AWall:TChartWall):TWallEditor; overload;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Canvas, FMXTee.Editor.Picture;

procedure TWallEditor.RefreshWall(const AWall: TChartWall);
begin
  CBVisible.IsChecked:=AWall.Visible;
  CBDark3D.IsChecked:=AWall.Dark3D;
  CBAutoHide.IsChecked:=AWall.AutoHide;
  UDWallSize.Value:=AWall.Size;
  UDStart.Value:=AWall.StartPosition;
  UDEnd.Value:=AWall.EndPosition;

  if not Assigned(IShapeForm) then
  begin
    IShapeForm:=TTeeShapeEditor.Embedd(Self,TabControl2);
    IShapeForm.TabFont.Visible:=False;
  end;

  IShapeForm.RefreshShape(AWall);
end;

procedure TWallEditor.TabControl1Change(Sender: TObject);
begin
  TabSubWalls.Parent:=TabControl1.ActiveTab;
  RefreshWall(Wall);
end;

procedure TWallEditor.TabControl2Change(Sender: TObject);
begin
  if Assigned(IShapeForm) then
     IShapeForm.PC1Change(TabControl2);
end;

procedure TWallEditor.UDAllSizeChange(Sender: TObject);
begin
  Walls.Size:=Round(UDAllSize.Value);
end;

procedure TWallEditor.UDEndChange(Sender: TObject);
begin
  Wall.EndPosition:=Round(UDEnd.Value);
end;

procedure TWallEditor.UDStartChange(Sender: TObject);
begin
  Wall.StartPosition:=Round(UDStart.Value);
end;

procedure TWallEditor.UDWallSizeChange(Sender: TObject);
begin
  Wall.Size:=Round(UDWallSize.Value);
end;

function TWallEditor.Wall: TChartWall;
begin
  case TabControl1.ActiveTab.Index of
    0: result:=Walls.Left;
    1: result:=Walls.Right;
    2: result:=Walls.Bottom;
  else
    result:=Walls.Back;
  end;
end;

procedure TWallEditor.CBDark3DChange(Sender: TObject);
begin
  Wall.Dark3D:=CBDark3D.IsChecked;
end;

procedure TWallEditor.CBVisibleChange(Sender: TObject);
begin
  Wall.Visible:=CBVisible.IsChecked;
end;

procedure TWallEditor.RefreshWalls(const AWalls:TChartWalls; const AWall:TChartWall=nil);
begin
  Walls:=AWalls;

  CBView3dWalls.IsChecked:=Walls.Visible;
  UDAllSize.Value:=Walls.Left.Size;

  if Assigned(AWall) then
     RefreshWall(AWall)
  else
     RefreshWall(Walls.Left);
end;

class function TWallEditor.CreateEditor(const AOwner: TComponent; const AWalls: TChartWalls):TWallEditor;
begin
  result:=TWallEditor.Create(AOwner);
  result.RefreshWalls(AWalls);
end;

class function TWallEditor.CreateEditor(const AOwner: TComponent; const AWall: TChartWall):TWallEditor;
begin
  result:=TWallEditor.Create(AOwner);
  result.RefreshWalls(TCustomChart(AWall.ParentChart).Walls, AWall);
end;

procedure TWallEditor.CBAutoHideChange(Sender: TObject);
begin
  Wall.AutoHide:=CBAutoHide.IsChecked;
end;

procedure TWallEditor.BImageClick(Sender: TObject);
var tmp : TBackImageEditor;
begin
  tmp:=TBackImageEditor.Create(Self);

  with tmp do
  try
    RefreshPicture(Wall.Picture);
    RGBitmap.Visible:=False;
    GBPosition.Visible:=False;
    ShowModal;
  finally
    Free;
  end;
end;

procedure TWallEditor.CBView3dWallsChange(Sender: TObject);
begin
  Walls.Visible:=CBView3dWalls.IsChecked;
end;

end.
