unit FMXTee.Editor.Tools.Nearest;

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.ListBox, FMX.Edit, FMXTee.Tools;

type
  TNearestToolEdit = class(TSeriesToolEditor)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label2: TLabel;
    UDSize: TComboTrackBar;
    Label3: TLabel;
    CBStyle: TComboBox;
    CBFull: TCheckBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    procedure CBFullChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure UDSizeChangeTracking(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    Nearest : TNearestTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Editor.Brush;

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

procedure TNearestToolEdit.Button2Click(Sender: TObject);
begin
  TBrushEditor.Edit(Self, Nearest.Brush);
end;

procedure TNearestToolEdit.Button3Click(Sender: TObject);
begin
  TStrokeEditor.Edit(Self, Nearest.LinePen);
end;

procedure TNearestToolEdit.CBFullChange(Sender: TObject);
begin
  Nearest.FullRepaint:=CBFull.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;
    end;
  end;
end;

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

initialization
  RegisterSeriesEditor(TNearestToolEdit);
end.
