unit Vis2D_GridFamiliesSettings;

interface

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

type
  TVis2D_GridFamiliesSettingsFrm = class(TDrawableOptionsFrm)
    pnClient: TPanel;
    UxClient1: TUxClient;
    cbFamilies: TComboBox;
    procedure cbFamiliesChange(Sender: TObject);
  strict protected
    Families: TGridLineFamilies;
    Frm: TDrawableOptionsFrm;
    procedure Initialize; override;
  public

  end;

implementation

{$R *.dfm}

{ TVis2D_GridFamiliesSettingsFrm }

procedure TVis2D_GridFamiliesSettingsFrm.cbFamiliesChange(Sender: TObject);
var
  GridLineFamily: TGridLineFamily;
begin

  if cbFamilies.ItemIndex <> -1 then
  begin
    GridLineFamily := cbFamilies.Items.Objects[cbFamilies.ItemIndex] as TGridLineFamily;
    if Frm = nil then
    begin
      Frm := GridLineFamily.OptionsFormClass.Create(Self, GridLineFamily);
      Frm.Parent := pnClient;
      Frm.BorderStyle := bsNone;
      Frm.Align := alClient;
      Frm.ScaleForPPI(Self.CurrentPPI);
      Frm.Show;
    end
    else
      Frm.Reassign(GridLineFamily)
  end;

end;

procedure TVis2D_GridFamiliesSettingsFrm.Initialize;

  procedure AddFamily(AFamily: TGridLineFamily);
  begin
    cbFamilies.Items.AddObject(AFamily.Name, AFamily)
  end;

begin

  inherited;

  Families := FDrawable as TGridLineFamilies;

  cbFamilies.Items.BeginUpdate;
  try
    cbFamilies.Clear;
    AddFamily(Families.HorizontalPrimary);
    AddFamily(Families.HorizontalSecondary);
    AddFamily(Families.VerticalPrimary);
    AddFamily(Families.VerticalSecondary);
    AddFamily(Families.RadialPrimary);
    AddFamily(Families.RadialSecondary);
    AddFamily(Families.Circular);
  finally
    cbFamilies.Items.EndUpdate;
  end;

  cbFamilies.ItemIndex := 0;
  cbFamiliesChange(Self);

end;

end.
