{$INCLUDE Switches.inc}
unit Back;

interface

uses
  LCLIntf, LCLType, SysUtils, Classes,
  {$IFDEF DPI}Dpi.Graphics, Dpi.Forms, Dpi.Controls{$ELSE}
  Graphics, Forms, Controls{$ENDIF};

type

  { TBackground }

  TBackground = class(TForm)
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    Img: TBitmap;
  public
    procedure UpdateInterface;
  end;


implementation

uses
  Directories, ScreenTools, Start;

{$R *.lfm}

procedure TBackground.FormCreate(Sender: TObject);
begin
  Img := nil;
end;

procedure TBackground.FormShow(Sender: TObject);
begin
  UpdateInterface;
end;

procedure TBackground.FormDestroy(Sender: TObject);
begin
  if Assigned(Img) then FreeAndNil(Img);
end;

procedure TBackground.FormPaint(Sender: TObject);
begin
  if Assigned(Img) and FullScreen then
    BitBltCanvas(Canvas, Width - Img.Width - (Width - 800) *
      3 div 8, (Height - 600) div 3, Img.Width, Img.Height,
      Img.Canvas, 0, 0);
end;

procedure TBackground.UpdateInterface;
var
  FileName: string;
begin
  if FullScreen then begin
    BoundsRect := Screen.PrimaryMonitor.BoundsRect;
    WindowState := TWindowState.wsFullScreen;
    if not Assigned(Img) then begin
      FileName := GetGraphicsDir + DirectorySeparator + 'Background' + PngExt;
      if FileExists(FileName) then begin
        Img := TBitmap.Create;
        LoadGraphicFile(Img, FileName);
        Repaint;
      end;
    end;
  end else begin
    if WindowState <> TWindowState.wsMaximized then begin
      WindowState := TWindowState.wsNormal;
      WindowState := TWindowState.wsFullScreen;
    end;
    WindowState := TWindowState.wsNormal;
    BoundsRect := Bounds(StartDlg.Left - 8, StartDlg.Top - 8,
      StartDlg.Width + 16, StartDlg.Height + 16);
  end;
end;

end.
