unit FMXTee.Editor.Tools.Axis;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.ListBox,
  FMXTee.Procs, FMXTee.Engine, FMXTee.Canvas;

type
  TAxisToolEditor = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    CBAxis: TComboBox;
    BPen: TButton;
    procedure CBAxisChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    //Function DepthAxesOffset:Integer;
  protected
    AxisTool : TTeeCustomTool;
    IncludeDepthAxes : Boolean;

    function GetAxis:TChartAxis; virtual;
    procedure SetAxis(const AAxis:TChartAxis); virtual;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

Uses
  FMXTee.Editor.Stroke, FMXTee.Editor.Axis, FMXTee.Constants, FMXTee.ProConstants;

procedure TAxisToolEditor.BPenClick(Sender: TObject);
begin
  if Assigned(AxisTool) then
     TStrokeEditor.Edit(Self,AxisTool.Pen);
end;

procedure TAxisToolEditor.CBAxisChange(Sender: TObject);
begin
  if Assigned(AxisTool) and Assigned(AxisTool.ParentChart) then
     if CBAxis.ItemIndex>=0 then
        SetAxis(TChartAxis(CBAxis.Selected.Data))
     else
        SetAxis(nil);
end;

procedure TAxisToolEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(AxisTool) then
  begin
    AxisTool:=TTeeCustomToolAxis(TagObject);

    if Assigned(AxisTool) then
    begin
      CBAxis.Enabled:=Assigned(AxisTool.ParentChart);

      if Assigned(AxisTool.ParentChart) then
      begin
        FillAxesList(AxisTool.ParentChart.Axes,CBAxis.ListBox,IncludeDepthAxes);

        CBAxis.ItemIndex:=CBAxis.Items.IndexOfObject(GetAxis);
      end;

      if (CBAxis.ItemIndex<0) and (CBAxis.Items.Count>0) then
      begin
        CBAxis.ItemIndex:=0;
        CBAxisChange(CBAxis);
      end;
    end;
  end;
end;

function TAxisToolEditor.GetAxis:TChartAxis;
begin
  if AxisTool is TTeeCustomToolAxis then
     result:=TTeeCustomToolAxis(AxisTool).Axis
  else
     result:=nil;
end;

procedure TAxisToolEditor.SetAxis(const AAxis:TChartAxis);
begin
  if AxisTool is TTeeCustomToolAxis then
     TTeeCustomToolAxis(AxisTool).Axis:=AAxis;
end;

procedure TAxisToolEditor.FormCreate(Sender: TObject);
begin
  IncludeDepthAxes:=False;
end;

initialization
  RegisterSeriesEditor(TAxisToolEditor);
end.
