unit GLBitDraw;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Spin, MiscRoutines;

type
  TGLBitSize = class(TForm)
    SEWidth: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    SEHeight: TSpinEdit;
    OkButton: TButton;
    Bevel1: TBevel;
    CancelButton: TButton;
    Label3: TLabel;
    EFileSize: TEdit;
    procedure SEWidthExit(Sender: TObject);
    procedure SEHeightExit(Sender: TObject);
    procedure SEWidthChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    function  Validate:Boolean;
    procedure Clean;
  end;

var
  GLBitSize: TGLBitSize;

implementation

{$R *.DFM}

function TGLBitSize.Validate;
begin
  Result:=
    CheckSpinContens(SEWidth,'Ширина растра') and
    CheckSpinContens(SEHeight,'Высота растра');
end;

procedure TGLBitSize.Clean;
begin
  SEWidth.Value:=ValidInteger(SEWidth);
  SEHeight.Value:=ValidInteger(SEHeight);
end;

procedure TGLBitSize.SEWidthExit(Sender: TObject);
begin
  if(not CheckSpinContens(SEWidth,'Ширина растра')) then
  begin
    EFileSize.Text:='';
    FocusControl(SEWidth);
  end;
end;

procedure TGLBitSize.SEHeightExit(Sender: TObject);
begin
  if(not CheckSpinContens(SEHeight,'Высота растра')) then
  begin
    EFileSize.Text:='';
    FocusControl(SEHeight);
  end;
end;

procedure TGLBitSize.SEWidthChange(Sender: TObject);
var
  w,h : integer;
begin
  try
    w:=SEWidth.Value;
    h:=SEHeight.Value;
    EFileSize.Text:=IntToStr(Round((w*h*3+sizeof(TBITMAPFILEHEADER)+
      sizeof(TBITMAPINFO))/1024));
  except
    on EConvertError do
    begin
      EFileSize.Text:='';
    end;
  end;
end;

procedure TGLBitSize.FormShow(Sender: TObject);
begin
  SEWidthChange(nil);
end;

procedure TGLBitSize.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  CanClose:=ValidateByResult(Validate,Clean,ModalResult);
end;

procedure TGLBitSize.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if(ChooseResult(Key,ModalResult)<>mrNone) then
    ModalResult:=ChooseResult(Key,ModalResult);
end;

end.
