unit Vis2D_GridSettings;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ColorContainer, Vcl.StdCtrls,
  TextEditor, UxPanel, VisCtl2D, ScrollBoxEx;

type
  TVis2D_GridSettingsFrm = class(TDrawableOptionsFrm)
    btnApply: TUxButton;
    ScrollBox1: TScrollBoxEx;
    lblGridName: TLabel;
    Label1: TLabel;
    lblRangeFrom: TLabel;
    lblRangeTo: TLabel;
    Label2: TLabel;
    Label13: TLabel;
    Label4: TLabel;
    eRangeFrom: TTextEditor;
    eRangeTo: TTextEditor;
    cbRangeUnlimited: TCheckBox;
    cbVisible: TCheckBox;
    ccGrid: TColorContainer;
    eWidth: TTextEditor;
    Label3: TLabel;
    lblLinesBegin: TLabel;
    lblLinesEnd: TLabel;
    eLinesBegin: TTextEditor;
    eLinesEnd: TTextEditor;
    cbLinesUnlimited: TCheckBox;
    eDistance: TTextEditor;
    Label5: TLabel;
    procedure CallUpdateDrawable(Sender: TObject);
    procedure ScrollBox1Enter(Sender: TObject);
    procedure ScrollBox1Exit(Sender: TObject);
    procedure cbRangeUnlimitedClick(Sender: TObject);
    procedure cbLinesUnlimitedClick(Sender: TObject);
  strict protected
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  public
  end;

implementation

{$R *.dfm}

procedure TVis2D_GridSettingsFrm.CallUpdateDrawable(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis2D_GridSettingsFrm.cbRangeUnlimitedClick(Sender: TObject);
begin


  lblRangeFrom.Enabled := not cbRangeUnlimited.Checked;
  lblRangeTo.Enabled := not cbRangeUnlimited.Checked;
  eRangeFrom.Enabled := not cbRangeUnlimited.Checked;
  eRangeTo.Enabled := not cbRangeUnlimited.Checked;

  UpdateDrawable;

end;

procedure TVis2D_GridSettingsFrm.cbLinesUnlimitedClick(Sender: TObject);
begin

  lblLinesBegin.Enabled := not cbLinesUnlimited.Checked;
  lblLinesEnd.Enabled := not cbLinesUnlimited.Checked;
  eLinesBegin.Enabled := not cbLinesUnlimited.Checked;
  eLinesEnd.Enabled := not cbLinesUnlimited.Checked;

  UpdateDrawable;

end;

procedure TVis2D_GridSettingsFrm.Initialize;
var
  Grid: TGridLineFamily;
begin

  inherited;

  Grid := FDrawable as TGridLineFamily;

  lblGridName.Caption := Grid.Name;

  cbVisible.Checked := Grid.Visible;
  cbRangeUnlimited.Checked := not Grid.Limited;
  eRangeFrom.PlainText := Grid.AxMin.ToString;
  eRangeTo.PlainText := Grid.AxMax.ToString;
  eDistance.PlainText := Grid.Distance.ToString;
  cbLinesUnlimited.Checked := not Grid.LineLimited;
  eLinesBegin.PlainText := Grid.LineBegin.ToString;
  eLinesEnd.PlainText := Grid.LineEnd.ToString;
  eWidth.PlainText := Grid.Width.ToString;
  ccGrid.Color := Grid.Color;

end;

procedure TVis2D_GridSettingsFrm.ScrollBox1Enter(Sender: TObject);
begin
  btnApply.Default := True;
end;

procedure TVis2D_GridSettingsFrm.ScrollBox1Exit(Sender: TObject);
begin
  btnApply.Default := False;
end;

procedure TVis2D_GridSettingsFrm.UpdateDrawable;
var
  Grid: TGridLineFamily;
begin

  if not Initialized then
    Exit;

  Grid := FDrawable as TGridLineFamily;

  Grid.Visible := cbVisible.Checked;

  if cbRangeUnlimited.Checked then
  begin
    Grid.AxMin := 0.0;
    Grid.AxMax := 0.0;
  end
  else
  begin
    Grid.AxMin := StrToFloat(eRangeFrom.PlainText);
    Grid.AxMax := StrToFloat(eRangeTo.PlainText);
  end;

  Grid.Distance := StrToFloat(eDistance.PlainText);

  if cbLinesUnlimited.Checked then
  begin
    Grid.LineBegin := 0.0;
    Grid.LineEnd := 0.0;
  end
  else
  begin
    Grid.LineBegin := StrToFloat(eLinesBegin.PlainText);
    Grid.LineEnd := StrToFloat(eLinesEnd.PlainText);
  end;

  Grid.Width := StrToInt(eWidth.PlainText);
  Grid.Color := ccGrid.Color;

  inherited;

end;

end.
