{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Tools.DrawLine;
{$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, FMX.Edit, FMXTee.Tools, FMX.TabControl;

type
  TDrawLineEdit = class(TSeriesToolEditor)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabFormat: TTabItem;
    Label2: TLabel;
    CBButton: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    CBEnable: TCheckBox;
    CBSelect: TCheckBox;
    CBSelectNew: TCheckBox;
    Label4: TLabel;
    UDClick: TSpinBox;
    Label3: TLabel;
    BPen: TButton;
    Label5: TLabel;
    CBStyle: TComboBox;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    ListBoxItem6: TListBoxItem;
    ListBoxItem7: TListBoxItem;
    ListBoxItem8: TListBoxItem;
    procedure CBStyleChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CBButtonChange(Sender: TObject);
    procedure CBEnableChange(Sender: TObject);
    procedure CBSelectChange(Sender: TObject);
    procedure CBSelectNewChange(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure UDClickChange(Sender: TObject);
  private
    { Private declarations }
    DrawLine : TDrawLineTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

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

procedure TDrawLineEdit.FormActivate(Sender: TObject);
begin
  inherited;

  if not Assigned(DrawLine) then
  begin
    DrawLine:=TDrawLineTool(TagObject);

    if Assigned(DrawLine) then
    With DrawLine do
    begin
      CBButton.ItemIndex:=Ord(Button);
      CBEnable.IsChecked:=EnableDraw;
      CBSelect.IsChecked:=EnableSelect;
      CBSelectNew.IsChecked:=SelectNewLines;
      UDClick.Value:=ClickTolerance;
      CBStyle.ItemIndex:=Ord(Style);
    end;
  end;
end;

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

procedure TDrawLineEdit.CBButtonChange(Sender: TObject);
begin
  if Assigned(DrawLine) then
     DrawLine.Button:=TMouseButton(CBButton.ItemIndex);
end;

procedure TDrawLineEdit.CBEnableChange(Sender: TObject);
begin
  if Assigned(DrawLine) then
     DrawLine.EnableDraw:=CBEnable.IsChecked;
end;

procedure TDrawLineEdit.CBSelectChange(Sender: TObject);
begin
  if Assigned(DrawLine) then
     DrawLine.EnableSelect:=CBSelect.IsChecked
end;

procedure TDrawLineEdit.CBSelectNewChange(Sender: TObject);
begin
  if Assigned(DrawLine) then
     DrawLine.SelectNewLines:=CBSelectNew.IsChecked
end;

procedure TDrawLineEdit.CBStyleChange(Sender: TObject);
begin
  if Assigned(DrawLine) then
     DrawLine.Style:=TDrawLineStyle(CBStyle.ItemIndex);
end;

procedure TDrawLineEdit.UDClickChange(Sender: TObject);
begin
  if Assigned(DrawLine) then
     DrawLine.ClickTolerance:=Round(UDClick.Value);
end;

initialization
  RegisterSeriesEditor(TDrawLineEdit);
end.
