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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMXTee.Procs, FMX.ListBox, FMXTee.Tools.Arrow, FMX.Edit, FMX.TabControl;

type
  TArrowToolEditor = class(TForm)
    TabControl1: TTabControl;
    TabPosition: TTabItem;
    TabFormat: TTabItem;
    CBDraw2D: TCheckBox;
    SBZ: TTrackBar;
    LabelZ: TLabel;
    Label4: TLabel;
    BPen: TButton;
    GroupBox1: TGroupBox;
    UDFromX: TSpinBox;
    UDFromY: TSpinBox;
    Label1: TLabel;
    Label3: TLabel;
    GroupBox2: TGroupBox;
    UDToX: TSpinBox;
    UDToY: TSpinBox;
    Label6: TLabel;
    Label7: TLabel;
    ADAngle: TArcDial;
    Label5: TLabel;
    BBrush: TButton;
    CBFilled: TCheckBox;
    SBWidth: TTrackBar;
    LabelWidth: TLabel;
    Label8: TLabel;
    Label2: TLabel;
    SBHeight: TTrackBar;
    LabelHeight: TLabel;
    Label9: TLabel;
    SBPercent: TTrackBar;
    LabelPercent: TLabel;
    Label10: TLabel;
    SBTransparency: TTrackBar;
    LabelTrans: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure CBDraw2DChange(Sender: TObject);
    procedure SBZChange(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure UDFromXChange(Sender: TObject);
    procedure UDFromYChange(Sender: TObject);
    procedure UDToXChange(Sender: TObject);
    procedure UDToYChange(Sender: TObject);
    procedure ADAngleChange(Sender: TObject);
    procedure BBrushClick(Sender: TObject);
    procedure CBFilledChange(Sender: TObject);
    procedure SBWidthChange(Sender: TObject);
    procedure SBHeightChange(Sender: TObject);
    procedure SBPercentChange(Sender: TObject);
    procedure SBTransparencyChange(Sender: TObject);
  private
    { Private declarations }
    Arrow : TArrowTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Editor.Brush;

procedure TArrowToolEditor.ADAngleChange(Sender: TObject);
begin
  if Assigned(Arrow) then
    Arrow.Angle:=ADAngle.Value;
end;

procedure TArrowToolEditor.BBrushClick(Sender: TObject);
begin
  if Assigned(Arrow) then
     TBrushEditor.Edit(Self, Arrow.Brush);
end;

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

procedure TArrowToolEditor.CBDraw2DChange(Sender: TObject);
begin
  if Assigned(Arrow) then
    Arrow.Draw2D:=CBDraw2D.IsChecked;
end;

procedure TArrowToolEditor.CBFilledChange(Sender: TObject);
begin
  if Assigned(Arrow) then
    Arrow.Filled:=CBFilled.IsChecked;
end;

procedure TArrowToolEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Arrow) then
  begin
    Arrow:=TArrowTool(TagObject);

    if Assigned(Arrow) then
    With Arrow do
    begin
      CBFilled.IsChecked:=Arrow.Filled;
      SBWidth.Value:=Arrow.Width;
      SBHeight.Value:=Arrow.Height;
      ADAngle.Value:=Arrow.Angle;
      SBZ.Value:=Arrow.Z;
      SBPercent.Value:=Arrow.Percent;
      CBDraw2D.IsChecked:=Arrow.Draw2D;

      UDFromX.Value:=Arrow.FromPoint.X;
      UDFromY.Value:=Arrow.FromPoint.Y;
      UDToX.Value:=Arrow.ToPoint.X;
      UDToY.Value:=Arrow.ToPoint.Y;

      SBTransparency.Value:=Arrow.Transparency;
    end;
  end;
end;

procedure TArrowToolEditor.SBHeightChange(Sender: TObject);
begin
  if Assigned(Arrow) then
  begin
    Arrow.Height:=Round(SBHeight.Value);
    LabelHeight.Text:=IntToStr(Arrow.Height);
  end;
end;

procedure TArrowToolEditor.SBPercentChange(Sender: TObject);
begin
  if Assigned(Arrow) then
  begin
    Arrow.Percent:=Round(SBPercent.Value);
    LabelPercent.Text:=FloatToStr(Arrow.Percent);
  end;
end;

procedure TArrowToolEditor.SBTransparencyChange(Sender: TObject);
begin
  if Assigned(Arrow) then
  begin
    Arrow.Transparency:=Round(SBTransparency.Value);
    LabelTrans.Text:=IntToStr(Arrow.Transparency);
  end;
end;

procedure TArrowToolEditor.SBWidthChange(Sender: TObject);
begin
  if Assigned(Arrow) then
  begin
    Arrow.Width:=Round(SBWidth.Value);
    LabelWidth.Text:=IntToStr(Arrow.Width);
  end;
end;

procedure TArrowToolEditor.SBZChange(Sender: TObject);
begin
  if Assigned(Arrow) then
  begin
    Arrow.Z:=Round(SBZ.Value);
    LabelZ.Text:=IntToStr(Arrow.Z);
  end;
end;

procedure TArrowToolEditor.UDFromXChange(Sender: TObject);
begin
  if Assigned(Arrow) then
    Arrow.FromPoint.X:=Round(UDFromX.Value);
end;

procedure TArrowToolEditor.UDFromYChange(Sender: TObject);
begin
  if Assigned(Arrow) then
    Arrow.FromPoint.Y:=Round(UDFromY.Value);
end;

procedure TArrowToolEditor.UDToXChange(Sender: TObject);
begin
  if Assigned(Arrow) then
    Arrow.ToPoint.X:=Round(UDToX.Value);
end;

procedure TArrowToolEditor.UDToYChange(Sender: TObject);
begin
  if Assigned(Arrow) then
    Arrow.ToPoint.Y:=Round(UDToY.Value);
end;

initialization
  RegisterSeriesEditor(TArrowToolEditor);
end.
