Changeset 4 for trunk/UGame.pas


Ignore:
Timestamp:
Sep 24, 2019, 8:22:47 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Keep aspect ration of board and center it.
  • Added: Build modes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r3 r4  
    200200  CellSize: TPoint;
    201201  ValueStr: string;
     202  Frame: TRect;
    202203begin
    203204  CellSize := Point(Canvas.Width div Size.X, Canvas.Height div Size.Y);
     205  if CellSize.X < CellSize.Y then CellSize.Y := CellSize.X;
     206  if CellSize.Y < CellSize.X then CellSize.X := CellSize.Y;
     207  Frame := Rect(Canvas.Width div 2 - (Size.X * CellSize.X) div 2,
     208    Canvas.Height div 2 - (Size.Y * CellSize.Y) div 2,
     209    Canvas.Width div 2 + (Size.X * CellSize.X) div 2,
     210    Canvas.Height div 2 + (Size.Y * CellSize.Y) div 2);
     211
    204212  Canvas.FillRect(0, 0, Canvas.Width, Canvas.Height);
    205213  Canvas.Font.Color := clBlack;
     
    209217      Canvas.Brush.Color := GetCellColor(Cells[Y, X].Value);
    210218      Canvas.Brush.Style := bsSolid;
    211       Canvas.FillRect(Rect(X * CellSize.X, Y * CellSize.Y,
    212         (X + 1) * CellSize.X, (Y + 1) * CellSize.Y));
     219      Canvas.FillRect(Rect(Frame.Left + X * CellSize.X, Frame.Top + Y * CellSize.Y,
     220        Frame.Left + (X + 1) * CellSize.X, Frame.Top + (Y + 1) * CellSize.Y));
    213221      if Cells[Y, X].Value <> 0 then begin
    214222        ValueStr := IntToStr(Cells[Y, X].Value);
    215         Canvas.TextOut(X * CellSize.X + CellSize.X div 2 -
    216           Canvas.TextWidth(ValueStr) div 2, Y * CellSize.Y, ValueStr);
     223        Canvas.TextOut(Frame.Left + X * CellSize.X + CellSize.X div 2 -
     224          Canvas.TextWidth(ValueStr) div 2,
     225          Frame.Top + Y * CellSize.Y, ValueStr);
    217226      end;
    218227    end;
    219228
    220229  for Y := 0 to Size.Y - 1 do begin
    221     Canvas.MoveTo(0, Y * CellSize.Y);
    222     Canvas.LineTo(Canvas.Width, Y * CellSize.Y);
     230    Canvas.MoveTo(Frame.Left, Frame.Top + Y * CellSize.Y);
     231    Canvas.LineTo(Frame.Left + Size.X * CellSize.X, Frame.Top + Y * CellSize.Y);
    223232  end;
    224233  for X := 0 to Size.X - 1 do begin
    225     Canvas.MoveTo(X * CellSize.X, 0);
    226     Canvas.LineTo(X * CellSize.X, Canvas.Height);
    227   end;
     234    Canvas.MoveTo(Frame.Left + X * CellSize.X, Frame.Top);
     235    Canvas.LineTo(Frame.Left + X * CellSize.X, Frame.Top + Size.Y * CellSize.Y);
     236  end;
     237  Canvas.Brush.Style := bsClear;
     238  Canvas.Rectangle(Frame);
    228239end;
    229240
Note: See TracChangeset for help on using the changeset viewer.