unit FMXTee.Editor.Tools.LegendScrollBar;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  FMX.ListBox, FMXTee.Tools, FMX.Edit, FMX.TabControl, FMX.Layouts, FMX.Memo,
  FMXTee.Tools.LegendScrollBar, FMX.Colors;

type
  TScrollbarEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabFormat: TTabItem;
    TabThumb: TTabItem;
    BBorder: TButton;
    BBack: TButton;
    CBAuto: TCheckBox;
    Label5: TLabel;
    UDSize: TSpinBox;
    Label4: TLabel;
    UDDelay: TSpinBox;
    BArrows: TButton;
    BGradient: TButton;
    Label1: TLabel;
    GBImage: TGroupBox;
    BBrowse: TButton;
    BFilters: TButton;
    CBStyle: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    BPattern: TButton;
    BThumbGrad: TButton;
    Label2: TLabel;
    UDThumbSize: TSpinBox;
    CBBevel: TComboBox;
    ListBoxItem6: TListBoxItem;
    ListBoxItem7: TListBoxItem;
    ListBoxItem8: TListBoxItem;
    Label3: TLabel;
    CBColor: TComboColorBox;
    procedure FormActivate(Sender: TObject);
    procedure UDSizeChange(Sender: TObject);
    procedure BBorderClick(Sender: TObject);
    procedure CBAutoChange(Sender: TObject);
    procedure UDDelayChange(Sender: TObject);
    procedure BBackClick(Sender: TObject);
    procedure BArrowsClick(Sender: TObject);
    procedure BGradientClick(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
    procedure BFiltersClick(Sender: TObject);
    procedure BBrowseClick(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure BPatternClick(Sender: TObject);
    procedure BThumbGradClick(Sender: TObject);
    procedure UDThumbSizeChange(Sender: TObject);
    procedure CBBevelChange(Sender: TObject);
  private
    { Private declarations }
    Scrollbar : TLegendScrollBar;
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Editor.Brush, FMXTee.Editor.Gradient,
  FMXTee.Editor.Picture, FMXTee.Procs;

procedure TScrollbarEditor.BArrowsClick(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     TBrushEditor.Edit(Self,Scrollbar.ArrowBrush);
end;

procedure TScrollbarEditor.BBackClick(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     TBrushEditor.Edit(Self,Scrollbar.Brush);
end;

procedure TScrollbarEditor.BBorderClick(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     TStrokeEditor.Edit(Self, Scrollbar.Pen);
end;

procedure TScrollbarEditor.BBrowseClick(Sender: TObject);
var tmp : String;
begin
  if Assigned(ScrollBar) then
  begin
    Scrollbar.Thumb.Image.SetSize(0,0);

    tmp:=TBackImageEditor.GetPictureFileName(Self);

    if tmp<>'' then
    begin
      if not FileExists(tmp) then
         raise Exception.Create('Image file does not exist: '+tmp);

      Scrollbar.Thumb.Image.LoadFromFile(tmp);
      Scrollbar.Thumb.Image.Repaint;
    end;
  end;
end;

procedure TScrollbarEditor.BFiltersClick(Sender: TObject);
begin
  //TODO
end;

procedure TScrollbarEditor.BGradientClick(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    TGradientEditor.Edit(Self, Scrollbar.Gradient);
end;

procedure TScrollbarEditor.BPatternClick(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     TBrushEditor.Edit(Self,Scrollbar.ThumbBrush);
end;

procedure TScrollbarEditor.BThumbGradClick(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    TGradientEditor.Edit(Self, Scrollbar.Thumb.Gradient);
end;

procedure TScrollbarEditor.CBColorChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    Scrollbar.BackColor:=CBColor.Color;
end;

procedure TScrollbarEditor.CBStyleChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.Thumb.Style:=TScrollThumbStyle(CBStyle.ItemIndex);
end;

procedure TScrollbarEditor.CBAutoChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    Scrollbar.AutoRepeat:=CBAuto.IsChecked;
end;

procedure TScrollbarEditor.CBBevelChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.Bevel:=TPanelBevel(CBStyle.ItemIndex);
end;

procedure TScrollbarEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Scrollbar) then
  begin
    Scrollbar:=TLegendScrollBar(TagObject);;

    if Assigned(Scrollbar) then
    begin
      With Scrollbar do
      begin
        CBBevel.ItemIndex:=Ord(Bevel);
        CBAuto.IsChecked:=AutoRepeat;
        UDSize.Value:=Size;
        UDDelay.Value:=InitialDelay;
        UDThumbSize.Value:=Thumb.Size;

        CBColor.Color:=BackColor;

        CBStyle.ItemIndex:=Ord(Thumb.Style);
      end;
    end;
  end;
end;

procedure TScrollbarEditor.UDSizeChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    Scrollbar.Size:=Round(UDSize.Value);
end;

procedure TScrollbarEditor.UDThumbSizeChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    Scrollbar.ThumbSize:=Round(UDThumbSize.Value);
end;

procedure TScrollbarEditor.UDDelayChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    Scrollbar.InitialDelay:=Round(UDDelay.Value);
end;

initialization
  RegisterSeriesEditor(TScrollbarEditor);
end.
