unit Trans1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, OpenGL;

type
  TFormTransform = class(TForm)
    CheckBoxTranslate: TCheckBox;
    CheckBoxScale: TCheckBox;
    CheckBoxRotate: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    EditTX: TEdit;
    EditTY: TEdit;
    EditTZ: TEdit;
    EditSX: TEdit;
    EditSY: TEdit;
    EditSZ: TEdit;
    EditRX: TEdit;
    EditRY: TEdit;
    EditRZ: TEdit;
    EditRA: TEdit;
    RadioGroupT: TRadioGroup;
    RadioGroupS: TRadioGroup;
    RadioGroupR: TRadioGroup;
    BitBtnOK: TBitBtn;
    BitBtn2: TBitBtn;
    procedure CheckBoxTranslateClick(Sender: TObject);
    procedure CheckBoxScaleClick(Sender: TObject);
    procedure CheckBoxRotateClick(Sender: TObject);
    procedure BitBtnOKClick(Sender: TObject);
    procedure RadioGroupClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormTransform: TFormTransform;
  transData: record
    translate,
    scale,
    rotate: boolean;
    orT,
    orS,
    orR: char;
    tx,ty,tz,
    sx,sy,sz,
    rx,ry,rz,ra: GLfloat;
  end;

implementation

{$R *.DFM}

procedure TFormTransform.CheckBoxTranslateClick(Sender: TObject);
var
  chck: boolean;
begin
  with Sender as TCheckBox do
    chck := checked;
  EditTX.Enabled := chck;
  EditTY.Enabled := chck;
  EditTZ.Enabled := chck;
  RadioGroupT.Enabled := chck;
  BitBtnOk.Enabled := chck
  or EditSX.Enabled
  or EditRX.Enabled;
end;

procedure TFormTransform.CheckBoxScaleClick(Sender: TObject);
var
  chck: boolean;
begin
  with Sender as TCheckBox do
    chck := checked;
  EditSX.Enabled := chck;
  EditSY.Enabled := chck;
  EditSZ.Enabled := chck;
  RadioGroupS.Enabled := chck;
  BitBtnOk.Enabled := chck
  or EditTX.Enabled
  or EditRX.Enabled;
end;

procedure TFormTransform.CheckBoxRotateClick(Sender: TObject);
var
  chck: boolean;
begin
  with Sender as TCheckBox do
    chck := checked;
  EditRX.Enabled := chck;
  EditRY.Enabled := chck;
  EditRZ.Enabled := chck;
  EditRA.Enabled := chck;
  RadioGroupR.Enabled := chck;
  BitBtnOk.Enabled := chck
  or EditSX.Enabled
  or EditTX.Enabled;
end;

procedure TFormTransform.BitBtnOKClick(Sender: TObject);
begin
  ModalResult := mrNone;

  with transData do
  begin
    translate := checkBoxTranslate.Checked;
    scale := checkBoxScale.Checked;
    rotate := checkBoxRotate.Checked;

    if translate then
    begin
      tx := StrToFloat(EditTX.Text);
      ty := StrToFloat(EditTY.Text);
      tz := StrToFloat(EditTZ.Text);
    end;

    if scale then
    begin
      sx := StrToFloat(EditSX.Text);
      sy := StrToFloat(EditSY.Text);
      sz := StrToFloat(EditSZ.Text);
    end;

    if rotate then
    begin
      rx := StrToFloat(EditRX.Text);
      ry := StrToFloat(EditRY.Text);
      rz := StrToFloat(EditRZ.Text);
      ra := StrToFloat(EditRA.Text);
    end;

    orT := char(48+RadioGroupT.ItemIndex);
    orS := char(48+RadioGroupS.ItemIndex);
    orR := char(48+RadioGroupR.ItemIndex);
  end; {with}

  ModalResult := mrOk;
end;

procedure TFormTransform.RadioGroupClick(Sender: TObject);
type
  TRange=0..2;
  SRange=Set of TRange;
var
  ch: char;
  Xii,
  Uii,
  Tii,
  Sii,
  Rii: integer;
  Used: SRange;
  ar: array['R'..'T'] of TRadioGroup;
  notif: TNotifyEvent;
begin
  {build set of used values to find what's left}
  Tii := RadioGroupT.ItemIndex;
  Sii := RadioGroupS.ItemIndex;
  Rii := RadioGroupR.ItemIndex;
  Used := [Tii]+[Sii]+[Rii];
  Xii := TRadioGroup(Sender).ItemIndex;

  {build array of rg for convenient searching}
  ar['T'] := RadioGroupT;
  ar['S'] := RadioGroupS;
  ar['R'] := RadioGroupR;

  {find rg not the sender but with same ItemIndex}
  for ch := 'R' to 'T' do
  with ar[ch] do
  if (ar[ch]<>Sender) and (ItemIndex=Xii) then
  begin
    for Uii := 0 to 2 do
    if not (Uii in Used) then
    begin
      notif := OnClick;
      OnClick := nil; {prevent second triggering}

      {set to unused ItemIndex and leave}
      ar[ch].ItemIndex := Uii;
      OnClick := notif;
      exit;
    end; {for if}
  end; {for with if}

end;

end.
