unit TrRotation;

interface

uses
	Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
	StdCtrls, FormUtils, Mask, Geomet, GraphicComponents;

type
	TTrRotationForm = class(TExForm)
		Label1: TLabel;
		GradAngle: TMaskEdit;
		RadAngle: TFloatEdit;
		Ok: TButton;
		Cancel: TButton;
		ComboBox: TComboBox;
		procedure ComboBoxChange(Sender: TObject);
		procedure RadAngleChange(Sender: TObject);
		procedure GradAngleChange(Sender: TObject);
	private
		FAngle: Double;

		procedure SetAngle(const Value: Double);
	public
		property Angle: Double read FAngle write SetAngle;
	end;


function DoEditAngle(anOwner: TComponent; var anAngle: Double): Boolean;

implementation

{$R *.DFM}

function DoEditAngle(anOwner: TComponent; var anAngle: Double): Boolean;
var
	aForm: TTrRotationForm;
begin
	aForm := TTrRotationForm.Create(anOwner);
	try
		aForm.Angle := anAngle;
		Result := aForm.ShowModal = mrOk;
		if Result then
			anAngle := aForm.Angle;
	finally
    aForm.Free;
	end;
end;

{ TTrRotationForm }

procedure TTrRotationForm.SetAngle(const Value: Double);
begin
	if ComboBox.ItemIndex = 0 then
		GradAngle.Text := AngleToStr(Value, True)
	else
		RadAngle.Value := Value;

	FAngle := Value;	
end;

procedure TTrRotationForm.ComboBoxChange(Sender: TObject);
begin
	if ComboBox.ItemIndex = 0 then begin
		GradAngle.Visible := True;
		GradAngle.BringToFront;
		RadAngle.Visible := False;
	end else begin
		RadAngle.Visible := True;
		RadAngle.BringToFront;
		GradAngle.Visible := False;
	end;
	Angle := FAngle;
end;

procedure TTrRotationForm.RadAngleChange(Sender: TObject);
begin
	FAngle := RadAngle.Value;
end;

procedure TTrRotationForm.GradAngleChange(Sender: TObject);
begin
	FAngle := StrToAngle(StringReplace(GradAngle.Text, ' ', '0', [rfReplaceAll, rfIgnoreCase]));
end;

end.
