unit dlgSetTexteAttributs;
{$INCLUDE CompilationParameters.inc}
interface

uses
  {$INCLUDE SelectionLangues.inc} // insère les unités en fonction de la langue
  StructuresDonnees, GHTopoGeneralFunctions, unitDatesUtils, unitGHTopoViseesUtils, unitGHTopoStringUtils,  unitColorsUtils, unitSolveEquationsPolynomes,  Classes, SysUtils, Math, // anciennement Include
  FileUtil, curredit, Forms, Controls,
  Graphics, Dialogs, StdCtrls, EditBtn, Buttons;

type

  { TfrmSelectTexteAttributs }

  TfrmSelectTexteAttributs = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    btnFontColor: TColorButton;
    btnBackColor: TColorButton;
    chkBold: TCheckBox;
    chkItalic: TCheckBox;
    chkUnderline: TCheckBox;
    editHauteurTexteInPX: TCurrencyEdit;
    editHauteurTexteInMM: TCurrencyEdit;
    editFontName: TEdit;
    editAngleRot: TCurrencyEdit;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    RadioButton6: TRadioButton;
    RadioButton7: TRadioButton;
    RadioButton8: TRadioButton;
    RadioButton9: TRadioButton;
  private
    { private declarations }

  public
    { public declarations }
    function  Initialiser(const AT: TTexteAttributs): boolean;
    function  GetTexteAttributs(): TTexteAttributs;
  end;

var
  frmSelectTexteAttributs: TfrmSelectTexteAttributs;

implementation

{$R *.lfm}

{ TfrmSelectTexteAttributs }

function TfrmSelectTexteAttributs.Initialiser(const AT: TTexteAttributs): boolean;
begin
  result := false;
  RadioButton1.Checked     := True;
  editFontName.Text        := AT.FontName;
  btnFontColor.ButtonColor := AT.FontColor.toTColor();
  btnBackColor.ButtonColor := AT.BackColor.toTColor();
  editHauteurTexteInPX.AsInteger   := AT.HauteurTexteInPx;
  editHauteurTexteInMM.Value       := AT.HauteurTexteInMM;
  editAngleRot.AsInteger   := AT.AngleRot;
  chkBold.Checked      := (fsBold      in AT.FontStyle);
  chkItalic.Checked    := (fsItalic    in AT.FontStyle);
  chkUnderline.Checked := (fsUnderline in AT.FontStyle);

  case AT.Alignement of
    1: RadioButton1.Checked := True;
    2: RadioButton2.Checked := True;
    3: RadioButton3.Checked := True;
    4: RadioButton4.Checked := True;
    5: RadioButton5.Checked := True;
    6: RadioButton6.Checked := True;
    7: RadioButton7.Checked := True;
    8: RadioButton8.Checked := True;
    9: RadioButton9.Checked := True;
  else
    RadioButton1.Checked := True;
  end;

  result := true;
end;

function TfrmSelectTexteAttributs.GetTexteAttributs: TTexteAttributs;
begin
  Result.FontName  := Trim(editFontName.Text);
  result.FontColor.setFrom(btnFontColor.ButtonColor, 255);
  Result.BackColor.setFrom(btnBackColor.ButtonColor, 255);
  Result.HauteurTexteInMM := editHauteurTexteInMM.Value;
  Result.HauteurTexteInPx := editHauteurTexteInPX.AsInteger;

  Result.AngleRot     := editAngleRot.AsInteger;
  Result.FontStyle := [];
  if (chkBold.Checked)      then Result.FontStyle := Result.FontStyle + [fsBold];
  if (chkItalic.Checked)    then Result.FontStyle := Result.FontStyle + [fsItalic];
  if (chkUnderline.Checked) then Result.FontStyle := Result.FontStyle + [fsUnderline];
  if      (RadioButton1.Checked = True) then Result.Alignement := 1
  else if (RadioButton2.Checked = True) then Result.Alignement := 2
  else if (RadioButton3.Checked = True) then Result.Alignement := 3
  else if (RadioButton4.Checked = True) then Result.Alignement := 4
  else if (RadioButton5.Checked = True) then Result.Alignement := 5
  else if (RadioButton6.Checked = True) then Result.Alignement := 6
  else if (RadioButton7.Checked = True) then Result.Alignement := 7
  else if (RadioButton8.Checked = True) then Result.Alignement := 8
  else if (RadioButton9.Checked = True) then Result.Alignement := 9
  else Result.Alignement := 0;
end;

end.

