{********************************************}
{ TTowerSeries Editor Dialog                 }
{ Copyright (c) 2002-2020 by Steema Software }
{********************************************}
unit TeeTowerEdit;
{$I TeeDefs.inc}

interface

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

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

     Chart, TeeSurfa, TeCanvas, TeePenDlg, TeeProcs;

type
  TTowerSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabBorder: TTabSheet;
    TabPattern: TTabSheet;
    Label1: TLabel;
    Label4: TLabel;
    CBDark3D: TCheckBox;
    GroupBox1: TGroupBox;
    CBOrigin: TCheckBox;
    EOrigin: TEdit;
    CBStyle: TComboFlat;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    UDDepth: TUpDown;
    Edit2: TEdit;
    UDWidth: TUpDown;
    TBTransp: TTrackBar;
    LTransp: TLabel;
    Label5: TLabel;
    CBStacked: TComboFlat;
    CBIgnoreNulls: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBDark3DClick(Sender: TObject);
    procedure CBOriginClick(Sender: TObject);
    procedure EOriginChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBStackedChange(Sender: TObject);
    procedure CBIgnoreNullsClick(Sender: TObject);
  private
    { Private declarations }
    Tower : TTowerSeries;
    Grid3DForm : TCustomForm;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeeBrushDlg, TeeGriEd, TeEngine;

procedure TTowerSeriesEditor.FormShow(Sender: TObject);
begin
  Tower:=TTowerSeries(Tag);

  if Assigned(Tower) then
  begin
    With Tower do
    begin
      CBDark3D.Checked:=Dark3D;
      CBOrigin.Checked:=UseOrigin;
      EOrigin.Text:=FloatToStr(Origin);
      CBStyle.ItemIndex:=Ord(TowerStyle);
      UDDepth.Position:=PercentDepth;
      UDWidth.Position:=PercentWidth;

      CBIgnoreNulls.Checked:=TreatNulls=tnIgnore;
      CBStacked.ItemIndex:=Ord(Stacked);

      TBTransp.Position:=Transparency;
      LTransp.Caption:=IntToStr(Transparency);
    end;

    if not Assigned(Grid3DForm) then
       Grid3DForm:=TeeInsertGrid3DForm(Parent,Tower);
  end;
end;

procedure TTowerSeriesEditor.FormCreate(Sender: TObject);
begin
  BorderStyle:=TeeBorderStyle;
end;

procedure TTowerSeriesEditor.CBDark3DClick(Sender: TObject);
begin
  Tower.Dark3D:=CBDark3D.Checked;
end;

procedure TTowerSeriesEditor.CBOriginClick(Sender: TObject);
begin
  Tower.UseOrigin:=CBOrigin.Checked;
end;

procedure TTowerSeriesEditor.EOriginChange(Sender: TObject);
begin
  Tower.Origin:=StrToFloatDef(EOrigin.Text,Tower.Origin)
end;

procedure TTowerSeriesEditor.CBStyleChange(Sender: TObject);
begin
  Tower.TowerStyle:=TTowerStyle(CBStyle.ItemIndex);
end;

procedure TTowerSeriesEditor.Edit1Change(Sender: TObject);
begin
  if Showing then
     Tower.PercentDepth:=UDDepth.Position;
end;

procedure TTowerSeriesEditor.Edit2Change(Sender: TObject);
begin
  if Showing then
     Tower.PercentWidth:=UDWidth.Position;
end;

procedure TTowerSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(Grid3DForm);
end;

procedure TTowerSeriesEditor.TBTranspChange(Sender: TObject);
begin
  if Showing then
  begin
    Tower.Transparency:=TBTransp.Position;
    LTransp.Caption:=IntToStr(Tower.Transparency);
  end;
end;

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

procedure TTowerSeriesEditor.CBStackedChange(Sender: TObject);
begin
  if Showing then
     Tower.Stacked:=TTowerStacked(CBStacked.ItemIndex);
end;

procedure TTowerSeriesEditor.CBIgnoreNullsClick(Sender: TObject);
begin
  if CBIgnoreNulls.Checked then
     Tower.TreatNulls:=tnIgnore
  else
     Tower.TreatNulls:=tnDontPaint;
end;

initialization
  RegisterClass(TTowerSeriesEditor);
end.
