unit Vis3D_CylinderSettings;

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;

type
  TVis3D_CylinderSettingsFrm = class(TDrawableOptionsFrm3D)
    pnGeneral: TPanel;
    pnToolbar: TUxClient;
    btnCylinder: TUxButton;
    btnGeneral: TUxButton;
    pnCylinder: TPanel;
    lblInnerRadius: TLabel;
    eInnerRadius: TTextEditor;
    eAngle: TTextEditor;
    lblAngle: TLabel;
    lblParameters: TLabel;
    lblPercent: TLabel;
    lblDegrees: TLabel;
    btnApply: TUxButton;
    procedure btnApplyClick(Sender: TObject);
    procedure SetPage(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  strict private
    FPageButtons: TArray<TUxButton>;
    FGeneral: TDrawableOptionsFrm3D;
  public
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  end;

implementation

{$R *.dfm}

uses
  Vis3D_AxisSettings, Vis3D_GeoObjSettings;

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

procedure TVis3D_CylinderSettingsFrm.FormCreate(Sender: TObject);
begin

  var Cylinder := FDrawable as TSolidCylinder;

  btnGeneral.Tag := NativeInt(pnGeneral);
  btnCylinder.Tag := NativeInt(pnCylinder);
  FPageButtons := [btnGeneral, btnCylinder];

  SetPage(btnGeneral);

  FGeneral := TVis3D_GeoObjSettingsFrm.Create(Self, Cylinder);
  (FGeneral as TVis3D_GeoObjSettingsFrm).Customize(True, True, True);
  FGeneral.Parent := pnGeneral;
  FGeneral.BorderStyle := bsNone;
  FGeneral.Align := alClient;
  FGeneral.Show;

end;

procedure TVis3D_CylinderSettingsFrm.Initialize;
begin
  inherited;
  var Cylinder := FDrawable as TSolidCylinder;
  eInnerRadius.PlainText := FormatFloat('0.###', 100.0 * Cylinder.InnerRadiusFraction);
  eAngle.PlainText := FormatFloat('0.###', Cylinder.Angle);
end;

procedure TVis3D_CylinderSettingsFrm.SetPage(Sender: TObject);
begin
  for var B in FPageButtons do
  begin
    if B.Tag = 0 then
      Continue;
    var P := TObject(B.Tag) as TWinControl;
    P.Align := alClient;
    P.Visible := B = Sender;
    B.Down := B = Sender;
    if (B = Sender) and Visible and P.Visible and P.CanFocus then
      P.SetFocus;
  end;
  btnApply.Visible := pnCylinder.Visible;
end;

procedure TVis3D_CylinderSettingsFrm.UpdateDrawable;
begin
  if not FInitialized then
    Exit;
  var Cylinder := FDrawable as TSolidCylinder;
  Cylinder.InnerRadiusFraction := StrToFloat(eInnerRadius.PlainText) / 100.0;
  Cylinder.Angle := StrToFloat(eAngle.PlainText);
  inherited;
end;

end.
