unit FMXTee.Editor.Series.CustomBar;

interface

uses
  SysUtils, Types, Classes, Variants, FMX.Types, FMX.Controls, FMX.Forms,
  FMX.ListBox, FMX.Edit, FMX.Dialogs, FMX.TabControl, FMXTee.Series,
  FMXTee.Editor.Series.Bar.Stack, FMX.Colors;

type
  TBarSeriesEditor = class(TForm)
    PageControl1: TTabControl;
    TabSheet1: TTabItem;
    LStyle: TLabel;
    LTransp: TLabel;
    CBBarStyle: TComboBox;
    BBarBrush: TButton;
    GroupBox2: TGroupBox;
    CBColorEach: TCheckBox;
    BGradient: TButton;
    BTickLines: TButton;
    CBRelative: TCheckBox;
    TBTransp: TTrackBar;
    TabSheet2: TTabItem;
    Label1: TLabel;
    Label3: TLabel;
    Label2: TLabel;
    UDBarWidth: TSpinBox;
    UDBarOffset: TSpinBox;
    UDDepth: TSpinBox;
    CBBarSideMargins: TCheckBox;
    CBMarksAutoPosition: TCheckBox;
    GroupBox1: TGroupBox;
    Llocation: TLabel;
    cbMarksOnBar: TCheckBox;
    CBLocation: TComboBox;
    TabShadow: TTabItem;
    TabEmboss: TTabItem;
    TabSheet3: TTabItem;
    LBevel: TLabel;
    Label4: TLabel;
    BBarPen: TButton;
    UDBevel: TSpinBox;
    UDDarkPen: TSpinBox;
    GroupBox3: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    CBRound: TCheckBox;
    UDRoundSize: TSpinBox;
    CBBarRound: TComboBox;
    BColor: TComboColorBox;
    GroupBox4: TGroupBox;
    TBSides: TTrackBar;
    CBDarkBar: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBBarStyleChange(Sender: TObject);
    procedure BBarBrushClick(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure CBLocationChange(Sender: TObject);
    procedure EBevelChange(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure ERoundSizeChange(Sender: TObject);
    procedure CBBarRoundChange(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure CBDarkBarChange(Sender: TObject);
    procedure CBBarSideMarginsChange(Sender: TObject);
    procedure CBMarksAutoPositionChange(Sender: TObject);
    procedure cbMarksOnBarChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CBRelativeChange(Sender: TObject);
    procedure BTickLinesClick(Sender: TObject);
    procedure BBarPenClick(Sender: TObject);
    procedure CBRoundChange(Sender: TObject);
    procedure BColorChange(Sender: TObject);
    procedure UDDepthChange(Sender: TObject);
    procedure UDBarWidthChange(Sender: TObject);
    procedure UDBarOffsetChange(Sender: TObject);
    procedure UDDarkPenChange(Sender: TObject);
    procedure UDBevelChange(Sender: TObject);
    procedure UDRoundSizeChange(Sender: TObject);
    procedure TBSidesChange(Sender: TObject);
  private
   { Private declarations }
    Bar : TCustomBarSeries;

    FStackEditor : TStackBarSeriesEditor;
    FShadowEditor,
    FEmbossEditor : TForm;

    procedure RefreshBar(ABar:TCustomBarSeries);
  public
   { Public declarations }
    class function CreateEditor(AOwner:TComponent; ABar:TCustomBarSeries):TForm;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Constants, FMXTee.Canvas, FMXTee.Editor.Shadow, FMXTee.Editor.Brush,
  FMXTee.Editor.Stroke, FMXTee.Editor.Gradient, FMXTee.Procs;

procedure TBarSeriesEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Bar) then
     RefreshBar(TCustomBarSeries(TagObject));
end;

procedure TBarSeriesEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActiveTab:=TabSheet1;
end;

procedure TBarSeriesEditor.FormDestroy(Sender: TObject);
begin
// TODO
end;

procedure TBarSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActiveTab=TabShadow) and (not Assigned(FShadowEditor)) then
     FShadowEditor:=TShadowEditor.CreateEmbedd(Self,Bar.Shadow,TabShadow)
  else
  if (PageControl1.ActiveTab=TabEmboss) and (not Assigned(FEmbossEditor)) then
     FEmbossEditor:=TShadowEditor.CreateEmbedd(Self,Bar.Emboss,TabEmboss)
end;

procedure TBarSeriesEditor.RefreshBar(ABar: TCustomBarSeries);
var TabStack : TTabItem;
begin
  Bar:=ABar;

  CBBarStyle.ItemIndex:=Ord(Bar.BarStyle);

  CBColorEach.IsChecked:=Bar.ColorEachPoint;
  BColor.Color:=Bar.Color;
  BColor.Enabled:=not Bar.ColorEachPoint;

  CBDarkBar.IsChecked:=Bar.Dark3D;
  CBBarSideMargins.IsChecked:=Bar.SideMargins;
  CBMarksAutoPosition.IsChecked:=Bar.AutoMarkPosition;
  cbMarksOnBar.IsChecked:=Bar.MarksOnBar;
  CBLocation.ItemIndex:=Ord(Bar.MarksLocation);

  TBTransp.Value:=Bar.Transparency;
  TBSides.Value:=Bar.Sides;

  UDBarWidth.Value:=Bar.BarWidthPercent;
  UDBarOffset.Value:=Bar.OffsetPercent;
  UDDepth.Value:=Bar.Depth;
  UDBevel.Value:=Bar.BevelSize;
  UDDarkPen.Value:=Bar.DarkPen;
  UDRoundSize.Value:=Bar.RoundSize;

  if not Assigned(FStackEditor) then
  begin
    FStackEditor:=TStackBarSeriesEditor.CreateEditor(Self,ABar) as TStackBarSeriesEditor;

    TabStack:=TTabItem.Create(Self);
    TabStack.Text:=TeeMsg_Stack;

    PageControl1.AddObject(TabStack);
    EmbeddForm(FStackEditor,TabStack);
  end
  else
     FStackEditor.RefreshBar(Bar);
end;

procedure TBarSeriesEditor.CBBarStyleChange(Sender: TObject);
begin
  Bar.BarStyle:=TBarStyle(CBBarStyle.ItemIndex);
end;

procedure TBarSeriesEditor.BBarBrushClick(Sender: TObject);
begin
  TBrushEditor.Edit(Self, Bar.Brush);
end;

procedure TBarSeriesEditor.CBColorEachChange(Sender: TObject);
begin
  Bar.ColorEachPoint:=CBColorEach.IsChecked;
  BColor.Enabled:=not Bar.ColorEachPoint;
end;

procedure TBarSeriesEditor.BBarPenClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self,Bar.Pen);
end;

procedure TBarSeriesEditor.BColorChange(Sender: TObject);
begin
  Bar.Color:=BColor.Color;
end;

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

procedure TBarSeriesEditor.BTickLinesClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Bar.TickLines);
end;

procedure TBarSeriesEditor.CBDarkBarChange(Sender: TObject);
begin
  Bar.Dark3D:=CBDarkBar.IsChecked;
end;

procedure TBarSeriesEditor.CBRelativeChange(Sender: TObject);
begin
  Bar.GradientRelative:=CBRelative.IsChecked;
end;

procedure TBarSeriesEditor.TBSidesChange(Sender: TObject);
begin
  Bar.Sides:=Round(TBSides.Value);
end;

procedure TBarSeriesEditor.TBTranspChange(Sender: TObject);
begin
  Bar.Transparency:=Round(TBTransp.Value);
end;

procedure TBarSeriesEditor.UDBarOffsetChange(Sender: TObject);
begin
  Bar.OffsetPercent:=Round(UDBarOffset.Value);
end;

procedure TBarSeriesEditor.UDBarWidthChange(Sender: TObject);
begin
  if Assigned(Bar) then
     Bar.BarWidthPercent:=Round(UDBarWidth.Value);
end;

procedure TBarSeriesEditor.UDBevelChange(Sender: TObject);
begin
  if Assigned(Bar) then
     Bar.BevelSize:=Round(UDBevel.Value);
end;

procedure TBarSeriesEditor.UDDarkPenChange(Sender: TObject);
begin
  if Assigned(Bar) then
     Bar.DarkPen:=Round(UDDarkPen.Value);
end;

procedure TBarSeriesEditor.UDDepthChange(Sender: TObject);
begin
  if Assigned(Bar) then
     Bar.Depth:=Round(UDDepth.Value);
end;

procedure TBarSeriesEditor.UDRoundSizeChange(Sender: TObject);
begin
  if Assigned(Bar) then
     Bar.RoundSize:=Round(UDRoundSize.Value);
end;

procedure TBarSeriesEditor.CBBarSideMarginsChange(Sender: TObject);
begin
  Bar.SideMargins:=CBBarSideMargins.IsChecked;
end;

procedure TBarSeriesEditor.CBMarksAutoPositionChange(Sender: TObject);
begin
  Bar.AutoMarkPosition:=CBMarksAutoPosition.IsChecked;
end;

procedure TBarSeriesEditor.cbMarksOnBarChange(Sender: TObject);
begin
  Bar.MarksOnBar:=cbMarksOnBar.IsChecked;
end;

procedure TBarSeriesEditor.CBLocationChange(Sender: TObject);
begin
  Bar.MarksLocation:=TMarksLocation(CBLocation.ItemIndex);
end;

procedure TBarSeriesEditor.EBevelChange(Sender: TObject);
begin
// TODO
end;

procedure TBarSeriesEditor.Edit2Change(Sender: TObject);
begin
// TODO
end;

procedure TBarSeriesEditor.CBRoundChange(Sender: TObject);
begin
  if CBRound.IsChecked then
     Bar.BarRound:=brBothEnds
  else
     Bar.BarRound:=brNone;
end;

class function TBarSeriesEditor.CreateEditor(AOwner: TComponent;
  ABar: TCustomBarSeries): TForm;
begin
  result:=TBarSeriesEditor.Create(AOwner);
  TBarSeriesEditor(result).RefreshBar(ABar);
end;

procedure TBarSeriesEditor.ERoundSizeChange(Sender: TObject);
begin
// TODO
end;

procedure TBarSeriesEditor.CBBarRoundChange(Sender: TObject);
begin
  Bar.BarRound:=TBarRound(CBBarRound.ItemIndex);
end;

initialization
  RegisterSeriesEditor(TBarSeriesEditor);
end.
