unit Scene;

interface

uses
  Classes, SysUtils, Graphics;

type
  { TScene }

  TScene = class
  public
    Canvas: TCanvas;
    RedrawPending: Boolean;
    BackgroundColor: TColor;
    procedure Clear;
    procedure Draw; virtual;
    procedure Redraw;
    function GetBoardRect(Size: TPoint): TRect;
    constructor Create;
  end;

const
  clBlack = $000000;
  clWhite = $ffffff;
  clGray = $808080;
  clRed = $0000ff;
  clGreen = $00ff00;
  clBlue = $ff0000;
  clYellow = $00ffff;
  clFuchsia = $ff00ff;
  clAqua = $ffff00;
  clBrown = $003090;
  clOrange = $0080ff;
  clLightBlue = $ff5050;


implementation

{ TScene }

procedure TScene.Clear;
begin
  with Canvas do begin
    Font.Style := [];
    Font.Size := 0;
    Brush.Color := BackgroundColor;
    Brush.Style := bsSolid;
    Pen.Color := clWhite;
    Pen.Style := psSolid;
    FillRect(0, 0, Width, Height);
  end;
end;

procedure TScene.Draw;
begin
end;

procedure TScene.Redraw;
begin
  RedrawPending := True;
end;

function TScene.GetBoardRect(Size: TPoint): TRect;
var
  BoardRatio: Double;
  CanvasRatio: Double;
begin
  BoardRatio := Size.X / Size.Y;
  CanvasRatio := Canvas.Width / Canvas.Height;
  if BoardRatio > CanvasRatio then begin
    Result := Rect(0, (Canvas.Height - Trunc(Canvas.Width / BoardRatio)) div 2,
      Canvas.Width, Canvas.Height - (Canvas.Height - Trunc(Canvas.Width / BoardRatio)) div 2);
  end else begin
    Result := Rect((Canvas.Width - Trunc(Canvas.Height * BoardRatio)) div 2, 0,
      Canvas.Width - (Canvas.Width - Trunc(Canvas.Height * BoardRatio)) div 2, Canvas.Height);
  end;
end;

constructor TScene.Create;
begin
  BackgroundColor := $404040;
end;

end.

