{**********************************************}
{   TArrowTool and editor dialog               }
{   Copyright (c) 2000-2020 by Steema Software }
{**********************************************}
unit TeeArrowToolEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,

  Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,

  {$IFDEF D6}
  Types,
  {$ENDIF}
  TeeArrowTool;

type
  TArrowToolEditor = class(TForm)
    PageControl1: TPageControl;
    TabPosition: TTabSheet;
    TabSheet2: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label5: TLabel;
    TBWidth: TTrackBar;
    TBHeight: TTrackBar;
    TBPercent: TTrackBar;
    Label6: TLabel;
    EFromX: TEdit;
    UDFromX: TUpDown;
    Label8: TLabel;
    EFromY: TEdit;
    UDFromY: TUpDown;
    Label7: TLabel;
    EToX: TEdit;
    UDToX: TUpDown;
    Label9: TLabel;
    EToY: TEdit;
    UDToY: TUpDown;
    TabBorder: TTabSheet;
    TabPattern: TTabSheet;
    TabSheet3: TTabSheet;
    Label3: TLabel;
    TBAngle: TTrackBar;
    CBDraw2D: TCheckBox;
    Label4: TLabel;
    TBZ: TTrackBar;
    Label10: TLabel;
    TBTransp: TTrackBar;
    CBFilled: TCheckBox;
    CBRotateGradient: TCheckBox;
    procedure TBWidthChange(Sender: TObject);
    procedure TBHeightChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CBFilledClick(Sender: TObject);
    procedure TBAngleChange(Sender: TObject);
    procedure TBZChange(Sender: TObject);
    procedure TBPercentChange(Sender: TObject);
    procedure CBDraw2DClick(Sender: TObject);
    procedure EFromXChange(Sender: TObject);
    procedure EFromYChange(Sender: TObject);
    procedure EToXChange(Sender: TObject);
    procedure EToYChange(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBRotateGradientClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    Arrow : TArrowTool;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  Math, TeePenDlg, TeeBrushDlg;

{ TArrowToolEditor }
procedure TArrowToolEditor.TBWidthChange(Sender: TObject);
begin
  Arrow.Width:=TBWidth.Position;
end;

procedure TArrowToolEditor.TBHeightChange(Sender: TObject);
begin
  Arrow.Height:=TBHeight.Position;
end;

procedure TArrowToolEditor.FormShow(Sender: TObject);
begin
  Arrow:=TArrowTool(Tag);

  if Assigned(Arrow) then
  begin
    CBFilled.Checked:=Arrow.Filled;
    TBWidth.Position:=Arrow.Width;
    TBHeight.Position:=Arrow.Height;
    TBAngle.Position:=Round(Arrow.Angle);
    TBZ.Position:=Arrow.Z;
    TBPercent.Position:=Round(Arrow.Percent);
    CBDraw2D.Checked:=Arrow.Draw2D;

    CBRotateGradient.Checked:=Arrow.RotateGradient;

    UDFromX.Position:=Arrow.FromPoint.X;
    UDFromY.Position:=Arrow.FromPoint.Y;
    UDToX.Position:=Arrow.ToPoint.X;
    UDToY.Position:=Arrow.ToPoint.Y;

    TBTransp.Position:=Arrow.Transparency;
  end;
end;

procedure TArrowToolEditor.CBFilledClick(Sender: TObject);
begin
  Arrow.Filled:=CBFilled.Checked;
end;

procedure TArrowToolEditor.TBAngleChange(Sender: TObject);
begin
  Arrow.Angle:=TBAngle.Position;
end;

procedure TArrowToolEditor.TBZChange(Sender: TObject);
begin
  Arrow.Z:=TBZ.Position;
end;

procedure TArrowToolEditor.TBPercentChange(Sender: TObject);
begin
  Arrow.Percent:=TBPercent.Position;
end;

procedure TArrowToolEditor.CBDraw2DClick(Sender: TObject);
begin
  Arrow.Draw2D:=CBDraw2D.Checked;
end;

procedure TArrowToolEditor.EFromXChange(Sender: TObject);
begin
  if Showing then
     Arrow.FromPoint.X:=UDFromX.Position;
end;

procedure TArrowToolEditor.EFromYChange(Sender: TObject);
begin
  if Showing then
     Arrow.FromPoint.Y:=UDFromY.Position;
end;

procedure TArrowToolEditor.EToXChange(Sender: TObject);
begin
  if Showing then
     Arrow.ToPoint.X:=UDToX.Position;
end;

procedure TArrowToolEditor.EToYChange(Sender: TObject);
begin
  if Showing then
     Arrow.ToPoint.Y:=UDToY.Position;
end;

procedure TArrowToolEditor.TBTranspChange(Sender: TObject);
begin
  Arrow.Transparency:=TBTransp.Position;
end;

procedure TArrowToolEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(Arrow.Pen,TabBorder)
  else
  if (PageControl1.ActivePage=TabPattern) and (TabPattern.ControlCount=0) then
     TBrushDialog.AddDialog(Arrow.Brush,TabPattern);
end;

procedure TArrowToolEditor.CBRotateGradientClick(Sender: TObject);
begin
  Arrow.RotateGradient:=CBRotateGradient.Checked;
end;

procedure TArrowToolEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActivePage:=TabPosition;
end;

initialization
  RegisterClass(TArrowToolEditor);
end.
