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

type
  TSelectorToolEditor = class(TForm)
    Label2: TLabel;
    CBCursor: TComboBox;
    BHandles: TButton;
    CBAllowDrag: TCheckBox;
    Label5: TLabel;
    UDSize: TSpinBox;
    Label4: TLabel;
    CBColor: TComboColorBox;
    CBResizeChart: TCheckBox;
    procedure FormActivate(Sender: TObject);
    procedure CBCursorChange(Sender: TObject);
    procedure CBAllowDragChange(Sender: TObject);
    procedure UDSizeChange(Sender: TObject);
    procedure BHandlesClick(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
    procedure CBResizeChartChange(Sender: TObject);
  private
    { Private declarations }
    Selector : TSelectorTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  System.UIConsts, FMXTee.Editor.Series, FMXTee.Editor.Stroke;

const
  TeeCursorPrefix='cr';

procedure TSelectorToolEditor.BHandlesClick(Sender: TObject);
begin
  if Assigned(Selector) then
     TStrokeEditor.Edit(Self, Selector.Pen);
end;

procedure TSelectorToolEditor.CBColorChange(Sender: TObject);
begin
  if Assigned(Selector) then
    Selector.Brush.Color:=CBColor.Color;
end;

procedure TSelectorToolEditor.CBCursorChange(Sender: TObject);
begin
  if Assigned(Selector) and (CBCursor.ItemIndex>=0) then
    Selector.Cursor:=StringToCursor(TeeCursorPrefix+CBCursor.Selected.Text);
end;

procedure TSelectorToolEditor.CBResizeChartChange(Sender: TObject);
begin
  if Assigned(Selector) then
    Selector.AllowResizeChart:=CBResizeChart.IsChecked;
end;

procedure TSelectorToolEditor.CBAllowDragChange(Sender: TObject);
begin
  if Assigned(Selector) then
    Selector.AllowDrag:=CBAllowDrag.IsChecked;
end;

procedure TSelectorToolEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Selector) then
  begin
    Selector:=TSelectorTool(TagObject);

    if Assigned(Selector) then
    With Selector do
    begin
      CBColor.Color:=Brush.Color;
      UDSize.Value:=HandleSize;
      CBAllowDrag.IsChecked:=AllowDrag;
      CBResizeChart.IsChecked:=AllowResizeChart;

      TeeFillCursors(CBCursor,Cursor);
    end;
  end;
end;

procedure TSelectorToolEditor.UDSizeChange(Sender: TObject);
begin
  if Assigned(Selector) then
    Selector.HandleSize:=Round(UDSize.Value);
end;

initialization
  RegisterSeriesEditor(TSelectorToolEditor);
end.
