unit Vis3D_ArrowSettings;

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_ArrowSettingsFrm = class(TDrawableOptionsFrm3D)
    btnApply: TUxButton;
    ScrollBox1: TScrollBoxEx;
    lblColor: TLabel;
    lblLineWidth: TLabel;
    Label6: TLabel;
    ccColor: TColorContainer;
    eLineWidth: TTextEditor;
    lblHeadSize: TLabel;
    Label2: TLabel;
    eHeadSize: TTextEditor;
    lblAspect: TLabel;
    eAspect: TTextEditor;
    lblPos: TLabel;
    ePosX: TTextEditor;
    ePosY: TTextEditor;
    ePosZ: TTextEditor;
    eVectorX: TTextEditor;
    eVectorY: TTextEditor;
    eVectorZ: TTextEditor;
    lblVector: TLabel;
    procedure btnApplyClick(Sender: TObject);
    procedure ccColorChange(Sender: TObject);
  public
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  end;

implementation

{$R *.dfm}

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

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

procedure TVis3D_ArrowSettingsFrm.Initialize;
begin
  inherited;
  var Obj := FDrawable as TArrow;
  ccColor.Color := Obj.Color;
  eLineWidth.PlainText := FormatFloat('0.####', Obj.LineWidth);
  eHeadSize.PlainText := FormatFloat('0.####', Obj.HeadSize);
  eAspect.PlainText := FormatFloat('0.####', Obj.Aspect);
  ePosX.PlainText := FormatFloat('0.######', Obj.Position.x);
  ePosY.PlainText := FormatFloat('0.######', Obj.Position.y);
  ePosZ.PlainText := FormatFloat('0.######', Obj.Position.z);
  eVectorX.PlainText := FormatFloat('0.######', Obj.Vector.x);
  eVectorY.PlainText := FormatFloat('0.######', Obj.Vector.y);
  eVectorZ.PlainText := FormatFloat('0.######', Obj.Vector.z);
end;

procedure TVis3D_ArrowSettingsFrm.UpdateDrawable;
begin
  if not FInitialized then
    Exit;
  var Obj := FDrawable as TArrow;
  Obj.Color := ccColor.Color;
  Obj.LineWidth := StrToFloat(eLineWidth.PlainText);
  Obj.HeadSize := StrToFloat(eHeadSize.PlainText);
  Obj.Aspect := StrToFloat(eAspect.PlainText);
  Obj.Position := vec(
    StrToFloat(ePosX.PlainText),
    StrToFloat(ePosY.PlainText),
    StrToFloat(ePosZ.PlainText)
  );
  Obj.Vector := vec(
    StrToFloat(eVectorX.PlainText),
    StrToFloat(eVectorY.PlainText),
    StrToFloat(eVectorZ.PlainText)
  );
  inherited;
end;

end.
