{**********************************************}
{   TNearestToolEditor                         }
{   Copyright (c) 1999-2020 by Steema Software }
{**********************************************}
unit TeeNearestToolEditor;
{$I TeeDefs.inc}

interface

uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,

     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons,

     TeeToolSeriesEdit, TeeProcs, TeCanvas, TeEngine, TeePenDlg, TeeTools;

type
  TNearestToolEdit = class(TSeriesToolEditor)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabBorder: TTabSheet;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    UDSize: TUpDown;
    CBStyle: TComboFlat;
    CBFull: TCheckBox;
    Edit2: TEdit;
    UDDistance: TUpDown;
    CBShowHint: TCheckBox;
    CBHintStyle: TComboFlat;
    TabLine: TTabSheet;
    TabPattern: TTabSheet;
    procedure FormShow(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBFullClick(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure CBShowHintClick(Sender: TObject);
    procedure CBHintStyleChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    Nearest : TNearestTool;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  TeeBrushDlg, TeeEdiSeri;

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

  TFormTeeSeries.FillMarksStyle(CBHintStyle.Items);

  Nearest:=TNearestTool(Tag);

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

procedure TNearestToolEdit.Edit1Change(Sender: TObject);
begin
  if Showing then Nearest.Size:=UDSize.Position;
end;

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

procedure TNearestToolEdit.CBFullClick(Sender: TObject);
begin
  Nearest.FullRepaint:=CBFull.Checked;
end;

procedure TNearestToolEdit.Edit2Change(Sender: TObject);
begin
  if Showing then
     Nearest.Distance:=UDDistance.Position;
end;

procedure TNearestToolEdit.CBShowHintClick(Sender: TObject);
begin
  Nearest.Hint:=CBShowHint.Checked;
end;

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

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

  if PageControl1.ActivePage.ControlCount=0 then
     if PageControl1.ActivePage=TabBorder then
        TPenDialog.InsertForm(Tool.Pen,TabBorder)
     else
     if PageControl1.ActivePage=TabLine then
        TPenDialog.InsertForm(Nearest.LinePen,TabLine)
     else
     if PageControl1.ActivePage=TabPattern then
        TBrushDialog.AddDialog(Nearest.Brush,TabPattern);
end;

initialization
  RegisterClass(TNearestToolEdit);
end.
