unit Vis3D_SurfaceSettings;

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_SurfaceSettingsFrm = class(TDrawableOptionsFrm3D)
    btnApply: TUxButton;
    ScrollBox1: TScrollBoxEx;
    lblColor: TLabel;
    lblLineWidth: TLabel;
    cbShowSurface: TCheckBox;
    pnTransforms: TPanel;
    Label6: TLabel;
    ccColor: TColorContainer;
    eLineWidth: TTextEditor;
    lblPCColor: TLabel;
    ccPCColor: TColorContainer;
    cbShowPCs: TCheckBox;
    lblCounts: TLabel;
    ePCCx: TTextEditor;
    ePCCy: TTextEditor;
    cbBidirLight: TCheckBox;
    procedure btnApplyClick(Sender: TObject);
    procedure ccColorChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  strict private
    FTransforms: TVis3D_GeoObjSettingsFrm;
  public
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  end;

implementation

{$R *.dfm}

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

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

procedure TVis3D_SurfaceSettingsFrm.FormCreate(Sender: TObject);
begin

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

end;

procedure TVis3D_SurfaceSettingsFrm.Initialize;
begin
  inherited;
  var Obj := FDrawable as TAbstractSurface3D;
  cbShowSurface.Checked := Obj.ShowSurface;
  cbShowPCs.Checked := Obj.ShowParameterCurves;
  cbBidirLight.Checked := Obj.Unisided;
  if Obj.ColorNotApplicable then
  begin
    lblColor.Enabled := False;
    ccColor.Enabled := False;
    lblPCColor.Enabled := False;
    ccPCColor.Enabled := False;
  end
  else
  begin
    ccColor.Color := Obj.Color;
    ccPCColor.Color := Obj.LineColor;
  end;
  eLineWidth.PlainText := FormatFloat('0.###', Obj.LineWidth);
  ePCCx.PlainText := Obj.ParamCurveCounts.nx.ToString;
  ePCCy.PlainText := Obj.ParamCurveCounts.ny.ToString;
end;

procedure TVis3D_SurfaceSettingsFrm.UpdateDrawable;
begin
  if not FInitialized then
    Exit;
  var Obj := FDrawable as TAbstractSurface3D;
  Obj.ShowSurface := cbShowSurface.Checked;
  Obj.ShowParameterCurves := cbShowPCs.Checked;
  Obj.Unisided := cbBidirLight.Checked;
  Obj.Color := ccColor.Color;
  Obj.LineColor := ccPCColor.Color;
  Obj.LineWidth := StrToFloat(eLineWidth.PlainText);
  Obj.ParamCurveCounts :=
    TParamCurveFamilySize.Create(StrToInt(ePCCx.PlainText), StrToInt(ePCCy.PlainText));
  if Assigned(FTransforms) then
    FTransforms.UpdateDrawable;
  inherited;
end;

end.
