{**********************************************}
{   TRotateTool Editor                         }
{   Copyright (c) 1999-2020 by Steema Software }
{**********************************************}
unit TeeRotateToolEditor;
{$I TeeDefs.inc}

interface

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

     Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons,

     TeeTools, TeeProcs, TeCanvas, TeePenDlg;

type
  TRotateToolEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    LabelInertia: TLabel;
    CBInverted: TCheckBox;
    CBStyle: TComboFlat;
    CBButton: TComboFlat;
    ESpeed: TEdit;
    UDSpeed: TUpDown;
    SBInertia: TScrollBar;
    Label6: TLabel;
    CBCursor: TComboFlat;
    GroupBox1: TGroupBox;
    ImageCursor: TImage;
    SpeedButton1: TSpeedButton;
    TabOutline: TTabSheet;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CBInvertedClick(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBButtonChange(Sender: TObject);
    procedure ESpeedChange(Sender: TObject);
    procedure SBInertiaChange(Sender: TObject);
    procedure CBCursorChange(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    Tool : TRotateTool;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeeMouseCursor;
  
procedure TRotateToolEditor.FormCreate(Sender: TObject);
begin
  Align:=alClient;
  PageControl1.ActivePage:=TabSheet1;
end;

procedure TRotateToolEditor.FormShow(Sender: TObject);
begin
  Tool:=TRotateTool(Tag);

  if Assigned(Tool) then
  with Tool do
  begin
    CBInverted.Checked:=Inverted;
    CBStyle.ItemIndex:=Ord(Style);

    case Button of
      mbLeft: CBButton.ItemIndex:=0;
      mbMiddle: CBButton.ItemIndex:=1;
    else
      CBButton.ItemIndex:=2;
    end;

    UDSpeed.Position:=Speed;
    SBInertia.Position:=Inertia;

    TeeFillCursors(CBCursor,Cursor);
    TeePreviewCursor(Cursor,ImageCursor.Picture);
  end;
end;

procedure TRotateToolEditor.CBInvertedClick(Sender: TObject);
begin
  Tool.Inverted:=CBInverted.Checked;
end;

procedure TRotateToolEditor.CBStyleChange(Sender: TObject);
begin
  Tool.Style:=TRotateToolStyles(CBStyle.ItemIndex);
end;

procedure TRotateToolEditor.CBButtonChange(Sender: TObject);
begin
  Case CBButton.ItemIndex of
    0: Tool.Button:=mbLeft;
    1: Tool.Button:=mbMiddle;
  else
    Tool.Button:=mbRight;
  end;
end;

procedure TRotateToolEditor.ESpeedChange(Sender: TObject);
begin
  if Assigned(Tool) then
     Tool.Speed:=UDSpeed.Position;
end;

procedure TRotateToolEditor.SBInertiaChange(Sender: TObject);
begin
  Tool.Inertia:=SBInertia.Position;
  LabelInertia.Caption:=IntToStr(Tool.Inertia);
end;

procedure TRotateToolEditor.CBCursorChange(Sender: TObject);
begin
  with Tool do
  begin
    Cursor:=TeeSetCursor(Cursor,CBCursor.CurrentItem);
    TeePreviewCursor(Cursor,ImageCursor.Picture);
  end;
end;

procedure TRotateToolEditor.SpeedButton1Click(Sender: TObject);
begin
  Tool.Cursor:=TMouseCursorEdit.Choose(Tool,Tool.Cursor);
end;

procedure TRotateToolEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabOutline) and (TabOutline.ControlCount=0) then
     TPenDialog.InsertForm(Tool.Pen,TabOutline);
end;

initialization
  RegisterClass(TRotateToolEditor);
end.
