{**********************************************}
{   TSurfaceSeries Editor Dialog               }
{   Copyright (c) 1996-2020 by Steema Software }
{**********************************************}
unit TeeSurfEdit;
{$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
  TSurfaceSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabBorder: TTabSheet;
    TabBrush: TTabSheet;
    TabSides: TTabSheet;
    Label1: TLabel;
    RadioGroup1: TRadioGroup;
    CBSmooth: TCheckBox;
    CBFastBrush: TCheckBox;
    CBHideCells: TCheckBox;
    PageControl2: TPageControl;
    TabSideBorder: TTabSheet;
    TabSidePattern: TTabSheet;
    TBTransp: TTrackBar;
    LTransp: TLabel;
    procedure FormShow(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure CBSmoothClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBFastBrushClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure CBHideCellsClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure PageControl2Change(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
  private
    { Private declarations }
  protected
    Grid3DForm : TCustomForm;
    Surface    : TSurfaceSeries;
  public
    { Public declarations }
  end;

implementation

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

Uses
  TeeBrushDlg, TeeGriEd;

procedure TSurfaceSeriesEditor.FormShow(Sender: TObject);
begin
  Surface:=TSurfaceSeries(Tag);

  if Assigned(Surface) then
  begin
    With Surface do
    begin
      if WireFrame then
         RadioGroup1.ItemIndex:=1
      else
      if DotFrame then
         RadioGroup1.ItemIndex:=2
      else
         RadioGroup1.ItemIndex:=0;

      CBSmooth.Checked:=SmoothPalette;

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

      CBFastBrush.Checked:=FastBrush;
      CBHideCells.Checked:=HideCells;
    end;

    if not Assigned(Grid3DForm) then
       Grid3DForm:=TeeInsertGrid3DForm(Parent,Surface)
    else
       TGrid3DSeriesEditor(Grid3DForm).RefreshControls(Surface);
  end;
end;

procedure TSurfaceSeriesEditor.RadioGroup1Click(Sender: TObject);
begin
  if Showing then
  Case RadioGroup1.ItemIndex of
    0: { solid }
       begin
         Surface.DotFrame:=False;
         Surface.WireFrame:=False;
       end;
    1: Surface.WireFrame:=True;
    2: Surface.DotFrame:=True;
  end;
end;

procedure TSurfaceSeriesEditor.CBSmoothClick(Sender: TObject);
begin
  Surface.SmoothPalette:=CBSmooth.Checked
end;

procedure TSurfaceSeriesEditor.FormCreate(Sender: TObject);
begin
  BorderStyle:=TeeBorderStyle;
  PageControl1.ActivePageIndex:=0;
end;

procedure TSurfaceSeriesEditor.CBFastBrushClick(Sender: TObject);
begin
  Surface.FastBrush:=CBFastBrush.Checked;
end;

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

procedure TSurfaceSeriesEditor.CBHideCellsClick(Sender: TObject);
begin
  Surface.HideCells:=CBHideCells.Checked;
  Surface.Repaint;
end;

procedure TSurfaceSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage=TabSides then
     PageControl2Change(Self)
  else
  if PageControl1.ActivePage.ControlCount=0 then
     if PageControl1.ActivePage=TabBorder then
        TPenDialog.InsertForm(Surface.Pen,TabBorder)
     else
     if PageControl1.ActivePage=TabBrush then
        TBrushDialog.AddDialog(Surface.Brush,TabBrush);
end;

procedure TSurfaceSeriesEditor.PageControl2Change(Sender: TObject);
begin
  if (PageControl2.ActivePage=TabSideBorder) and (TabSideBorder.ControlCount=0) then
     TPenDialog.InsertForm(Surface.SideLines,TabSideBorder)
  else
  if (PageControl2.ActivePage=TabSidePattern) and (TabSidePattern.ControlCount=0) then
     TBrushDialog.AddDialog(Surface.SideBrush,TabSidePattern);
end;

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

initialization
  RegisterClass(TSurfaceSeriesEditor);
end.
