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

interface

uses SysUtils, Classes,
     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons,
     Chart, TeeTools, TeeProcs, TeCanvas, TeePenDlg, TeeAxisToolEdit, TeeEdiGrad,
     TeeColorLineEditor;

type
  TColorBandToolEditor = class(TAxisToolEditor)
    PageControl1: TPageControl;
    TabStart: TTabSheet;
    TabOptions: TTabSheet;
    ButtonColor1: TButtonColor;
    Label4: TLabel;
    ETrans: TEdit;
    UDTrans: TUpDown;
    CBDrawBehind: TCheckBox;
    CBBeforeAxes: TCheckBox;
    Label5: TLabel;
    CBCursor: TComboFlat;
    SpeedButton1: TSpeedButton;
    TabPattern: TTabSheet;
    TabBorder: TTabSheet;
    TabEnd: TTabSheet;
    Panel1: TPanel;
    Label2: TLabel;
    EStart: TEdit;
    CBStart: TCheckBox;
    CBStartActive: TCheckBox;
    Panel2: TPanel;
    Label3: TLabel;
    EEnd: TEdit;
    CBEnd: TCheckBox;
    CBEndActive: TCheckBox;
    CBAllowDrag: TCheckBox;
    TabPicture: TTabSheet;
    CBStartAnnValue: TCheckBox;
    CBEndAnnValue: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure EStartChange(Sender: TObject);
    procedure EEndChange(Sender: TObject);
    procedure ETransChange(Sender: TObject);
    procedure CBDrawBehindClick(Sender: TObject);
    procedure CBStartClick(Sender: TObject);
    procedure CBEndClick(Sender: TObject);
    procedure CBBeforeAxesClick(Sender: TObject);
    procedure CBCursorChange(Sender: TObject);
    procedure CBStartActiveClick(Sender: TObject);
    procedure CBEndActiveClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBAllowDragClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBStartAnnValueClick(Sender: TObject);
    procedure CBEndAnnValueClick(Sender: TObject);
  private
    { Private declarations }
    ColorBandTool : TColorBandTool;

    IStart,
    IEnd : TColorLineToolEditor;
  public
    { Public declarations }
  end;

implementation

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

Uses
  TeEngine, TeeConst, TeeProCo, TeeBrushDlg, TeeEdiAxis, TeeBackImage,
  TeeMouseCursor;

procedure TColorBandToolEditor.FormShow(Sender: TObject);
begin
  inherited;

  ColorBandTool:=TColorBandTool(Tag);

  if Assigned(ColorBandTool) then
  begin
    With ColorBandTool do
    begin
      EStart.Text:=FloatToStr(StartValue);
      EEnd.Text:=FloatToStr(EndValue);
      UDTrans.Position:=Transparency;
      CBDrawBehind.Checked:=DrawBehind;
      CBBeforeAxes.Checked:=DrawBehindAxes;
      CBStart.Checked:=ResizeStart;
      CBEnd.Checked:=ResizeEnd;
      CBAllowDrag.Checked:=AllowDrag;

      CBStartActive.Checked:=StartLine.Active;
      CBEndActive.Checked:=EndLine.Active;

      TeeFillCursors(CBCursor,Cursor);
    end;

    ButtonColor1.LinkProperty(ColorBandTool,'Color'); // Do not localize
  end;
end;

procedure TColorBandToolEditor.EStartChange(Sender: TObject);
begin
  if Showing then
     with ColorBandTool do StartValue:=StrToFloatDef(EStart.Text,StartValue);
end;

procedure TColorBandToolEditor.EEndChange(Sender: TObject);
begin
  if Showing then
     with ColorBandTool do EndValue:=StrToFloatDef(EEnd.Text,EndValue);
end;

procedure TColorBandToolEditor.ETransChange(Sender: TObject);
begin
  if Showing and Assigned(ColorBandTool) then
     ColorBandTool.Transparency:=UDTrans.Position;
end;

procedure TColorBandToolEditor.CBDrawBehindClick(Sender: TObject);
begin
  ColorBandTool.DrawBehind:=CBDrawBehind.Checked;
end;

procedure TColorBandToolEditor.CBStartClick(Sender: TObject);
begin
  ColorBandTool.ResizeStart:=CBStart.Checked
end;

procedure TColorBandToolEditor.CBEndClick(Sender: TObject);
begin
  ColorBandTool.ResizeEnd:=CBEnd.Checked
end;

procedure TColorBandToolEditor.CBBeforeAxesClick(Sender: TObject);
begin
  ColorBandTool.DrawBehindAxes:=CBBeforeAxes.Checked;
end;

procedure TColorBandToolEditor.CBCursorChange(Sender: TObject);
begin
  with ColorBandTool do
       Cursor:=TeeSetCursor(Cursor,CBCursor.CurrentItem);
end;

procedure TColorBandToolEditor.CBStartActiveClick(Sender: TObject);
begin
  if ColorBandTool.StartLine.Active<>CBStartActive.Checked then
  begin
    ColorBandTool.StartLine.Active:=CBStartActive.Checked;
    ColorBandTool.Repaint;
  end;
end;

procedure TColorBandToolEditor.CBEndActiveClick(Sender: TObject);
begin
  if ColorBandTool.EndLine.Active<>CBEndActive.Checked then
  begin
    ColorBandTool.EndLine.Active:=CBEndActive.Checked;
    ColorBandTool.Repaint;
  end;
end;

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

procedure TColorBandToolEditor.PageControl1Change(Sender: TObject);

  procedure TryAddColorLineEditor(var IEditor:TColorLineToolEditor; ALine:TColorLineTool; ATab:TTabSheet);
  begin
    if not Assigned(IEditor) then
    begin
      IEditor:=TColorLineToolEditor.Create(Self);

      IEditor.Align:=alClient;
      TeeTranslateControl(IEditor);
      AddFormTo(IEditor,ATab,ALine);

      IEditor.HideTabs;
    end;
  end;

begin
  inherited;

  if PageControl1.ActivePage=TabBorder then
  begin
     if TabBorder.ControlCount=0 then
        TPenDialog.InsertForm(ColorBandTool.Pen,TabBorder);
  end
  else
  if PageControl1.ActivePage=TabStart then
  begin
     TryAddColorLineEditor(IStart,ColorBandTool.StartLine,TabStart);
     CBStartAnnValue.Checked:=ColorBandTool.StartLine.AnnotationValue;
  end
  else
  if PageControl1.ActivePage=TabEnd then
  begin
     TryAddColorLineEditor(IEnd,ColorBandTool.EndLine,TabEnd);
     CBEndAnnValue.Checked:=ColorBandTool.EndLine.AnnotationValue;
  end
  else
  if PageControl1.ActivePage=TabPattern then
  begin
     if TabPattern.ControlCount=0 then
        TBrushDialog.AddDialog(ColorBandTool.Brush,TabPattern);
  end
  else
  if PageControl1.ActivePage=TabPicture then
  begin
     if TabPicture.ControlCount=0 then
        TBackImageEditor.InsertForm(TabPicture,ColorBandTool.Picture);
  end;
end;

procedure TColorBandToolEditor.CBAllowDragClick(Sender: TObject);
begin
  ColorBandTool.AllowDrag:=CBAllowDrag.Checked;
end;

procedure TColorBandToolEditor.FormCreate(Sender: TObject);
begin
  inherited;
  PanelTop.Height:=38;
  PageControl1.ActivePage:=TabOptions;
end;

procedure TColorBandToolEditor.CBStartAnnValueClick(Sender: TObject);
begin
  ColorBandTool.StartLine.AnnotationValue:=CBStartAnnValue.Checked;

  if CBStartAnnValue.Checked then
     ColorBandTool.StartLine.Annotation.Repaint;
end;

procedure TColorBandToolEditor.CBEndAnnValueClick(Sender: TObject);
begin
  ColorBandTool.EndLine.AnnotationValue:=CBEndAnnValue.Checked;

  if CBEndAnnValue.Checked then
     ColorBandTool.EndLine.Annotation.Repaint;
end;

initialization
  RegisterClass(TColorBandToolEditor);
end.
