unit FMXTee.Editor.Tools.Cursor;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  FMXTee.Procs, FMX.TabControl, FMX.ListBox, FMXTee.Tools, FMX.Edit;

type
  TCursorToolEditor = class(TSeriesToolEditor)
    TabControl1: TTabControl;
    TabItem1: TTabItem;
    TabItem2: TTabItem;
    TabItem3: TTabItem;
    Button1: TButton;
    CBStyle: TComboBox;
    Label2: TLabel;
    CBSnap: TCheckBox;
    Label3: TLabel;
    CBSnapStyle: TComboBox;
    CBZ: TCheckBox;
    CBFollow: TCheckBox;
    UDClick: TComboTrackBar;
    Label4: TLabel;
    UDHorizSize: TSpinBox;
    LabelHorizSize: TLabel;
    UDVertSize: TSpinBox;
    LabelVertSize: TLabel;
    UDScope: TSpinBox;
    LabelScope: TLabel;
    CBScopeStyle: TComboBox;
    Label5: TLabel;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    ListBoxItem6: TListBoxItem;
    ListBoxItem7: TListBoxItem;
    ListBoxItem8: TListBoxItem;
    ListBoxItem9: TListBoxItem;
    ListBoxItem10: TListBoxItem;
    ListBoxItem11: TListBoxItem;
    ListBoxItem12: TListBoxItem;
    ListBoxItem13: TListBoxItem;
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CBFollowChange(Sender: TObject);
    procedure CBZChange(Sender: TObject);
    procedure UDClickTyping(Sender: TObject);
    procedure UDClickChangeTracking(Sender: TObject);
    procedure CBSnapStyleChange(Sender: TObject);
    procedure UDHorizSizeChangeTracking(Sender: TObject);
    procedure UDVertSizeChangeTracking(Sender: TObject);
    procedure UDScopeChangeTracking(Sender: TObject);
    procedure CBScopeStyleChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBSeriesChange(Sender: TObject);
  private
    { Private declarations }
    CursorTool : TCursorTool;

    procedure EnableSnap;
    procedure EnableScope;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke;

procedure TCursorToolEditor.Button1Click(Sender: TObject);
begin
  TStrokeEditor.Edit(Self,CursorTool.Pen);
end;

procedure TCursorToolEditor.CBFollowChange(Sender: TObject);
begin
  CursorTool.FollowMouse:=CBFollow.IsChecked;
end;

procedure TCursorToolEditor.CBScopeStyleChange(Sender: TObject);
begin
  CursorTool.ScopeStyle:=TScopeCursorStyle(CBScopeStyle.ItemIndex);
end;

procedure TCursorToolEditor.CBSeriesChange(Sender: TObject);
begin
  inherited;
  EnableSnap;
  CBZ.Enabled:=CBSnap.Enabled;
end;

procedure TCursorToolEditor.CBSnapStyleChange(Sender: TObject);
begin
  CursorTool.SnapStyle:=TSnapStyle(CBSnapStyle.ItemIndex);
end;

procedure TCursorToolEditor.CBStyleChange(Sender: TObject);
begin
  CursorTool.Style:=TCursorToolStyle(CBStyle.ItemIndex);

  if (CursorTool.Style=cssScope) or (CursorTool.Style=cssScopeOnly) then
  begin
    if CursorTool.HorizSize=0 then
       UDHorizSize.Value:=20;

    if CursorTool.VertSize=0 then
       UDVertSize.Value:=20;
  end;

  EnableScope;
end;

procedure TCursorToolEditor.CBZChange(Sender: TObject);
begin
  CursorTool.UseSeriesZ:=CBZ.IsChecked
end;

procedure TCursorToolEditor.EnableScope;
begin
  UDScope.Enabled:=(CursorTool.Style=cssScope) or (CursorTool.Style=cssScopeOnly);
end;

procedure TCursorToolEditor.EnableSnap;
begin
  CBSnap.Enabled:=Assigned(CursorTool) and Assigned(CursorTool.Series);
  CBSnapStyle.Enabled:=CBSnap.Enabled and CursorTool.Snap;
end;

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

  if not Assigned(CursorTool) then
  begin
    CursorTool:=TCursorTool(Tool);

    if Assigned(CursorTool) then
    With CursorTool do
    begin
      CBStyle.ItemIndex:=Ord(Style);
      CBSnap.IsChecked:=Snap;
      CBSnapStyle.ItemIndex:=Ord(SnapStyle);
      CBZ.IsChecked:=UseSeriesZ;
      CBZ.Enabled:=CBSnap.Enabled;
      CBFollow.IsChecked:=FollowMouse;

      UDClick.Value:=ClickTolerance;
      UDHorizSize.Value:=HorizSize;
      UDVertSize.Value:=VertSize;
      UDScope.Value:=ScopeSize;

      CBScopeStyle.ItemIndex:=Ord(ScopeStyle);

      EnableSnap;
      EnableScope;
    end;
  end;
end;

procedure TCursorToolEditor.UDClickChangeTracking(Sender: TObject);
begin
  UDClickTyping(Self);
end;

procedure TCursorToolEditor.UDClickTyping(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.ClickTolerance:=Round(UDClick.Value);
end;

procedure TCursorToolEditor.UDHorizSizeChangeTracking(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.HorizSize:=Round(UDHorizSize.Value);
end;

procedure TCursorToolEditor.UDScopeChangeTracking(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.ScopeSize:=Round(UDScope.Value);
end;

procedure TCursorToolEditor.UDVertSizeChangeTracking(Sender: TObject);
begin
  if Assigned(CursorTool) then
     CursorTool.VertSize:=Round(UDVertSize.Value);
end;

initialization
  RegisterSeriesEditor(TCursorToolEditor);
end.
