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

type
  TDragPointToolEdit = class(TSeriesToolEditor)
    Label2: TLabel;
    CBCursor: TComboBox;
    GroupBox1: TGroupBox;
    RBX: TRadioButton;
    RBY: TRadioButton;
    RBBoth: TRadioButton;
    procedure FormActivate(Sender: TObject);
    procedure CBCursorChange(Sender: TObject);
    procedure CBSeriesChange(Sender: TObject);
    procedure RBXChange(Sender: TObject);
    procedure RBYChange(Sender: TObject);
    procedure RBBothChange(Sender: TObject);
  private
    { Private declarations }
    DragPoint : TDragPointTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  System.UIConsts, FMXTee.Editor.Stroke;

const
  TeeCursorPrefix='cr';

procedure TDragPointToolEdit.CBCursorChange(Sender: TObject);
begin
  if Assigned(DragPoint) and Assigned(DragPoint.Series) then
    DragPoint.Series.Cursor:=StringToCursor(TeeCursorPrefix+CBCursor.Selected.Text);
end;

procedure TDragPointToolEdit.CBSeriesChange(Sender: TObject);
begin
  inherited;

  CBCursor.Enabled:=Assigned(DragPoint) and Assigned(DragPoint.Series);

  if CBCursor.Enabled then
    TeeFillCursors(CBCursor,DragPoint.Series.Cursor);
end;

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

  if not Assigned(DragPoint) then
  begin
    DragPoint:=TDragPointTool(TagObject);

    if Assigned(DragPoint) then
    With DragPoint do
    begin
      Case DragStyle of
        dsX : RBX.IsChecked:=True;
        dsY : RBY.IsChecked:=True;
      else
        RBBoth.IsChecked:=True;
      end;
      if Assigned(Series) then
      begin
        CBCursor.Enabled:=True;
        TeeFillCursors(CBCursor,Series.Cursor);
      end;
    end;
  end;
end;

procedure TDragPointToolEdit.RBBothChange(Sender: TObject);
begin
  if Assigned(DragPoint) then
    DragPoint.DragStyle:=dsBoth;
end;

procedure TDragPointToolEdit.RBXChange(Sender: TObject);
begin
  if Assigned(DragPoint) then
    DragPoint.DragStyle:=dsX;
end;

procedure TDragPointToolEdit.RBYChange(Sender: TObject);
begin
  if Assigned(DragPoint) then
    DragPoint.DragStyle:=dsY;
end;

initialization
  RegisterSeriesEditor(TDragPointToolEdit);
end.
