unit FMXTee.Editor.Tools.SurfaceNearest;

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

type
  TSurfaceNearest = class(TSeriesToolEditor)
    Label5: TLabel;
    CBCellDefault: TCheckBox;
    CBCell: TComboColorBox;
    Label2: TLabel;
    CBRow: TComboColorBox;
    Label3: TLabel;
    CBColumn: TComboColorBox;
    CBRowDefault: TCheckBox;
    CBColumnDefault: TCheckBox;
    CBCellNone: TCheckBox;
    CBRowNone: TCheckBox;
    CBColumnNone: TCheckBox;
    procedure FormActivate(Sender: TObject);
    procedure CBCellDefaultChange(Sender: TObject);
    procedure CBRowDefaultChange(Sender: TObject);
    procedure CBColumnDefaultChange(Sender: TObject);
    procedure CBCellNoneChange(Sender: TObject);
    procedure CBRowNoneChange(Sender: TObject);
    procedure CBColumnNoneChange(Sender: TObject);
    procedure CBCellChange(Sender: TObject);
    procedure CBRowChange(Sender: TObject);
    procedure CBColumnChange(Sender: TObject);
  private
    { Private declarations }
    SurfaceNearest : TSurfaceNearestTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Engine, FMXTee.Canvas, FMXTee.Series.Surface;

procedure TSurfaceNearest.CBCellChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
  begin
    SurfaceNearest.CellColor:=CBCell.Color;
    CBCellDefault.IsChecked:=False;
    CBCellNone.IsChecked:=False;
  end;
end;

procedure TSurfaceNearest.CBCellDefaultChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
    if CBCellDefault.IsChecked then
    begin
      CBCellNone.IsChecked:=False;
      SurfaceNearest.CellColor:=clTeeColor;
    end
    else
      SurfaceNearest.CellColor:=CBCell.Color;
end;

procedure TSurfaceNearest.CBCellNoneChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
    if CBCellNone.IsChecked then
    begin
      CBCellDefault.IsChecked:=False;
      SurfaceNearest.CellColor:=clNone;
    end
    else
      SurfaceNearest.CellColor:=CBCell.Color;
end;

procedure TSurfaceNearest.CBColumnChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
  begin
    SurfaceNearest.ColumnColor:=CBColumn.Color;
    CBColumnDefault.IsChecked:=False;
    CBColumnNone.IsChecked:=False;
  end;
end;

procedure TSurfaceNearest.CBColumnDefaultChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
    if CBColumnDefault.IsChecked then
    begin
      CBColumnNone.IsChecked:=False;
      SurfaceNearest.ColumnColor:=clTeeColor;
    end
    else
      SurfaceNearest.ColumnColor:=CBColumn.Color;
end;

procedure TSurfaceNearest.CBColumnNoneChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
    if CBColumnNone.IsChecked then
    begin
      CBColumnDefault.IsChecked:=False;
      SurfaceNearest.ColumnColor:=clNone;
    end
    else
      SurfaceNearest.ColumnColor:=CBColumn.Color;
end;

procedure TSurfaceNearest.CBRowChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
  begin
    SurfaceNearest.RowColor:=CBRow.Color;
    CBRowDefault.IsChecked:=False;
    CBRowNone.IsChecked:=False;
  end;
end;

procedure TSurfaceNearest.CBRowDefaultChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
    if CBRowDefault.IsChecked then
    begin
      CBRowNone.IsChecked:=False;
      SurfaceNearest.RowColor:=clTeeColor;
    end
    else
      SurfaceNearest.RowColor:=CBRow.Color;
end;

procedure TSurfaceNearest.CBRowNoneChange(Sender: TObject);
begin
  if Assigned(SurfaceNearest) then
    if CBRowNone.IsChecked then
    begin
      CBRowDefault.IsChecked:=False;
      SurfaceNearest.RowColor:=clNone;
    end
    else
      SurfaceNearest.RowColor:=CBRow.Color;
end;

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

  if not Assigned(SurfaceNearest) then
  begin
    SurfaceNearest:=TSurfaceNearestTool(TagObject);

    if Assigned(SurfaceNearest) then
    With SurfaceNearest do
    begin
      FillSeries(CBSeries,TSurfaceSeries,Series);

      if (CellColor<>clTeeColor) and (CellColor<>clNone) then
        CBCell.Color:=CellColor;
      if (RowColor<>clTeeColor) and (RowColor<>clNone) then
        CBRow.Color:=RowColor;
      if (ColumnColor<>clTeeColor) and (ColumnColor<>clNone) then
        CBColumn.Color:=ColumnColor;

      CBCellDefault.IsChecked:=CellColor=clTeeColor;
      CBRowDefault.IsChecked:=RowColor=clTeeColor;
      CBColumnDefault.IsChecked:=ColumnColor=clTeeColor;

      CBCellNone.IsChecked:=CellColor=clNone;
      CBRowNone.IsChecked:=RowColor=clNone;
      CBColumnNone.IsChecked:=ColumnColor=clNone;
    end;
  end;
end;

initialization
  RegisterSeriesEditor(TSurfaceNearest);
end.
