Changeset 64 for trunk/UMenu.pas
- Timestamp:
- Nov 26, 2020, 4:58:02 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMenu.pas
r63 r64 14 14 15 15 TMenuItem = class 16 BackgroundColor: TColor; 17 BackgroundSelectedColor: TColor; 16 18 Kind: TMenuItemKind; 17 19 Text: string; 18 20 Bounds: TRect; 19 21 Selected: Boolean; 22 FontSize: Integer; 23 FontColor: Integer; 24 Enabled: Boolean; 20 25 procedure Paint(Canvas: TCanvas; P: TPoint); virtual; 26 function GetOutputText: string; virtual; 27 constructor Create; 21 28 end; 22 29 … … 43 50 destructor Destroy; override; 44 51 procedure Paint(Canvas: TCanvas; P: TPoint); override; 52 function GetOutputText: string; override; 45 53 property OnChanged: TNotifyEvent read FOnChanged write FOnChanged; 46 54 end; … … 66 74 67 75 TMenu = class 76 private 77 FOnExit: TNotifyEvent; 78 public 68 79 Items: TMenuItems; 69 80 Parent: TMenu; … … 73 84 constructor Create; 74 85 destructor Destroy; override; 86 property OnExit: TNotifyEvent read FOnExit write FOnExit; 75 87 end; 76 88 … … 87 99 SAutomatic = 'Automatic'; 88 100 SFullScreen = 'Full screen'; 101 SContinue = 'Continue'; 102 SRestart = 'Try again'; 89 103 90 104 … … 95 109 procedure TMenuItemButton.Paint(Canvas: TCanvas; P: TPoint); 96 110 begin 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; 99 115 Bounds := Classes.Bounds(P.X, P.Y, Canvas.TextWidth(Text), Canvas.TextHeight(Text)); 100 116 Canvas.TextOut(P.X, P.Y, Text); … … 109 125 OutputText := Text; 110 126 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; 113 131 Bounds := Classes.Bounds(P.X, P.Y, Canvas.TextWidth(OutputText), Canvas.TextHeight(OutputText)); 114 132 Canvas.TextOut(P.X, P.Y, OutputText); … … 121 139 end; 122 140 141 function TMenuItem.GetOutputText: string; 142 begin 143 Result := Text; 144 end; 145 146 constructor TMenuItem.Create; 147 begin 148 Enabled := True; 149 FontSize := 40; 150 FontColor := clWhite; 151 end; 152 123 153 { TMenuItemComboBox } 124 154 … … 135 165 136 166 procedure 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); 167 begin 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); 174 end; 175 176 function TMenuItemComboBox.GetOutputText: string; 177 begin 178 Result := Text + ': ' + States[Index]; 145 179 end; 146 180 … … 152 186 begin 153 187 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); 155 190 end; 156 191 end; … … 187 222 Y: Integer; 188 223 LineHeight: Integer; 224 TotalWidth: Integer; 225 TotalHeight: Integer; 189 226 begin 190 227 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 206 232 Font.Style := [fsBold]; 207 233 Brush.Style := bsSolid; 208 LineHeight := Round(TextHeight('I') * 1.1);209 234 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; 210 251 Items[I].Paint(Canvas, Point(X, Y)); 252 LineHeight := Round(TextHeight('I') * 1.1); 211 253 Inc(Y, LineHeight); 212 254 end;
Note:
See TracChangeset
for help on using the changeset viewer.