unit Vis2D_LineSettings;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VisCtl2D,
  TextEditor, ColorContainer, Vcl.StdCtrls, ScrollBoxEx, UxPanel, Vcl.ExtCtrls;

type
  TVis2D_LineSettingsFrm = class(TDrawableOptionsFrm)
    pnToolbar: TUxClient;
    btnStyle: TUxButton;
    btnStart: TUxButton;
    btnEnd: TUxButton;
    pnStyle: TPanel;
    pnEnd: TPanel;
    pnStart: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure SetPage(Sender: TObject);
  strict private
    FPageButtons: TArray<TUxButton>;
    FStyle, FStart, FEnd: TDrawableOptionsFrm;
  end;

implementation

uses
  Math, Vis2D_ElementSettings, Vis2D_LineEndSettings, Generics.Collections;

{$R *.dfm}

{ TVis2D_LineSettingsFrm }

procedure TVis2D_LineSettingsFrm.FormCreate(Sender: TObject);
var
  Line: TLine;
begin

  Line := FDrawable as TLine;

  btnStyle.Tag := NativeInt(pnStyle);
  btnStart.Tag := NativeInt(pnStart);
  btnEnd.Tag := NativeInt(pnEnd);
  FPageButtons := [btnStyle, btnStart, btnEnd];

  SetPage(btnStyle);

  FStyle := TVis2D_ElementSettingsFrm.Create(Self, Line.Style);
  FStyle.Parent := pnStyle;
  FStyle.BorderStyle := bsNone;
  FStyle.Align := alClient;
  FStyle.Show;

  FStart := TVis2D_LineEndSettingsFrm.Create(Self, Line.StartMarker);
  FStart.Parent := pnStart;
  FStart.BorderStyle := bsNone;
  FStart.Align := alClient;
  FStart.Show;

  FEnd := TVis2D_LineEndSettingsFrm.Create(Self, Line.EndMarker);
  FEnd.Parent := pnEnd;
  FEnd.BorderStyle := bsNone;
  FEnd.Align := alClient;
  FEnd.Show;

end;

procedure TVis2D_LineSettingsFrm.SetPage(Sender: TObject);
var
  B: TUxButton;
  P: TPanel;
begin
  LockDrawing;
  try
    for B in FPageButtons do
    begin
      if B.Tag = 0 then
        Continue;
      P := TObject(B.Tag) as TPanel;
      P.Align := alClient;
      P.Visible := B = Sender;
      B.Down := B = Sender;
      if (B = Sender) and Visible and P.Visible and P.CanFocus then
      begin
        if (P.ControlCount = 1) and (P.Controls[0] is TCustomForm) then
        begin
          P.Controls[0].ScaleForPPI(Self.CurrentPPI);
          P.Realign;
        end;
        P.SetFocus;
      end;
    end;
  finally
    UnlockDrawing;
  end;
end;

end.
