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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms,
  FMX.ListBox, FMX.Edit, FMX.Dialogs, FMX.TabControl, FMXTee.Engine,
  FMXTee.Series;

type
  TSeriesPointerEditor = class(TForm)
    PanelBottom: TPanel;
    Panel1: TPanel;
    Button1: TButton;
    PageControl1: TTabControl;
    TabStyle: TTabItem;
    Label3: TLabel;
    LTransp: TLabel;
    CBDrawPoint: TCheckBox;
    CB3dPoint: TCheckBox;
    CBStyle: TComboBox;
    CBPoDark: TCheckBox;
    CBColorEach: TCheckBox;
    CBIgnoreNulls: TCheckBox;
    BGradient: TButton;
    Button2: TButton;
    TBTransp: TTrackBar;
    GroupBox1: TGroupBox;
    BPointFillColor: TButton;
    CBDefBrushColor: TCheckBox;
    BPoinPenCol: TButton;
    BEmboss: TButton;
    TabSize: TTabItem;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    UDPointHorizSize: TSpinBox;
    UDPointVertSize: TSpinBox;
    UDPointDepth: TSpinBox;
    CBInflate: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBStyleDrawItem;
    procedure BGradientClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure BPointFillColorClick(Sender: TObject);
    procedure BPoinPenColClick(Sender: TObject);
    procedure BEmbossClick(Sender: TObject);
    procedure SEPointHorizSizeChange(Sender: TObject);
    procedure SEPointVertSizeChange(Sender: TObject);
    procedure SEPointDepthChange(Sender: TObject);
    procedure CBDrawPointChange(Sender: TObject);
    procedure CB3dPointChange(Sender: TObject);
    procedure CBColorEachChange(Sender: TObject);
    procedure CBIgnoreNullsChange(Sender: TObject);
    procedure CBInflateChange(Sender: TObject);
    procedure CBPoDarkChange(Sender: TObject);
    procedure CBDefBrushColorChange(Sender: TObject);
    procedure UDPointDepthChangeTracking(Sender: TObject);
    procedure UDPointVertSizeChangeTracking(Sender: TObject);
    procedure UDPointHorizSizeChangeTracking(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
   { Private declarations }
    Pointer : TSeriesPointer;

    function CustomSeries:TCustomLineSeries;
    procedure RefreshPointer(const APointer:TSeriesPointer);
  public
   { Public declarations }
    class function CreateEditor(const AOwner:TComponent; const APointer:TSeriesPointer):TForm;
    class function Edit(const AOwner:TComponent; const APointer:TSeriesPointer):Boolean;
    procedure HideSizeOptions;
    class function InsertForm(const APointer:TSeriesPointer; const AParent:TControl):TSeriesPointerEditor;
  end;

implementation

{$R *.fmx}

uses
  {$IFDEF D17}
  System.UIConsts,
  {$ENDIF}
  FMXTee.Editor.Gradient, FMXTee.Editor.Stroke, FMXTee.Editor.Brush,
  FMXTee.Editor.Shadow, FMXTee.Procs;

procedure TSeriesPointerEditor.FormActivate(Sender: TObject);
begin
  if (not Assigned(Pointer)) and Assigned(TagObject) and (CustomSeries<>TagObject) then
     RefreshPointer(TCustomSeries(TagObject).Pointer);
end;

procedure TSeriesPointerEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActiveTab:=TabStyle;
end;

procedure TSeriesPointerEditor.HideSizeOptions;
begin
  Label1.Visible:=False;
  UDPointHorizSize.Visible:=False;
  Label2.Visible:=False;
  UDPointVertSize.Visible:=False;
end;

function TSeriesPointerEditor.CustomSeries:TCustomLineSeries;
begin
  if Assigned(Pointer) and (Pointer.ParentSeries is TCustomLineSeries) then
     result:=TCustomLineSeries(Pointer.ParentSeries)
  else
     result:=nil;
end;

procedure TSeriesPointerEditor.RefreshPointer(const APointer: TSeriesPointer);
begin
  Pointer:=APointer;

  CBDrawPoint.IsChecked:=Pointer.Visible;
  CB3dPoint.IsChecked:=Pointer.Draw3D;
  CBStyle.ItemIndex:=Ord(Pointer.Style);
  CBPoDark.IsChecked:=Pointer.Dark3D;
  EnableControls(Assigned(Pointer.ParentSeries),[CBColorEach,CBIgnoreNulls]);

  if Assigned(Pointer.ParentSeries) then
  begin
    CBColorEach.IsChecked:=Pointer.ParentSeries.ColorEachPoint;

    CBIgnoreNulls.Enabled:=(CustomSeries<>nil);

    if CBIgnoreNulls.Enabled then
       CBIgnoreNulls.IsChecked:=CustomSeries.TreatNulls=tnIgnore;
  end;

  CBInflate.IsChecked:=Pointer.InflateMargins;

  TBTransp.Value:=Pointer.Transparency;

  UDPointHorizSize.Value:=Pointer.HorizSize;
  UDPointVertSize.Value:=Pointer.VertSize;
  UDPointDepth.Value:=Pointer.Depth;
end;

procedure TSeriesPointerEditor.CBDrawPointChange(Sender: TObject);
begin
  Pointer.Visible:=CBDrawPoint.IsChecked;
end;

procedure TSeriesPointerEditor.CB3dPointChange(Sender: TObject);
begin
  Pointer.Draw3D:=CB3dPoint.IsChecked;
end;

procedure TSeriesPointerEditor.CBStyleChange(Sender: TObject);
begin
  Pointer.Style:=TSeriesPointerStyle(CBStyle.ItemIndex);
end;

procedure TSeriesPointerEditor.CBStyleDrawItem;
begin
// TODO
end;

class function TSeriesPointerEditor.CreateEditor(const AOwner: TComponent;
  const APointer: TSeriesPointer): TForm;
begin
  result:=TSeriesPointerEditor.Create(AOwner);
  TSeriesPointerEditor(result).RefreshPointer(APointer);
end;

class function TSeriesPointerEditor.InsertForm(const APointer: TSeriesPointer;
  const AParent: TControl): TSeriesPointerEditor;
begin
  result:=TSeriesPointerEditor.CreateEditor(AParent.Owner, APointer) as TSeriesPointerEditor;
  EmbeddForm(result,AParent);
end;

class function TSeriesPointerEditor.Edit(const AOwner: TComponent;
  const APointer: TSeriesPointer): Boolean;
begin
  with CreateEditor(AOwner, APointer) as TSeriesPointerEditor do
  try
    PanelBottom.Visible:=True;
    result:=ShowModal=mrOk;
  finally
    Free;
  end;
end;

procedure TSeriesPointerEditor.CBPoDarkChange(Sender: TObject);
begin
  Pointer.Dark3D:=CBPoDark.IsChecked;
end;

procedure TSeriesPointerEditor.CBColorEachChange(Sender: TObject);
begin
  Pointer.ParentSeries.ColorEachPoint:=CBColorEach.IsChecked;
end;

procedure TSeriesPointerEditor.CBIgnoreNullsChange(Sender: TObject);
begin
  if CBIgnoreNulls.IsChecked then
     CustomSeries.TreatNulls:=tnIgnore
  else
     CustomSeries.TreatNulls:=tnDontPaint;
end;

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

procedure TSeriesPointerEditor.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TSeriesPointerEditor.Button2Click(Sender: TObject);
begin
  TShadowEditor.Edit(Self, Pointer.Shadow);
end;

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

procedure TSeriesPointerEditor.UDPointDepthChangeTracking(Sender: TObject);
begin
  if Assigned(Pointer) then
     Pointer.Depth:=Round(UDPointDepth.Value);
end;

procedure TSeriesPointerEditor.UDPointHorizSizeChangeTracking(Sender: TObject);
begin
  if Assigned(Pointer) then
     Pointer.HorizSize:=Round(UDPointHorizSize.Value);
end;

procedure TSeriesPointerEditor.UDPointVertSizeChangeTracking(Sender: TObject);
begin
  if Assigned(Pointer) then
     Pointer.VertSize:=Round(UDPointVertSize.Value);
end;

procedure TSeriesPointerEditor.BPointFillColorClick(Sender: TObject);
begin
  TBrushEditor.Edit(Self, Pointer.Brush);
end;

procedure TSeriesPointerEditor.CBDefBrushColorChange(Sender: TObject);
begin
  if CBDefBrushColor.IsChecked then
  begin
    Pointer.Color:=clTeeColor;
    Pointer.Pen.Color:=clTeeColor;
  end
  else
  if Pointer.Pen.Color=clTeeColor then
     Pointer.Pen.Color:=claBlack;

  //BPoinPenCol.Repaint;
  CBStyle.Repaint;
end;

procedure TSeriesPointerEditor.BPoinPenColClick(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Pointer.Pen);
end;

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

procedure TSeriesPointerEditor.SEPointHorizSizeChange(Sender: TObject);
begin
// TODO
end;

procedure TSeriesPointerEditor.SEPointVertSizeChange(Sender: TObject);
begin
// TODO
end;

procedure TSeriesPointerEditor.SEPointDepthChange(Sender: TObject);
begin
// TODO
end;

procedure TSeriesPointerEditor.CBInflateChange(Sender: TObject);
begin
  Pointer.InflateMargins:=CBInflate.IsChecked;
end;

initialization
  RegisterSeriesEditor(TSeriesPointerEditor);
end.
