unit Vis2D_ViewSettings;

interface

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

type
  TVis2D_ViewSettingsFrm = class(TDrawableOptionsFrm)
    pnControls: TPanel;
    eXmin: TTextEditor;
    eXmax: TTextEditor;
    eYmax: TTextEditor;
    eYmin: TTextEditor;
    btnApply: TUxButton;
    btnRight: TUxButton;
    btnLeft: TUxButton;
    btnUp: TUxButton;
    btnDown: TUxButton;
    procedure btnApplyClick(Sender: TObject);
    procedure eYminEnter(Sender: TObject);
    procedure eYminExit(Sender: TObject);
    procedure btnRightClick(Sender: TObject);
    procedure btnLeftClick(Sender: TObject);
    procedure btnUpClick(Sender: TObject);
    procedure btnDownClick(Sender: TObject);
    procedure FormResize(Sender: TObject);
  strict protected
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  public
  end;

implementation

{$R *.dfm}

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

procedure TVis2D_ViewSettingsFrm.btnDownClick(Sender: TObject);
begin
  FDrawable.Control.Translate(0, -FDrawable.Control.View.YSpan / 10);
  Initialize;
end;

procedure TVis2D_ViewSettingsFrm.btnLeftClick(Sender: TObject);
begin
  FDrawable.Control.Translate(-FDrawable.Control.View.XSpan / 10, 0);
  Initialize;
end;

procedure TVis2D_ViewSettingsFrm.btnRightClick(Sender: TObject);
begin
  FDrawable.Control.Translate(FDrawable.Control.View.XSpan / 10, 0);
  Initialize;
end;

procedure TVis2D_ViewSettingsFrm.btnUpClick(Sender: TObject);
begin
  FDrawable.Control.Translate(0, FDrawable.Control.View.YSpan / 10);
  Initialize;
end;

procedure TVis2D_ViewSettingsFrm.eYminEnter(Sender: TObject);
begin
  btnApply.Default := True;
end;

procedure TVis2D_ViewSettingsFrm.eYminExit(Sender: TObject);
begin
  btnApply.Default := False;
end;

procedure TVis2D_ViewSettingsFrm.FormResize(Sender: TObject);
begin
  pnControls.Top := (ClientHeight - pnControls.Height) div 2;
  pnControls.Left := (ClientWidth - pnControls.Width) div 2;
end;

procedure TVis2D_ViewSettingsFrm.Initialize;
var
  View: TView2D;
begin
  inherited;
  View := FDrawable as TView2D;
  eXmin.PlainText := View.XMin.ToString;
  eXmax.PlainText := View.XMax.ToString;
  eYmin.PlainText:= View.YMin.ToString;
  eYmax.PlainText:= View.YMax.ToString;
end;

procedure TVis2D_ViewSettingsFrm.UpdateDrawable;
var
  View: TView2D;
begin
  View := FDrawable as TView2D;
  View.&Set(
    StrToFloat(eXmin.PlainText),
    StrToFloat(eXmax.PlainText),
    StrToFloat(eYmin.PlainText),
    StrToFloat(eYmax.PlainText)
  );
  inherited;
end;

end.
