Changeset 102 for trunk/Game.pas
- Timestamp:
- Dec 9, 2024, 11:55:53 AM (13 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Game.pas
r100 r102 119 119 procedure DoPaint; 120 120 procedure RenderTile(Canvas: TCanvas; Tile: TTile; TileRect: TRect; WithText: Boolean); 121 procedure RenderControls(Canvas: TCanvas; Rect: TRect; Horizontal: Boolean); 122 function RenderTextBox(Canvas: TCanvas; Pos: TPoint; Title, Value: string): TSize; 121 123 procedure GameOver; 122 124 procedure SetColorPalette(AValue: TColorPalette); … … 185 187 resourcestring 186 188 SScore = 'Score'; 187 STopScore = ' Top score';189 STopScore = 'Best'; 188 190 SSkinLinear = 'Linear'; 189 191 SSkinPowerOfTwo = 'Power of two'; … … 643 645 X, Y: Integer; 644 646 TileSize: TPoint; 645 ValueStr: string;646 647 Frame: TRect; 647 648 TileRect: TRect; 648 649 TopBarHeight: Integer; 650 LeftBarWidth: Integer; 649 651 TileMargin: Integer; 650 652 TileCenter: TPoint; … … 652 654 MetaCanvas: TMetaCanvas; 653 655 BorderSize: Integer; 654 begin 656 ControlsRect: TRect; 657 BoardRect: TRect; 658 Horizontal: Boolean; 659 begin 660 // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows. 661 // So dimensions are provided by CanvasSize parameter. 662 655 663 MetaCanvas := TMetaCanvas.Create; 656 664 MetaCanvas.Size := Point(Canvas.Width, Canvas.Height); 657 665 658 TopBarHeight := ScaleY(24, 96);666 // Clear background 659 667 MetaCanvas.Brush.Style := bsSolid; 660 668 MetaCanvas.Brush.Color := Core.Core.ThemeManager1.Theme.ColorControl; 661 669 MetaCanvas.FillRect(0, 0, MetaCanvas.Width, MetaCanvas.Height); 662 670 663 ValueStr := SScore + ': ' + IntToStr(Score); 664 MetaCanvas.Brush.Style := bsClear; 665 MetaCanvas.Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText; 666 MetaCanvas.Font.Height := Trunc(TopBarHeight * 0.7); 667 MetaCanvas.TextOut(ScaleY(16, 96), (TopBarHeight - MetaCanvas.TextHeight(ValueStr)) div 2, ValueStr); 668 669 ValueStr := STopScore + ': ' + IntToStr(TopScore); 670 MetaCanvas.Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText; 671 MetaCanvas.Font.Height := Trunc(TopBarHeight * 0.7); 672 MetaCanvas.TextOut(ScaleY(136, 96), (TopBarHeight - MetaCanvas.TextHeight(ValueStr)) div 2, ValueStr); 673 674 // Form.Canvas.Width and Form.Canvas.Height is not working correctly under Windows. 675 // So dimensions are provided by CanvasSize parameter. 671 TopBarHeight := ScaleY(55, 96); 672 LeftBarWidth := ScaleY(90, 96); 673 if CanvasSize.X - LeftBarWidth < Canvas.Height then begin 674 ControlsRect := Rect(0, 0, CanvasSize.X, TopBarHeight); 675 BoardRect := Rect(0, TopBarHeight, CanvasSize.X, CanvasSize.Y); 676 Horizontal := True; 677 end else begin 678 ControlsRect := Rect(0, 0, LeftBarWidth, CanvasSize.Y); 679 BoardRect := Rect(LeftBarWidth, 0, CanvasSize.X, CanvasSize.Y); 680 Horizontal := False; 681 end; 682 683 RenderControls(MetaCanvas, ControlsRect, Horizontal); 684 676 685 BorderSize := ScaleY(2, 96); 677 Frame := Rect(BorderSize, BorderSize + TopBarHeight, CanvasSize.X - BorderSize, CanvasSize.Y - BorderSize); 686 Frame := Rect(BoardRect.Left + BorderSize, BoardRect.Top + BorderSize, 687 BoardRect.Right - BorderSize, BoardRect.Bottom - BorderSize); 688 678 689 TileSize := Point(Frame.Width div Board.Size.X, Frame.Height div Board.Size.Y); 679 690 if TileSize.X < TileSize.Y then TileSize.Y := TileSize.X; … … 849 860 end; 850 861 862 procedure TGame.RenderControls(Canvas: TCanvas; Rect: TRect; Horizontal: Boolean); 863 var 864 Pos: TPoint; 865 Size: TSize; 866 begin 867 if Horizontal then Pos := Point(ScaleY(16, 96), ScaleY(4, 96)) 868 else Pos := Point(ScaleY(4, 96), ScaleY(16, 96)); 869 870 Size := RenderTextBox(Canvas, Pos, SScore, IntToStr(Score)); 871 872 if Horizontal then Pos := Point(ScaleY(16 + 16, 96) + Size.Width, ScaleY(4, 96)) 873 else Pos := Point(ScaleY(4, 96), ScaleY(16 + 16, 96) + Size.Height); 874 875 Size := RenderTextBox(Canvas, Pos, STopScore, IntToStr(TopScore)); 876 end; 877 878 function TGame.RenderTextBox(Canvas: TCanvas; Pos: TPoint; Title, Value: string 879 ): TSize; 880 var 881 BoxSize: TSize; 882 begin 883 with Canvas do begin 884 Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText; 885 Font.Height := Trunc(24); 886 887 BoxSize := Size(TextWidth(Title), TextHeight(Title) + TextHeight(Value)); 888 if BoxSize.Width < TextWidth(Value) then BoxSize.Width := TextWidth(Value); 889 BoxSize := Size(Round(BoxSize.Width * 1.2), Round(BoxSize.Height * 1)); 890 891 Brush.Style := bsSolid; 892 Brush.Color := Core.Core.ThemeManager1.Theme.ColorWindow; 893 FillRect(Pos.X, Pos.Y, Pos.X + BoxSize.Width, Pos.Y + BoxSize.Height); 894 895 Brush.Style := bsClear; 896 TextOut(Pos.X + (BoxSize.Width - TextWidth(Title)) div 2, Pos.Y, Title); 897 898 Brush.Style := bsClear; 899 Font.Color := Core.Core.ThemeManager1.Theme.ColorControlText; 900 Font.Height := Trunc(24); 901 TextOut(Pos.X + (BoxSize.Width - TextWidth(Value)) div 2, 902 Pos.Y + TextHeight(Title), Value); 903 end; 904 905 Result := BoxSize; 906 end; 907 851 908 function TGame.CanUndo: Boolean; 852 909 begin
Note:
See TracChangeset
for help on using the changeset viewer.