Changeset 6


Ignore:
Timestamp:
Sep 24, 2019, 10:33:34 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Get rendering area size from Form dimensions. Form Canvas dimensions are not updated correctly under Windows.
  • Added: Windows installer script and installer executable.
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        44lib
        55heaptrclog.trc
         6Game2048.exe
  • trunk/Game2048.lpi

    r4 r6  
    77      <MainUnit Value="0"/>
    88      <Title Value="Game2048"/>
     9      <Scaled Value="True"/>
    910      <ResourceType Value="res"/>
    1011      <UseXPManifest Value="True"/>
  • trunk/Game2048.lpr

    r5 r6  
    2525  {$ENDIF}
    2626  RequireDerivedFormResource:=True;
     27  Application.Scaled:=True;
    2728  Application.Initialize;
    2829  Application.CreateForm(TFormMain, FormMain);
  • trunk/UFormMain.pas

    r5 r6  
    6767procedure TFormMain.FormPaint(Sender: TObject);
    6868begin
    69   Game.Render(Canvas);
     69  Game.Render(Canvas, Point(Width, Height - MainMenu1.Height));
    7070end;
    7171
  • trunk/UGame.pas

    r5 r6  
    4545    procedure New;
    4646    procedure Clear;
    47     procedure Render(Canvas: TCanvas);
     47    procedure Render(Canvas: TCanvas; CanvasSize: TPoint);
    4848    function MoveAll(Direction: TDirection): Integer;
    4949    procedure MoveCell(SourceCell, TargetCell: TCell);
     
    198198end;
    199199
    200 procedure TGame.Render(Canvas: TCanvas);
     200procedure TGame.Render(Canvas: TCanvas; CanvasSize: TPoint);
    201201var
    202202  X, Y: Integer;
     
    205205  Frame: TRect;
    206206  TextSize: TSize;
    207 const
    208   TopBarHeight = 32;
    209 begin
     207  TopBarHeight: Integer;
     208begin
     209  TopBarHeight := ScaleY(24, 96);
    210210  Canvas.Brush.Style := bsSolid;
    211211  Canvas.Brush.Color := clBlack;
    212212  Canvas.FillRect(0, 0, Canvas.Width, Canvas.Height);
    213213
     214  ValueStr := 'Score: ' + IntToStr(Score);
    214215  Canvas.Font.Color := clWhite;
    215   Canvas.Font.Height := 20;
    216   Canvas.TextOut(16, 4, 'Score: ' + IntToStr(Score));
    217 
    218   Frame := Rect(0, TopBarHeight, Canvas.Width, Canvas.Height);
     216  Canvas.Font.Height := Trunc(TopBarHeight * 0.7);
     217  Canvas.TextOut(ScaleY(16, 96), (TopBarHeight - Canvas.TextHeight(ValueStr)) div 2, ValueStr);
     218
     219  // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows.
     220  // So dimensions are provided by CanvasSize parameter.
     221  Frame := Rect(2, TopBarHeight, CanvasSize.X - 2, CanvasSize.Y - 2);
    219222  CellSize := Point(Frame.Width div Size.X, Frame.Height div Size.Y);
    220223  if CellSize.X < CellSize.Y then CellSize.Y := CellSize.X;
Note: See TracChangeset for help on using the changeset viewer.