unit Vis2D_PieChartSettings;

interface

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

type
  TVis2D_PieChartSettingsFrm = class(TDrawableOptionsFrm)
    btnApply: TUxButton;
    ScrollBox1: TScrollBoxEx;
    Label9: TLabel;
    eRadius: TTextEditor;
    eStartAngle: TTextEditor;
    Label7: TLabel;
    Label8: TLabel;
    eOriginX: TTextEditor;
    eOriginY: TTextEditor;
    procedure ScrollBox1Enter(Sender: TObject);
    procedure ScrollBox1Exit(Sender: TObject);
    procedure btnApplyClick(Sender: TObject);
    procedure CallUpdateDrawable(Sender: TObject);
  strict protected
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  public

  end;

implementation

uses
  Math;

{$R *.dfm}

{ TVis2D_PieChartSettingsFrm }

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

procedure TVis2D_PieChartSettingsFrm.CallUpdateDrawable(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis2D_PieChartSettingsFrm.Initialize;
var
  PieChart: TPieChart;
begin

  inherited;

  PieChart := FDrawable as TPieChart;

  eOriginX.PlainText := PieChart.Origin.X.ToString;
  eOriginY.PlainText := PieChart.Origin.Y.ToString;
  eRadius.PlainText := PieChart.Radius.ToString;
  eStartAngle.PlainText := PieChart.StartAngle.ToString;

end;

procedure TVis2D_PieChartSettingsFrm.ScrollBox1Enter(Sender: TObject);
begin
  btnApply.Default := True;
end;

procedure TVis2D_PieChartSettingsFrm.ScrollBox1Exit(Sender: TObject);
begin
  btnApply.Default := False;
end;

procedure TVis2D_PieChartSettingsFrm.UpdateDrawable;
var
  PieChart: TPieChart;
begin

  if not Initialized then
    Exit;

  PieChart := FDrawable as TPieChart;

  PieChart.Origin := TPointD.Create(StrToFloat(eOriginX.PlainText), StrToFloat(eOriginY.PlainText));
  PieChart.Radius := StrToFloat(eRadius.PlainText);
  PieChart.StartAngle := StrToFloat(eStartAngle.PlainText);

  inherited;

end;

end.
