unit Vis3D_AxisSettings;

interface

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

type
  TVis3D_AxisSettingsFrm = class(TDrawableOptionsFrm3D)
    btnApply: TUxButton;
    ScrollBox1: TScrollBoxEx;
    lblPosExt: TLabel;
    lblExtent: TLabel;
    pnTransforms: TPanel;
    ePosExt: TTextEditor;
    eNegExt: TTextEditor;
    lblNegExt: TLabel;
    cbLabels: TCheckBox;
    lblFont: TLabel;
    lblLabelFormat: TLabel;
    lblLabelDelta: TLabel;
    eLabelFormat: TTextEditor;
    pnLabelFont: TPanel;
    btnLabelFont: TUxButton;
    eLabelDist: TTextEditor;
    lblColor: TLabel;
    ccColor: TColorContainer;
    cbVisible: TCheckBox;
    procedure btnApplyClick(Sender: TObject);
    procedure ccColorChange(Sender: TObject);
    procedure btnLabelFontClick(Sender: TObject);
    procedure cbLabelsClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cbVisibleClick(Sender: TObject);
  strict private
    FTransforms: TVis3D_GeoObjSettingsFrm;
  public
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  end;

implementation

{$R *.dfm}

procedure TVis3D_AxisSettingsFrm.btnApplyClick(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis3D_AxisSettingsFrm.btnLabelFontClick(Sender: TObject);
begin
  with TFontDialog.Create(nil) do
    try
      Font := pnLabelFont.Font;
      if Execute then
      begin
        pnLabelFont.Font := Font;
        pnLabelFont.Caption := Format('%s, %d pt', [Font.Name, Font.Size]);
        UpdateDrawable;
      end;
    finally
      Free;
    end;
end;

procedure TVis3D_AxisSettingsFrm.cbLabelsClick(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis3D_AxisSettingsFrm.cbVisibleClick(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis3D_AxisSettingsFrm.ccColorChange(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis3D_AxisSettingsFrm.FormCreate(Sender: TObject);
begin

  FTransforms := TVis3D_GeoObjSettingsFrm.Create(Self, FDrawable);
  FTransforms.Parent := pnTransforms;
  FTransforms.BorderStyle := bsNone;
  FTransforms.Customize(False, True, False);
  FTransforms.Show;
  pnTransforms.Width := FTransforms.Width;
  pnTransforms.Height := FTransforms.Height;
  FTransforms.Align := alClient;

end;

procedure TVis3D_AxisSettingsFrm.Initialize;
begin
  inherited;
  var Obj := FDrawable as TAxis;
  cbVisible.Checked := Obj.Visible;
  ePosExt.PlainText := FormatFloat('0.00###', Obj.Length);
  eNegExt.PlainText := FormatFloat('0.00###', Obj.NegativeLength);
  ccColor.Color := Obj.Color;
  cbLabels.Checked := Obj.Labels;
  eLabelFormat.PlainText := Obj.LabelFormat;
  pnLabelFont.Font := Obj.LabelFont;
  pnLabelFont.Caption := Format('%s, %d pt', [pnLabelFont.Font.Name, pnLabelFont.Font.Size]);
  eLabelDist.PlainText := FormatFloat('0.00###', Obj.LabelDelta);
end;

procedure TVis3D_AxisSettingsFrm.UpdateDrawable;
begin
  if not FInitialized then
    Exit;
  var Obj := FDrawable as TAxis;
  Obj.Visible := cbVisible.Checked;
  Obj.Length := StrToFloat(ePosExt.PlainText);
  Obj.NegativeLength := Abs(StrToFloat(eNegExt.PlainText));
  Obj.Color := ccColor.Color;
  Obj.Labels := cbLabels.Checked;
  Obj.LabelFormat := eLabelFormat.PlainText;
  Obj.LabelFont := pnLabelFont.Font;
  Obj.LabelDelta := StrToFloat(eLabelDist.PlainText);
  if Assigned(FTransforms) then
    FTransforms.UpdateDrawable;
  inherited;
end;

end.
