unit Vis2D_LineEndSettings;

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,
  System.ImageList, Vcl.ImgList, Vcl.ComCtrls;

type
  TVis2D_LineEndSettingsFrm = class(TDrawableOptionsFrm)
    StyleImages: TImageList;
    lblAreaColor: TLabel;
    lblLineEndName: TLabel;
    ccColor: TColorContainer;
    cbParentColor: TCheckBox;
    Label1: TLabel;
    lvStyle: TListView;
    Label2: TLabel;
    tbZoom: TTrackBar;
    tbAspect: TTrackBar;
    Label3: TLabel;
    cbFilled: TCheckBox;
    procedure btnApplyClick(Sender: TObject);
    procedure CallUpdateDrawable(Sender: TObject);
    procedure cbParentColorClick(Sender: TObject);
    procedure lvStyleSelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
  strict protected
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  public

  end;

implementation

uses
  Math, RTTI;

{$R *.dfm}

{ TVis2D_LineEndSettingsFrm }

procedure TVis2D_LineEndSettingsFrm.btnApplyClick(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis2D_LineEndSettingsFrm.CallUpdateDrawable(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis2D_LineEndSettingsFrm.cbParentColorClick(Sender: TObject);
begin
  ccColor.Enabled := not cbParentColor.Checked;
  UpdateDrawable;
end;

procedure TVis2D_LineEndSettingsFrm.Initialize;
var
  LineEnd: TLineEndMarkerDrawable;
begin

  inherited;

  LineEnd := FDrawable as TLineEndMarkerDrawable;

  lblLineEndName.Caption := LineEnd.Name;

  ccColor.Color := LineEnd.Color;
  cbParentColor.Checked := LineEnd.LineColor;
  lvStyle.ItemIndex := Ord(LineEnd.Kind);
  cbFilled.Checked := LineEnd.Filled;
  tbZoom.Position := Round(LineEnd.SizeX);
  tbAspect.Position := Round(tbAspect.Max * (LineEnd.SizeY / LineEnd.SizeX - 1) / 2);

end;

procedure TVis2D_LineEndSettingsFrm.lvStyleSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
  if Selected then
    UpdateDrawable;
end;

procedure TVis2D_LineEndSettingsFrm.UpdateDrawable;
var
  LineEnd: TLineEndMarkerDrawable;
begin

  if not Initialized then
    Exit;

  LineEnd := FDrawable as TLineEndMarkerDrawable;

  LineEnd.Color := ccColor.Color;
  LineEnd.LineColor := cbParentColor.Checked;
  if InRange(lvStyle.ItemIndex, Ord(Low(TLineEndMarker)), Ord(High(TLineEndMarker))) then
    LineEnd.Kind := TLineEndMarker(lvStyle.ItemIndex)
  else
    LineEnd.Kind := lemNone;
  LineEnd.Filled := cbFilled.Checked;

  LineEnd.SizeX := tbZoom.Position;
  LineEnd.SizeY := tbZoom.Position * (1 + 2*tbAspect.Position / tbAspect.Max);

  inherited;

end;

end.
