{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Series.Surface;
{$I TeeDefs.inc}

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Chart.ListBox,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  FMX.TabControl, FMXTee.Series.Surface, FMX.Edit, FMX.ListBox, FMX.Colors,
  FMXTee.Procs, FMX.Layouts, FMX.Grid, FMXTee.Chart.Grid,
  FMXTee.Editor.Stroke, FMXTee.Editor.Brush;

type
  TSurfaceSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabGlobal: TTabItem;
    TabGrid3D: TTabItem;
    TabControl2: TTabControl;
    TabItem1: TTabItem;
    TabBorder: TTabItem;
    TabPattern: TTabItem;
    TabSides: TTabItem;
    GroupBox1: TGroupBox;
    rbWireFrame: TRadioButton;
    rbDotFrame: TRadioButton;
    rbSolid: TRadioButton;
    CBSmoothPalette: TCheckBox;
    CBHideCells: TCheckBox;
    Label6: TLabel;
    CBFastBrush: TCheckBox;
    TabControl3: TTabControl;
    TabSidesPen: TTabItem;
    TabSidesBrush: TTabItem;
    TBTransp: TTrackBar;
    procedure FormActivate(Sender: TObject);
    procedure CBSmoothPaletteChange(Sender: TObject);
    procedure rbSolidChange(Sender: TObject);
    procedure rbWireFrameChange(Sender: TObject);
    procedure rbDotFrameChange(Sender: TObject);
    procedure CBHideCellsChange(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure CBFastBrushChange(Sender: TObject);
    procedure TabControl2Change(Sender: TObject);
    procedure TabControl3Change(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure TBTranspTracking(Sender: TObject);
  private
    { Private declarations }
    ISideBorder,
    IBorder : TStrokeEditor;
    ISidePattern,
    IPattern : TBrushEditor;

  protected
    Grid3DForm : TCustomForm;
    Surface    : TSurfaceSeries;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Series.Grid;

procedure TSurfaceSeriesEditor.CBFastBrushChange(Sender: TObject);
begin
  if assigned(Surface) then
    Surface.FastBrush:=CBFastBrush.IsChecked;
end;

procedure TSurfaceSeriesEditor.CBHideCellsChange(Sender: TObject);
begin
  if assigned(Surface) then
  begin
    Surface.HideCells:=CBHideCells.IsChecked;
    Surface.Repaint;
  end;
end;

procedure TSurfaceSeriesEditor.CBSmoothPaletteChange(Sender: TObject);
begin
  if assigned(Surface) then
    Surface.SmoothPalette:=CBSmoothPalette.IsChecked;
end;

procedure TSurfaceSeriesEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Surface) then
  begin
    Surface:=TSurfaceSeries(TagObject);

    if Assigned(Surface) then
    With Surface do
    begin
      if WireFrame then
         rbWireFrame.IsChecked:=True
      else if DotFrame then
         rbDotFrame.IsChecked:=True
      else
         rbSolid.IsChecked:=True;

      CBSmoothPalette.IsChecked:=SmoothPalette;
      TBTransp.Value:=Transparency;
      CBFastBrush.IsChecked:=FastBrush;
      CBHideCells.IsChecked:=HideCells;

      TGrid3DSeriesEditor.CreateEmbedd(Self,Surface,TabGrid3D);
    end;
  end;
end;

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

procedure TSurfaceSeriesEditor.rbDotFrameChange(Sender: TObject);
begin
  if Assigned(Surface) then
    Surface.DotFrame:=True;
end;

procedure TSurfaceSeriesEditor.rbSolidChange(Sender: TObject);
begin
  if Assigned(Surface) then
  begin
    Surface.DotFrame:=False;
    Surface.WireFrame:=False;
  end;
end;

procedure TSurfaceSeriesEditor.rbWireFrameChange(Sender: TObject);
begin
  if Assigned(Surface) then
     Surface.WireFrame:=True;
end;

procedure TSurfaceSeriesEditor.TabControl2Change(Sender: TObject);
begin
  if TabControl2.ActiveTab=TabSides then
     TabControl3Change(Self)
  else
  if (TabControl2.ActiveTab=TabBorder) and (not Assigned(IBorder)) then
     IBorder:=TStrokeEditor.InsertForm(Surface.Pen,TabBorder)
  else
  if (TabControl2.ActiveTab=TabPattern) and (not Assigned(IPattern)) then
     IPattern:=TBrushEditor.InsertForm(Surface.Brush,TabPattern);
end;

procedure TSurfaceSeriesEditor.TabControl3Change(Sender: TObject);
begin
  if (TabControl3.ActiveTab=TabSidesPen) and (not Assigned(ISideBorder)) then
     ISideBorder:=TStrokeEditor.InsertForm(Surface.SideLines,TabSidesPen)
  else
  if (TabControl3.ActiveTab=TabSidesBrush) and (not Assigned(ISidePattern)) then
     ISidePattern:=TBrushEditor.InsertForm(Surface.SideBrush,TabSidesBrush);
end;

procedure TSurfaceSeriesEditor.TBTranspChange(Sender: TObject);
begin
  if Assigned(Surface) then
     Surface.Transparency:=Round(TBTransp.Value);
end;

procedure TSurfaceSeriesEditor.TBTranspTracking(Sender: TObject);
begin
  TBTranspChange(Self);
end;

initialization
  RegisterSeriesEditor(TSurfaceSeriesEditor);
end.
