Changeset 64


Ignore:
Timestamp:
Nov 26, 2020, 4:58:02 PM (4 years ago)
Author:
chronos
Message:
  • Added: Support for dark mode.
  • Added: Top left back button to exit from game to game menu. Allow to restart game and continue with playing.
  • Added: Support for Escape key for exiting game and menu.
Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/BigMetro.lpi

    r62 r64  
    8787      </Item2>
    8888    </RequiredPackages>
    89     <Units Count="6">
     89    <Units Count="7">
    9090      <Unit0>
    9191        <Filename Value="BigMetro.lpr"/>
     
    118118        <IsPartOfProject Value="True"/>
    119119      </Unit5>
     120      <Unit6>
     121        <Filename Value="UControls.pas"/>
     122        <IsPartOfProject Value="True"/>
     123      </Unit6>
    120124    </Units>
    121125  </ProjectOptions>
  • trunk/BigMetro.lpr

    r62 r64  
    88  {$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, SysUtils, UFormMain, UFormImages, Common, UMenu;
     10  Forms, SysUtils, UFormMain, UFormImages, Common, UMenu, UControls;
    1111
    1212{$R *.res}
  • trunk/Forms/UFormMain.pas

    r63 r64  
    6565procedure TFormMain.FormCreate(Sender: TObject);
    6666begin
     67  Engine := TEngine.Create;
    6768  LoadConfig;
    68   Engine := TEngine.Create;
    6969  //PaintBox1.ControlStyle := [csOpaque];
    7070  Randomize;
     
    8585procedure TFormMain.FormDestroy(Sender: TObject);
    8686begin
     87  SaveConfig;
    8788  Engine.Free;
    88   SaveConfig;
    8989end;
    9090
     
    103103begin
    104104  if Key = KeyF11 then begin
    105     FormMain.FullScreen := not FormMain.FullScreen;
    106     FormMain.PersistentForm1.SetFullScreen(FormMain.FullScreen);
    107   end;
     105    FullScreen := not FullScreen;
     106    PersistentForm1.SetFullScreen(FormMain.FullScreen);
     107  end else
     108    Engine.KeyUp(Key);
    108109end;
    109110
     
    112113  PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
    113114  PersistentForm1.Load(Self, False, True);
     115  FullScreen := PersistentForm1.FormFullScreen;
    114116  Randomize;
     117  Engine.InitMenus;
    115118  Engine.ImagePassenger.Picture.Assign(FormImages.ImagePassenger.Picture);
    116119  Engine.ImageLocomotive.Picture.Assign(FormImages.ImageLocomotive.Picture);
     
    185188      Translator1.Language := Translator1.Languages.SearchByCode(LangCode);
    186189    end else Translator1.Language := Translator1.Languages.SearchByCode('');
    187     //ThemeManager1.Theme := ThemeManager1.Themes.FindByName(ReadStringWithDefault('Theme', 'System'));
     190    Engine.DarkMode := ReadBoolWithDefault('DarkMode', False);
    188191  finally
    189192    Free;
     
    200203      WriteString('LanguageCode', Translator1.Language.Code)
    201204      else DeleteValue('LanguageCode');
    202     //WriteString('Theme', ThemeManager1.Theme.Name);
     205    WriteBool('DarkMode', Engine.DarkMode);
    203206  finally
    204207    Free;
  • trunk/Languages/BigMetro.cs.po

    r63 r64  
    5454msgstr "Big Metro"
    5555
     56#: umenu.scontinue
     57msgid "Continue"
     58msgstr "Pokračovat"
     59
    5660#: umenu.sczech
    5761msgid "Czech"
     
    8892msgid "Play"
    8993msgstr "Hrát"
     94
     95#: umenu.srestart
     96msgid "Try again"
     97msgstr "Zkusit znovu"
  • trunk/Languages/BigMetro.po

    r63 r64  
    4444msgstr ""
    4545
     46#: umenu.scontinue
     47msgid "Continue"
     48msgstr ""
     49
    4650#: umenu.sczech
    4751msgid "Czech"
     
    7983msgstr ""
    8084
     85#: umenu.srestart
     86msgid "Try again"
     87msgstr ""
     88
  • trunk/UEngine.pas

    r63 r64  
    2424  TTrackLink = class;
    2525  TTrackLinks = class;
     26
     27  TColors = record
     28    Background: TColor;
     29    Text: TColor;
     30    MenuItemText: TColor;
     31    MenuItemBackground: TColor;
     32    MenuItemBackgroundSelected: TColor;
     33  end;
    2634
    2735  { TMapStation }
     
    265273  TEngine = class
    266274  private
     275    FDarkMode: Boolean;
    267276    LastMousePos: TPoint;
    268277    LastFocusedStation: TMapStation;
     
    279288    MenuMain: TMenu;
    280289    MenuOptions: TMenu;
     290    MenuGame: TMenu;
     291    ButtonBack: TMenuItemButton;
    281292    procedure ResizeView;
    282293    function GetExistStationShapes: TStationShapeSet;
     
    292303    procedure ComputeShapeDistanceStation(Station: TMapStation;
    293304      UpdatedShape: TStationShape; Distance: Integer);
     305    procedure SetDarkMode(AValue: Boolean);
     306    procedure InitColors;
    294307    procedure TrainMovement;
    295308    function GetUnusedLine: TMetroLine;
     
    298311    procedure MenuItemPlay(Sender: TObject);
    299312    procedure MenuItemOptions(Sender: TObject);
     313    procedure MenuItemGameContinue(Sender: TObject);
     314    procedure MenuItemGameExit(Sender: TObject);
     315    procedure MenuItemGameRestart(Sender: TObject);
    300316    procedure MenuItemBack(Sender: TObject);
     317    procedure ButtonBackClick(Sender: TObject);
    301318    procedure DarkModeChanged(Sender: TObject);
    302319    procedure LanguageChanged(Sender: TObject);
    303320    procedure FullScreenChanged(Sender: TObject);
    304     procedure InitMenus;
    305321  public
     322    Colors: TColors;
    306323    Passengers: TMetroPassengers;
    307324    Stations: TMapStations;
     
    320337    ImagePassenger: TImage;
    321338    ImageLocomotive: TImage;
     339    procedure InitMenus;
    322340    procedure MouseMove(Position: TPoint);
    323341    procedure MouseUp(Button: TMouseButton; Position: TPoint);
    324342    procedure MouseDown(Button: TMouseButton; Position: TPoint);
     343    procedure KeyUp(Key: Word);
    325344    procedure MainMenu;
     345    procedure Clear;
    326346    procedure NewGame;
    327347    procedure Redraw;
     
    331351    procedure Paint(TargetCanvas: TCanvas);
    332352    property Time: TDateTime read FTime;
     353    property DarkMode: Boolean read FDarkMode write SetDarkMode;
    333354  end;
    334355
     
    16171638      end;
    16181639    end;
     1640  end;
     1641end;
     1642
     1643procedure TEngine.SetDarkMode(AValue: Boolean);
     1644begin
     1645  if FDarkMode = AValue then Exit;
     1646  FDarkMode := AValue;
     1647  InitColors;
     1648end;
     1649
     1650procedure TEngine.InitColors;
     1651begin
     1652  with Colors do
     1653  if FDarkMode then begin
     1654    Background := $2f3020;
     1655    Text := clWhite;
     1656    MenuItemText := $cccccc;
     1657    MenuItemBackground := $b75C01;
     1658    MenuItemBackgroundSelected := $070C81;
     1659  end else begin
     1660    Background := $eff0e0;
     1661    Text := clBlack;
     1662    MenuItemText := clWhite;
     1663    MenuItemBackground := $e78C31;
     1664    MenuItemBackgroundSelected := $f7bC61;
    16191665  end;
    16201666end;
     
    18721918    Menu := Menu.Parent;
    18731919    Redraw;
    1874   end;
     1920  end else MenuItemExit(nil);
     1921end;
     1922
     1923procedure TEngine.MenuItemGameContinue(Sender: TObject);
     1924begin
     1925  State := gsRunning;
     1926end;
     1927
     1928procedure TEngine.MenuItemGameExit(Sender: TObject);
     1929begin
     1930  State := gsMenu;
     1931  Clear;
     1932  Menu := MenuMain;
     1933  Redraw;
     1934end;
     1935
     1936procedure TEngine.MenuItemGameRestart(Sender: TObject);
     1937begin
     1938  NewGame;
    18751939end;
    18761940
    18771941procedure TEngine.DarkModeChanged(Sender: TObject);
    18781942begin
    1879 
     1943  DarkMode := TMenuItemCheckBox(Sender).Checked;
     1944  InitMenus;
    18801945end;
    18811946
     
    19001965procedure TEngine.InitMenus;
    19011966begin
    1902   with MenuMain.Items do begin
     1967  with MenuMain, Items do begin
    19031968    Clear;
    1904     AddButton(SPlay, MenuItemPlay);
    1905     AddButton(SOptions, MenuItemOptions);
    1906     AddButton(SExit, MenuItemExit);
    1907   end;
     1969    with AddButton(SBigMetro, nil) do begin
     1970      Enabled := False;
     1971      FontSize := 60;
     1972      FontColor := Colors.Text;
     1973      BackgroundColor := clNone;
     1974      BackgroundSelectedColor := clNone;
     1975    end;
     1976    with AddButton(SPlay, MenuItemPlay) do begin
     1977      FontSize := 40;
     1978      FontColor := Colors.MenuItemText;
     1979      BackgroundColor := Colors.MenuItemBackground;
     1980      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     1981    end;
     1982    with AddButton(SOptions, MenuItemOptions) do begin
     1983      FontSize := 40;
     1984      FontColor := Colors.MenuItemText;
     1985      BackgroundColor := Colors.MenuItemBackground;
     1986      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     1987    end;
     1988    with AddButton(SExit, MenuItemExit) do begin
     1989      FontSize := 40;
     1990      FontColor := Colors.MenuItemText;
     1991      BackgroundColor := Colors.MenuItemBackground;
     1992      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     1993    end;
     1994    OnExit := MenuItemExit;
     1995  end;
     1996
    19081997  MenuOptions.Parent := MenuMain;
    1909   with MenuOptions.Items do begin
     1998  with MenuOptions, Items do begin
    19101999    Clear;
    19112000    with AddComboBox(SLanguage, [], LanguageChanged) do begin
     2001      FontSize := 40;
     2002      FontColor := Colors.MenuItemText;
     2003      BackgroundColor := Colors.MenuItemBackground;
     2004      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
    19122005      FormMain.Translator1.LanguageListToStrings(States);
    19132006      Index := States.IndexOfObject(FormMain.Translator1.Language);
    19142007      if Index = -1 then Index := 0;
    19152008    end;
    1916     AddCheckBox(SDarkMode, DarkModeChanged);
     2009    with AddCheckBox(SDarkMode, DarkModeChanged) do begin
     2010      FontSize := 40;
     2011      FontColor := Colors.MenuItemText;
     2012      BackgroundColor := Colors.MenuItemBackground;
     2013      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     2014      Checked := DarkMode;
     2015    end;
    19172016    with AddCheckBox(SFullScreen, FullScreenChanged) do begin
     2017      FontSize := 40;
     2018      FontColor := Colors.MenuItemText;
     2019      BackgroundColor := Colors.MenuItemBackground;
     2020      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
    19182021      Checked := FormMain.FullScreen;
    19192022    end;
    1920     AddButton(SBack, MenuItemBack);
    1921   end;
     2023    with AddButton(SBack, MenuItemBack) do begin
     2024      FontSize := 40;
     2025      FontColor := Colors.MenuItemText;
     2026      BackgroundColor := Colors.MenuItemBackground;
     2027      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     2028    end;
     2029    OnExit := MenuItemBack;
     2030  end;
     2031
     2032  with MenuGame, Items do begin
     2033    Clear;
     2034    with AddButton(SContinue, MenuItemGameContinue) do begin
     2035      FontSize := 40;
     2036      FontColor := Colors.MenuItemText;
     2037      BackgroundColor := Colors.MenuItemBackground;
     2038      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     2039    end;
     2040    with AddButton(SRestart, MenuItemGameRestart) do begin
     2041      FontSize := 40;
     2042      FontColor := Colors.MenuItemText;
     2043      BackgroundColor := Colors.MenuItemBackground;
     2044      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     2045    end;
     2046    with AddButton(SExit, MenuItemGameExit) do begin
     2047      FontSize := 40;
     2048      FontColor := Colors.MenuItemText;
     2049      BackgroundColor := Colors.MenuItemBackground;
     2050      BackgroundSelectedColor := Colors.MenuItemBackgroundSelected;
     2051    end;
     2052    OnExit := MenuItemGameContinue;
     2053  end;
     2054end;
     2055
     2056procedure TEngine.ButtonBackClick(Sender: TObject);
     2057begin
     2058  Menu := MenuGame;
     2059  State := gsMenu;
     2060  Redraw;
    19222061end;
    19232062
     
    19322071begin
    19332072  Canvas.Pen.Style := psSolid;
    1934   Canvas.Pen.Color := clBlack;
     2073  Canvas.Pen.Color := Colors.Text;
    19352074  Canvas.Pen.Width := 2;
    19362075  ClockCenter := Point(Canvas.Width - 30, 40);
     
    21442283      Redraw;
    21452284    end else begin
    2146         // Place selected train if focused track
     2285      // Back button
     2286      if ButtonBack.Bounds.Contains(Position) then begin
     2287        if Assigned(ButtonBack.OnClick) then
     2288          ButtonBack.OnClick(ButtonBack);
     2289      end;
     2290
     2291      // Place selected train if focused track
    21472292      if Assigned(SelectedTrain) then begin
    21482293        SelectedTrain.TargetStation := nil;
     
    22002345begin
    22012346  if Button = mbLeft then begin
     2347    if State <> gsMenu then begin
    22022348    MouseHold := True;
    22032349    LastFocusedStation := nil;
     
    22542400      end;
    22552401    end;
     2402    end;
     2403  end;
     2404end;
     2405
     2406procedure TEngine.KeyUp(Key: Word);
     2407const
     2408  KeyEsc = 27;
     2409begin
     2410  if Key = KeyEsc then begin
     2411    if State = gsMenu then begin
     2412      if Assigned(Menu.OnExit) then
     2413        Menu.OnExit(nil);
     2414    end else begin
     2415      ButtonBackClick(nil);
     2416    end;
    22562417  end;
    22572418end;
     
    22632424end;
    22642425
    2265 procedure TEngine.NewGame;
    2266 var
    2267   NewTrain: TMetroTrain;
    2268   I: Integer;
    2269   NewStation: TMapStation;
    2270   InitialStationCount: Integer;
    2271 begin
     2426procedure TEngine.Clear;
     2427begin
     2428  Trains.Clear;
    22722429  Passengers.Clear;
    22732430  Lines.Clear;
    22742431  Stations.Clear;
    2275 
     2432end;
     2433
     2434procedure TEngine.NewGame;
     2435var
     2436  NewTrain: TMetroTrain;
     2437  I: Integer;
     2438  NewStation: TMapStation;
     2439  InitialStationCount: Integer;
     2440begin
     2441  Clear;
    22762442  ShapeCount := 3;
    22772443  ServedPassengerCount := 0;
     
    23132479constructor TEngine.Create;
    23142480begin
     2481  ButtonBack := TMenuItemButton.Create;
     2482  ButtonBack.Text := '🡸';
     2483  ButtonBack.OnClick := ButtonBackClick;
     2484  ButtonBack.BackgroundColor := clNone;
    23152485  MenuMain := TMenu.Create;
    23162486  MenuOptions := TMenu.Create;
     2487  MenuGame := TMenu.Create;
    23172488  Menu := MenuMain;
    23182489  InitMenus;
     
    23332504  //  ImageLocomotive.Picture.LoadFromFile(ImageLocomotiveName);
    23342505  MetaCanvas := TMetaCanvas.Create;
     2506  InitColors;
    23352507end;
    23362508
     
    23482520  FreeAndNil(MenuMain);
    23492521  FreeAndNil(MenuOptions);
     2522  FreeAndNil(MenuGame);
     2523  FreeAndNil(ButtonBack);
    23502524  inherited;
    23512525end;
     
    25122686
    25132687  // MainMenu background
    2514   TargetCanvas.Brush.Color := $eff0e0;
     2688  TargetCanvas.Brush.Color := Colors.Background;
    25152689  TargetCanvas.Brush.Style := bsSolid;
    25162690  TargetCanvas.Clear;
     
    25332707        Size := 5;
    25342708      end;
    2535       TargetCanvas.Pen.Color := clBlack;
     2709      TargetCanvas.Pen.Color := Colors.Text;
    25362710      if Assigned(SelectedLine) and (SelectedLine.Color = LineColors[I]) then begin
    25372711        TargetCanvas.Pen.Style := psSolid;
     
    25502724    TargetCanvas.Brush.Style := bsClear;
    25512725    TargetCanvas.Font.Size := 14;
    2552     TargetCanvas.Font.Color := clBlack;
     2726    TargetCanvas.Font.Color := Colors.Text;
    25532727    TargetCanvas.TextOut(TargetCanvas.Width div 2 - Length(LineColors) div 2 * LineColorsDist - 50 - TargetCanvas.TextWidth(Text),
    25542728      TargetCanvas.Height - LineColorsDist - TargetCanvas.TextHeight(Text) div 2, Text);
     
    25592733    TargetCanvas.Brush.Style := bsClear;
    25602734    TargetCanvas.Font.Size := 14;
    2561     TargetCanvas.Font.Color := clBlack;
     2735    TargetCanvas.Font.Color := Colors.Text;
    25622736    TargetCanvas.TextOut(TargetCanvas.Width - 70 - TargetCanvas.TextWidth(Text), TargetCanvas.Height - 55, Text);
    25632737
    25642738    DrawClock(TargetCanvas);
     2739
     2740    // Back button
     2741    TargetCanvas.Font.Size := 40;
     2742    TargetCanvas.Font.Color := Colors.Text;
     2743    ButtonBack.Paint(TargetCanvas, Point(10, 10));
    25652744  end;
    25662745
    25672746  // Show train grabbed by mouse
    25682747  if Assigned(SelectedTrain) then begin
    2569     TargetCanvas.Brush.Color := clBlack; //SelectedTrain.Line.Color;
     2748    TargetCanvas.Brush.Color := Colors.Text; //SelectedTrain.Line.Color;
    25702749    TargetCanvas.Brush.Style := bsSolid;
    25712750    TargetCanvas.Pen.Style := psClear;
     
    25852764  begin
    25862765    TargetCanvas.Font.Size := 40;
    2587     TargetCanvas.Font.Color := clBlack;
     2766    TargetCanvas.Font.Color := Colors.Text;
    25882767    TargetCanvas.TextOut((TargetCanvas.Width - TargetCanvas.TextWidth(SGameOver)) div 2, 100, SGameOver);
    25892768    TargetCanvas.Font.Size := 14;
  • trunk/UMenu.pas

    r63 r64  
    1414
    1515  TMenuItem = class
     16    BackgroundColor: TColor;
     17    BackgroundSelectedColor: TColor;
    1618    Kind: TMenuItemKind;
    1719    Text: string;
    1820    Bounds: TRect;
    1921    Selected: Boolean;
     22    FontSize: Integer;
     23    FontColor: Integer;
     24    Enabled: Boolean;
    2025    procedure Paint(Canvas: TCanvas; P: TPoint); virtual;
     26    function GetOutputText: string; virtual;
     27    constructor Create;
    2128  end;
    2229
     
    4350    destructor Destroy; override;
    4451    procedure Paint(Canvas: TCanvas; P: TPoint); override;
     52    function GetOutputText: string; override;
    4553    property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
    4654  end;
     
    6674
    6775  TMenu = class
     76  private
     77    FOnExit: TNotifyEvent;
     78  public
    6879    Items: TMenuItems;
    6980    Parent: TMenu;
     
    7384    constructor Create;
    7485    destructor Destroy; override;
     86    property OnExit: TNotifyEvent read FOnExit write FOnExit;
    7587  end;
    7688
     
    8799  SAutomatic = 'Automatic';
    88100  SFullScreen = 'Full screen';
     101  SContinue = 'Continue';
     102  SRestart = 'Try again';
    89103
    90104
     
    95109procedure TMenuItemButton.Paint(Canvas: TCanvas; P: TPoint);
    96110begin
    97   if Selected then Canvas.Brush.Color := $e78C31
    98     else Canvas.Brush.Color := $f7bC61;
     111  if Selected then Canvas.Brush.Color := BackgroundSelectedColor
     112    else Canvas.Brush.Color := BackgroundColor;
     113  if Canvas.Brush.Color = clNone then Canvas.Brush.Style := bsClear
     114    else Canvas.Brush.Style := bsSolid;
    99115  Bounds := Classes.Bounds(P.X, P.Y, Canvas.TextWidth(Text), Canvas.TextHeight(Text));
    100116  Canvas.TextOut(P.X, P.Y, Text);
     
    109125  OutputText := Text;
    110126  if Checked then OutputText := '✓' + OutputText;
    111   if Selected then Canvas.Brush.Color := $e78C31
    112     else Canvas.Brush.Color := $f7bC61;
     127  if Selected then Canvas.Brush.Color := BackgroundSelectedColor
     128    else Canvas.Brush.Color := BackgroundColor;
     129  if Canvas.Brush.Color = clNone then Canvas.Brush.Style := bsClear
     130    else Canvas.Brush.Style := bsSolid;
    113131  Bounds := Classes.Bounds(P.X, P.Y, Canvas.TextWidth(OutputText), Canvas.TextHeight(OutputText));
    114132  Canvas.TextOut(P.X, P.Y, OutputText);
     
    121139end;
    122140
     141function TMenuItem.GetOutputText: string;
     142begin
     143  Result := Text;
     144end;
     145
     146constructor TMenuItem.Create;
     147begin
     148  Enabled := True;
     149  FontSize := 40;
     150  FontColor := clWhite;
     151end;
     152
    123153{ TMenuItemComboBox }
    124154
     
    135165
    136166procedure TMenuItemComboBox.Paint(Canvas: TCanvas; P: TPoint);
    137 var
    138   OutputText: string;
    139 begin
    140   if Selected then Canvas.Brush.Color := $e78C31
    141     else Canvas.Brush.Color := $f7bC61;
    142   OutputText := Text + ': ' + States[Index];
    143   Bounds := Classes.Bounds(P.X, P.Y, Canvas.TextWidth(OutputText), Canvas.TextHeight(OutputText));
    144   Canvas.TextOut(P.X, P.Y, OutputText);
     167begin
     168  if Selected then Canvas.Brush.Color := BackgroundSelectedColor
     169    else Canvas.Brush.Color := BackgroundColor;
     170  if Canvas.Brush.Color = clNone then Canvas.Brush.Style := bsClear
     171    else Canvas.Brush.Style := bsSolid;
     172  Bounds := Classes.Bounds(P.X, P.Y, Canvas.TextWidth(GetOutputText), Canvas.TextHeight(GetOutputText));
     173  Canvas.TextOut(P.X, P.Y, GetOutputText);
     174end;
     175
     176function TMenuItemComboBox.GetOutputText: string;
     177begin
     178  Result := Text + ': ' + States[Index];
    145179end;
    146180
     
    152186begin
    153187  for I := 0 to Items.Count - 1 do begin
    154     Items[I].Selected := Items[I].Bounds.Contains(Position);
     188    if Items[I].Enabled then
     189      Items[I].Selected := Items[I].Bounds.Contains(Position);
    155190  end;
    156191end;
     
    187222  Y: Integer;
    188223  LineHeight: Integer;
     224  TotalWidth: Integer;
     225  TotalHeight: Integer;
    189226begin
    190227  with Canvas do begin
    191     X := Width div 3;
    192     Y := Height div 5;
    193 
    194     // Title
    195     Font.Size := 60;
    196     Font.Color := clBlack;
    197     Font.Style := [fsBold];
    198     Brush.Style := bsClear;
    199     TextOut(X, Y, SBigMetro);
    200     LineHeight := Round(TextHeight('I') * 1.1);
    201     Inc(Y, LineHeight);
    202 
    203     // Menu items
    204     Font.Size := 40;
    205     Font.Color := clWhite;
     228    TotalWidth := 0;
     229    TotalHeight := 0;
     230
     231    // Calculate total dimensions for centering
    206232    Font.Style := [fsBold];
    207233    Brush.Style := bsSolid;
    208     LineHeight := Round(TextHeight('I') * 1.1);
    209234    for I := 0 to Items.Count - 1 do begin
     235      Font.Size := Items[I].FontSize;
     236      if TotalWidth < TextWidth(Items[I].GetOutputText) then
     237        TotalWidth := TextWidth(Items[I].GetOutputText);
     238      LineHeight := Round(TextHeight('I') * 1.1);
     239      TotalHeight := TotalHeight + LineHeight;
     240    end;
     241
     242    X := (Width - TotalWidth) div 2;
     243    Y := (Height - TotalHeight) div 2;
     244
     245    // Menu items
     246    Font.Style := [fsBold];
     247    Brush.Style := bsSolid;
     248    for I := 0 to Items.Count - 1 do begin
     249      Font.Size := Items[I].FontSize;
     250      Font.Color := Items[I].FontColor;
    210251      Items[I].Paint(Canvas, Point(X, Y));
     252      LineHeight := Round(TextHeight('I') * 1.1);
    211253      Inc(Y, LineHeight);
    212254    end;
Note: See TracChangeset for help on using the changeset viewer.