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

type
  TNearestToolEdit = class(TSeriesToolEditor)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabPen: TTabItem;
    TabBrush: TTabItem;
    TabLine: TTabItem;
    Label2: TLabel;
    UDSize: TComboTrackBar;
    Label3: TLabel;
    CBStyle: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    CBFull: TCheckBox;
    Label4: TLabel;
    UDDistance: TComboTrackBar;
    CBShowHint: TCheckBox;
    CBHintStyle: TComboBox;
    procedure CBFullChange(Sender: TObject);
    procedure UDSizeChangeTracking(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure UDDistanceChangeTracking(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBShowHintChange(Sender: TObject);
    procedure CBHintStyleChange(Sender: TObject);
  private
    { Private declarations }
    Nearest : TNearestTool;

    IPen, ILine : TStrokeEditor;
    IBrush : TBrushEditor;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Engine;

procedure TNearestToolEdit.CBFullChange(Sender: TObject);
begin
  Nearest.FullRepaint:=CBFull.IsChecked;
end;

procedure TNearestToolEdit.CBHintStyleChange(Sender: TObject);
begin
  if Assigned(Nearest) then
     Nearest.HintStyle:=TSeriesMarksStyle(CBHintStyle.ItemIndex);
end;

procedure TNearestToolEdit.CBShowHintChange(Sender: TObject);
begin
  Nearest.Hint:=CBShowHint.IsChecked;
end;

procedure TNearestToolEdit.CBStyleChange(Sender: TObject);
begin
  Nearest.Style:=TNearestToolStyle(CBStyle.ItemIndex);
end;

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

  if not Assigned(Nearest) then
  begin
    Nearest:=TNearestTool(TagObject);

    if Assigned(Nearest) then
    begin
      CBStyle.ItemIndex:=Ord(Nearest.Style);
      UDSize.Value:=Nearest.Size;
      CBFull.IsChecked:=Nearest.FullRepaint;
      UDDistance.Value:=Nearest.Distance;
      CBShowHint.IsChecked:=Nearest.Hint;
      CBHintStyle.ItemIndex:=Ord(Nearest.HintStyle);
    end;
  end;
end;

procedure TNearestToolEdit.FormCreate(Sender: TObject);
begin
  inherited;
  TSeriesToolEditor.FillMarksStyle(CBHintStyle.Items);
end;

procedure TNearestToolEdit.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabPen) and (not Assigned(IPen)) then
     IPen:=TStrokeEditor.InsertForm(Nearest.Pen,TabPen)
  else
  if (TabControl1.ActiveTab=TabLine) and (not Assigned(ILine)) then
     ILine:=TStrokeEditor.InsertForm(Nearest.LinePen,TabLine)
  else
  if (TabControl1.ActiveTab=TabBrush) and (not Assigned(IBrush)) then
     IBrush:=TBrushEditor.InsertForm(Nearest.Brush,TabBrush);
end;

procedure TNearestToolEdit.UDDistanceChangeTracking(Sender: TObject);
begin
  if Assigned(Nearest) then
     Nearest.Distance:=Round(UDDistance.Value);
end;

procedure TNearestToolEdit.UDSizeChangeTracking(Sender: TObject);
begin
  if Assigned(Nearest) then
     Nearest.Size:=Round(UDSize.Value);
end;

initialization
  RegisterSeriesEditor(TNearestToolEdit);
end.
