unit FMXTee.Editor.Series.ColorGrid;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Chart.ListBox,
  FMX.TabControl, FMXTee.Series.Surface, FMX.Edit, FMX.ListBox, FMX.Colors,
  FMXTee.Procs, FMX.Layouts, FMX.Grid, FMXTee.Chart.Grid, FMXTee.Editor.Series.Grid,
  FMXTee.Canvas, FMXTee.Editor.Stroke;

type
  TColorGridSeriesEditor = class(TForm)
    TabControl1: TTabControl;
    TabFormat: TTabItem;
    CBSmooth: TCheckBox;
    UDColorGridTransp: TSpinBox;
    Label6: TLabel;
    TabGrid: TTabItem;
    BLoad: TButton;
    TabPosition: TTabItem;
    TabFrame: TTabItem;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    UDX: TSpinBox;
    UDZ: TSpinBox;
    CBCentered: TCheckBox;
    Label3: TLabel;
    UDPosition: TSpinBox;
    Label4: TLabel;
    CBPlane: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    procedure FormActivate(Sender: TObject);
    procedure CBSmoothChange(Sender: TObject);
    procedure BPenClick(Sender: TObject);
    procedure BBrushClick(Sender: TObject);
    procedure UDColorGridTranspChange(Sender: TObject);
    procedure BLoadClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure UDXChange(Sender: TObject);
    procedure UDZChange(Sender: TObject);
    procedure CBPlaneChange(Sender: TObject);
    procedure UDPositionChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
  private
    { Private declarations }
    Creating   : Boolean;
    ColorGrid  : TColorGridSeries;
    Grid3DForm : TGrid3DSeriesEditor;
    FPen : TStrokeEditor;
    FFrame : TStrokeEditor;
  protected
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
 FMXTee.Editor.Brush;

procedure TColorGridSeriesEditor.CBPlaneChange(Sender: TObject);
begin
  ColorGrid.DrawPlane3D:=TCanvas3DPlane(CBPlane.ItemIndex);
end;

procedure TColorGridSeriesEditor.CBSmoothChange(Sender: TObject);
begin
  if assigned(ColorGrid) then
    ColorGrid.SmoothBitmap:=CBSmooth.IsChecked;
end;

procedure TColorGridSeriesEditor.BBrushClick(Sender: TObject);
begin
  if Assigned (ColorGrid) then
    TBrushEditor.Edit(Self, ColorGrid.Brush)
end;

procedure TColorGridSeriesEditor.BPenClick(Sender: TObject);
begin
  if Assigned(ColorGrid) then
    TStrokeEditor.Edit(Self, ColorGrid.Pen);
end;

procedure TColorGridSeriesEditor.BLoadClick(Sender: TObject);
var tmpSt : String;
    tmp   : TPicture;
begin
(*TODO
  if Assigned(ColorGrid) then
  begin
    tmpSt:=TeeGetPictureFileName(Self);

    if tmpSt<>'' then
    begin
      tmp:=TPicture.Create;
      try
        tmp.LoadFromFile(tmpSt);
        ColorGrid.Bitmap:=tmp.Bitmap;
        Grid3DForm.BRemove.Enabled:=HasColors(ColorGrid);
      finally
        tmp.Free;
      end;
    end;
  end;
  *)
end;

procedure TColorGridSeriesEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(ColorGrid) then
  begin
    ColorGrid:=TColorGridSeries(TagObject);

    if Assigned(ColorGrid) then
    With ColorGrid do
    begin
      CBCentered.IsChecked:=CenteredPoints;
      UDX.Value:=XGridEvery;
      UDZ.Value:=ZGridEvery;
      CBSmooth.IsChecked:=SmoothBitmap;
      UDColorGridTransp.Value:=Transparency;
      CBPlane.ItemIndex:=Ord(DrawPlane3D);
      UDPosition.Value:=DrawPosition;

      Creating:=False;
    end;
  end;
end;

procedure TColorGridSeriesEditor.FormCreate(Sender: TObject);
begin
  Creating:=True;
end;

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


procedure TColorGridSeriesEditor.TabControl1Change(Sender: TObject);
begin
  if (TabControl1.ActiveTab=TabGrid) and (not Assigned(FPen)) then
     FPen:=TStrokeEditor.InsertForm(ColorGrid.Pen,TabGrid)
  else
  if (TabControl1.ActiveTab=TabFrame) and (not Assigned(FFrame)) then
     FFrame:=TStrokeEditor.InsertForm(ColorGrid.Frame,TabFrame);
end;

procedure TColorGridSeriesEditor.UDColorGridTranspChange(Sender: TObject);
begin
   ColorGrid.Transparency:=Round(UDColorGridTransp.Value);
end;

procedure TColorGridSeriesEditor.UDPositionChange(Sender: TObject);
begin
  if Assigned(ColorGrid) then
     ColorGrid.DrawPosition:=Round(UDPosition.Value);
end;

procedure TColorGridSeriesEditor.UDXChange(Sender: TObject);
begin
  if not Creating then
     ColorGrid.XGridEvery:=Round(UDX.Value);
end;

procedure TColorGridSeriesEditor.UDZChange(Sender: TObject);
begin
  if not Creating then
     ColorGrid.ZGridEvery:=Round(UDZ.Value);
end;

initialization
  RegisterSeriesEditor(TColorGridSeriesEditor);
end.
