unit FMXTee.Editor.Wall;

interface

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

type
  TWallEditor = class(TForm)
    TabSubWalls: TPanel;
    L33: TLabel;
    Label1: TLabel;
    BWallColor: TComboColorBox;
    BWallPen: TButton;
    BWallBrush: TButton;
    CBTransp: TCheckBox;
    UDWallSize: TSpinBox;
    CBDark3D: TCheckBox;
    BGradient: TButton;
    CBVisible: TCheckBox;
    UDTransp: TSpinBox;
    CBAutoHide: TCheckBox;
    GroupBox1: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    UDStart: TSpinBox;
    UDEnd: TSpinBox;
    BImage: TButton;
    BShadow: TButton;
    BVisual: TButton;
    BEmboss: TButton;
    Panel1: TPanel;
    Label2: TLabel;
    CBView3dWalls: TCheckBox;
    UDAllSize: TSpinBox;
    CBWall: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    procedure FormCreate(Sender: TObject);
    procedure TabSubWallsChange(Sender: TObject);
    procedure BWallBrushClick(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
    procedure BImageClick(Sender: TObject);
    procedure BShadowClick(Sender: TObject);
    procedure BVisualClick(Sender: TObject);
    procedure BEmbossClick(Sender: TObject);
    procedure CBView3dWallsChange(Sender: TObject);
    procedure CBWallChange(Sender: TObject);
    procedure UDAllSizeChange(Sender: TObject);
    procedure CBVisibleChange(Sender: TObject);
    procedure CBDark3DChange(Sender: TObject);
    procedure CBAutoHideChange(Sender: TObject);
    procedure CBTranspChange(Sender: TObject);
    procedure BWallPenClick(Sender: TObject);
    procedure UDWallSizeChange(Sender: TObject);
    procedure UDTranspChange(Sender: TObject);
    procedure UDStartChange(Sender: TObject);
    procedure UDEndChange(Sender: TObject);
    procedure BWallColorChange(Sender: TObject);
    procedure UDTranspApplyStyleLookup(Sender: TObject);
  private
   { Private declarations }
    Walls : TChartWalls;

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

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Editor.Gradient, FMXTee.Editor.Brush,
  FMXTee.Editor.Shadow, FMXTee.Canvas, FMXTee.Editor.Picture;

procedure TWallEditor.FormCreate(Sender: TObject);
begin
// TODO
  BVisual.Visible:=Assigned(TeeOnChangeVisual);
end;

procedure TWallEditor.RefreshWall(AWall: TChartWall);
begin
  CBVisible.IsChecked:=AWall.Visible;
  CBDark3D.IsChecked:=AWall.Dark3D;
  CBTransp.IsChecked:=AWall.Transparent;
  CBAutoHide.IsChecked:=AWall.AutoHide;

  BWallColor.Color:=AWall.Color;

  UDWallSize.Value:=AWall.Size;
  UDTransp.Value:=AWall.Transparency;
  UDStart.Value:=AWall.StartPosition;
  UDEnd.Value:=AWall.EndPosition;
end;

procedure TWallEditor.TabSubWallsChange(Sender: TObject);
begin
// TODO
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.UDTranspApplyStyleLookup(Sender: TObject);
begin
  TStrokeEditor.SetRepeatClick(TSpinBox(Sender),True);
end;

procedure TWallEditor.UDTranspChange(Sender: TObject);
begin
  Wall.Transparency:=Round(UDTransp.Value);
end;

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

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

procedure TWallEditor.BWallBrushClick(Sender: TObject);
begin
  TBrushEditor.Edit(Self, Wall.Brush)
end;

procedure TWallEditor.BWallColorChange(Sender: TObject);
begin
  Wall.Color:=BWallColor.Color;
end;

procedure TWallEditor.BWallPenClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Wall.Pen)
end;

procedure TWallEditor.CBTranspChange(Sender: TObject);
begin
  Wall.Transparent:=CBTransp.IsChecked;
end;

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

procedure TWallEditor.BGradientClick(Sender: TObject);
begin
  TGradientEditor.Edit(Self, Wall.Gradient)
end;

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

procedure TWallEditor.CBWallChange(Sender: TObject);
begin
  RefreshWall(Wall);
end;

procedure TWallEditor.RefreshWalls(AWalls:TChartWalls; 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(AOwner: TComponent; AWalls: TChartWalls):TWallEditor;
begin
  result:=TWallEditor.Create(AOwner);
  result.RefreshWalls(AWalls);
end;

class function TWallEditor.CreateEditor(AOwner: TComponent; 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.BShadowClick(Sender: TObject);
begin
  TShadowEditor.Edit(Self,Wall.Shadow)
end;

procedure TWallEditor.BVisualClick(Sender: TObject);
begin
// TODO
end;

procedure TWallEditor.BEmbossClick(Sender: TObject);
begin
  TShadowEditor.Edit(Self,Wall.Emboss)
end;

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

end.
