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

type
  TRotateToolEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabFormat: TTabItem;
    Label2: TLabel;
    CBCursor: TComboBox;
    CBInverted: TCheckBox;
    CBStyle: TComboBox;
    Label1: TLabel;
    CBButton: TComboBox;
    Label3: TLabel;
    SBInertia: TTrackBar;
    LabelInertia: TLabel;
    Label4: TLabel;
    UDSpeed: TSpinBox;
    Label5: TLabel;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    ListBoxItem6: TListBoxItem;
    BOutline: TButton;
    procedure FormActivate(Sender: TObject);
    procedure CBCursorChange(Sender: TObject);
    procedure CBInvertedChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBButtonChange(Sender: TObject);
    procedure UDSpeedChange(Sender: TObject);
    procedure SBInertiaChange(Sender: TObject);
    procedure BOutlineClick(Sender: TObject);
  private
    { Private declarations }
    Rotate : TRotateTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

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

const
  TeeCursorPrefix='cr';

procedure TRotateToolEditor.BOutlineClick(Sender: TObject);
begin
  if Assigned(Rotate) then
     TStrokeEditor.Edit(Self, Rotate.Pen);
end;

procedure TRotateToolEditor.CBButtonChange(Sender: TObject);
begin
  if Assigned(Rotate) then
    Case CBButton.ItemIndex of
      0: Rotate.Button:=TMouseButton.mbLeft;
      1: Rotate.Button:=TMouseButton.mbMiddle;
    else
      Rotate.Button:=TMouseButton.mbRight;
    end;
end;

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

procedure TRotateToolEditor.CBInvertedChange(Sender: TObject);
begin
  if Assigned(Rotate) then
    Rotate.Inverted:=CBInverted.IsChecked;
end;

procedure TRotateToolEditor.CBStyleChange(Sender: TObject);
begin
  if Assigned(Rotate) then
    Rotate.Style:=TRotateToolStyles(CBStyle.ItemIndex);
end;

procedure TRotateToolEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Rotate) then
  begin
    Rotate:=TRotateTool(TagObject);

    if Assigned(Rotate) then
    With Rotate do
    begin
      CBInverted.IsChecked:=Inverted;
      CBStyle.ItemIndex:=Ord(Style);

      case Button of
        TMouseButton.mbLeft: CBButton.ItemIndex:=0;
        TMouseButton.mbMiddle: CBButton.ItemIndex:=1;
      else
        CBButton.ItemIndex:=2;
      end;

      UDSpeed.Value:=Speed;
      SBInertia.Value:=Inertia;

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

procedure TRotateToolEditor.SBInertiaChange(Sender: TObject);
begin
  if Assigned(Rotate) then
  begin
    Rotate.Inertia:=Round(SBInertia.Value);
    LabelInertia.Text:=IntToStr(Rotate.Inertia);
  end;
end;

procedure TRotateToolEditor.UDSpeedChange(Sender: TObject);
begin
  if Assigned(Rotate) then
    Rotate.Speed:=Round(UDSpeed.Value);
end;

initialization
  RegisterSeriesEditor(TRotateToolEditor);
end.
