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

interface

uses
  SysUtils, Types, System.UITypes, Classes, Variants,
  FMX.Types, FMX.Controls, FMX.Forms,
  FMX.Edit, FMX.Dialogs, FMXTee.Canvas, FMX.ListBox, FMX.Colors;

type
  TShadowEditor = class(TForm)
    LTransp: TLabel;
    Label2: TLabel;
    LBlur: TLabel;
    UDShadowTransp: TSpinBox;
    BShadowColor: TComboColorBox;
    BOK: TButton;
    CBSmooth: TCheckBox;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label5: TLabel;
    UDShadowSize: TSpinBox;
    UDShaVert: TSpinBox;
    CBVisible: TCheckBox;
    TBBlur: TTrackBar;
    TBColor: TTrackBar;
    CBClip: TCheckBox;
    procedure BOKClick(Sender: TObject);
    procedure TBBlurChange(Sender: TObject);
    procedure TBColorChange(Sender: TObject);
    procedure CBVisibleChange(Sender: TObject);
    procedure CBSmoothChange(Sender: TObject);
    procedure CBClipChange(Sender: TObject);
    procedure UDShadowTranspChange(Sender: TObject);
    procedure UDShaVertChange(Sender: TObject);
    procedure UDShadowSizeChange(Sender: TObject);
    procedure BShadowColorChange(Sender: TObject);
  private
   { Private declarations }
    Shadow : TTeeShadow;

    procedure RefreshShadow(AShadow:TTeeShadow);
  public
   { Public declarations }
    class function CreateEmbedd(AOwner: TComponent;
                                AShadow: TTeeShadow; AParent: TFmxObject): TForm;
    class function Edit(AOwner:TComponent; AShadow:TTeeShadow):Boolean;
  end;

implementation

{$R *.fmx}

uses
  {$IFDEF D17}
  System.UIConsts,
  {$ENDIF}
  FMXTee.Procs, FMXTee.Editor.Stroke;

procedure TShadowEditor.RefreshShadow(AShadow: TTeeShadow);
begin
  Shadow:=AShadow;

  CBClip.IsChecked:=Shadow.Clip;
  CBSmooth.IsChecked:=Shadow.Smooth;
  CBVisible.IsChecked:=Shadow.Visible;
  BShadowColor.Color:=Shadow.Color;
  UDShadowSize.Value:=Shadow.HorizSize;
  UDShaVert.Value:=Shadow.VertSize;

  TBBlur.Value:=Shadow.SmoothBlur;
  LBlur.Text:=IntToStr(Shadow.SmoothBlur);
end;

procedure TShadowEditor.BOKClick(Sender: TObject);
begin
  ModalResult:=mrOk;
end;

procedure TShadowEditor.CBSmoothChange(Sender: TObject);
begin
  Shadow.Smooth:=CBSmooth.IsChecked;
end;

class function TShadowEditor.Edit(AOwner: TComponent;
  AShadow: TTeeShadow): Boolean;
begin
  with TShadowEditor.Create(AOwner) do
  try
    RefreshShadow(AShadow);
    result:=ShowModal=mrOk;
  finally
    Free;
  end;
end;

class function TShadowEditor.CreateEmbedd(AOwner: TComponent;
  AShadow: TTeeShadow; AParent: TFmxObject): TForm;
begin
  result:=TShadowEditor.Create(AOwner);
  result.Name:=AOwner.ClassName+AParent.Name;
  TShadowEditor(result).BOK.Visible:=False;

  TShadowEditor(result).RefreshShadow(AShadow);

  EmbeddForm(result, AParent);
end;

procedure TShadowEditor.CBVisibleChange(Sender: TObject);
begin
  Shadow.Visible:=CBVisible.IsChecked;
end;

procedure TShadowEditor.TBBlurChange(Sender: TObject);
begin
  Shadow.SmoothBlur:=Round(TBBlur.Value);
  LBlur.Text:=IntToStr(Shadow.SmoothBlur);
end;

procedure TShadowEditor.TBColorChange(Sender: TObject);
var H,L,S : Single;
begin
  RGBtoHSL(Shadow.Color,H,S,L);
  Shadow.Color:=HSLtoRGB(H,S,TBColor.Value);
  BShadowColor.Color:=Shadow.Color;
end;

procedure TShadowEditor.UDShadowSizeChange(Sender: TObject);
begin
  Shadow.HorizSize:=Round(UDShadowSize.Value);
end;

procedure TShadowEditor.UDShadowTranspChange(Sender: TObject);
begin
  Shadow.Transparency:=Round(UDShadowTransp.Value);
end;

procedure TShadowEditor.UDShaVertChange(Sender: TObject);
begin
  Shadow.VertSize:=Round(UDShaVert.Value);
end;

procedure TShadowEditor.BShadowColorChange(Sender: TObject);
begin
  Shadow.Color:=BShadowColor.Color;
end;

procedure TShadowEditor.CBClipChange(Sender: TObject);
begin
  Shadow.Clip:=CBClip.IsChecked;
end;

end.
