Class TCastleOnScreenMenu

Unit

Declaration

type TCastleOnScreenMenu = class(TCastleUserInterfaceFont)

Description

On-screen menu, with all menu items displayed on the screen, one under another. Often used for game "main menu" screen. Normal tools may prefer to use the normal menu bar (TCastleWindowBase.MainMenu, or normal Lazarus main menu) instead of this.

Each clickable menu item should be a TCastleOnScreenMenuItem descendant, and should be added to the MenuItems list. The TCastleOnScreenMenuItem.Menu should be set to point back to the menu instance, this way it can look at menu's properties like desired color and font. You can also add other controls to MenuItems – it's a simple TCastleVerticalGroup, all the controls are just displayed one under another. E.g. you can add TCastleLabel to have non-clickable text, or you can add TCastleUserInterface with explicit TCastleUserInterface.Height to add some vertical space.

Hierarchy

Overview

Fields

Public nested const DefaultMenuKeyNextItem = K_Down;
Public nested const DefaultMenuKeyPreviousItem = K_Up;
Public nested const DefaultMenuKeySelectItem = K_Enter;
Public nested const DefaultCurrentItemBorderColor1: TCastleColor = (Data: (1.0, 1.0, 1.0, 1.0)) ;
Public nested const DefaultCurrentItemBorderColor2: TCastleColor = (Data: (0.5, 0.5, 0.5, 1.0)) ;
Public nested const DefaultCurrentItemColor : TCastleColor = (Data: (1.0, 1.0, 0.0, 1.0)) ;
Public nested const DefaultNonCurrentItemColor : TCastleColor = (Data: (1.0, 1.0, 1.0, 1.0)) ;
Public nested const DefaultNonFocusableItemColor : TCastleColor = (Data: (0.75, 0.75, 0.75, 1.0)) ;
Public nested const DefaultRegularSpaceBetweenItems = 10;
Public nested const DefaultBackgroundOpacityNotFocused = 0.4;
Public nested const DefaultBackgroundOpacityFocused = 0.7;

Methods

Protected procedure BeforeSizing; override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Add(const S: string);
Public procedure Add(const S: string; const Accessory: TCastleUserInterface);
Public procedure Add(const S: string; const ItemOnClick: TNotifyEvent);
Public procedure Add(const NewItem: TCastleUserInterface);
Public procedure NextItem;
Public procedure PreviousItem;
Public function CapturesEventsAtPosition(const Position: TVector2): boolean; override;
Public procedure Render; override;
Public function Press(const Event: TInputPressRelease): boolean; override;
Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;
Public function AllowSuspendForInput: boolean; override;
Public procedure Click; virtual; deprecated 'use TCastleMenuButton and it''s OnClick event';
Public procedure CurrentItemSelected; virtual; deprecated 'use TCastleMenuButton and it''s OnClick event';
Public procedure CurrentItemChanged; virtual;
Public procedure CurrentItemChangedByUser; virtual;
Public function SpaceBetweenItems(const NextItemIndex: Cardinal): Single; virtual; deprecated 'ignored now; if you want to add extra space, add TCastleUserInterface with explicit Height to MenuItems';

Properties

Public property CurrentItem: Integer read GetCurrentItem write SetCurrentItem;
Public property KeyNextItem: TKey read FKeyNextItem write FKeyNextItem default DefaultMenuKeyNextItem;
Public property KeyPreviousItem: TKey read FKeyPreviousItem write FKeyPreviousItem default DefaultMenuKeyPreviousItem;
Public property KeySelectItem: TKey read FKeySelectItem write FKeySelectItem default DefaultMenuKeySelectItem;
Public property CurrentItemBorderColor1: TCastleColor read FCurrentItemBorderColor1 write FCurrentItemBorderColor1;
Public property CurrentItemBorderColor2: TCastleColor read FCurrentItemBorderColor2 write FCurrentItemBorderColor2;
Public property CurrentItemColor: TCastleColor read FCurrentItemColor write FCurrentItemColor;
Public property NonCurrentItemColor: TCastleColor read FNonCurrentItemColor write FNonCurrentItemColor;
Public property NonFocusableItemColor: TCastleColor read FNonFocusableItemColor write FNonFocusableItemColor;
Public property OnClick: TNotifyEvent read FOnClick write FOnClick; deprecated 'use Add method to add a particular menu item with it''s own click callback; or just add TCastleMenuButton and handle it''s OnClick event';
Published property AutoSizeToChildren default true;
Published property MenuItems: TCastleVerticalGroup read FMenuItems;
Published property BackgroundOpacityFocused: Single read FBackgroundOpacityFocused write FBackgroundOpacityFocused default DefaultBackgroundOpacityFocused;
Published property BackgroundOpacityNotFocused: Single read FBackgroundOpacityNotFocused write FBackgroundOpacityNotFocused default DefaultBackgroundOpacityNotFocused;
Published property DrawBackgroundRectangle: boolean read FDrawBackgroundRectangle write FDrawBackgroundRectangle default true;
Published property RegularSpaceBetweenItems: Single read FRegularSpaceBetweenItems write SetRegularSpaceBetweenItems default DefaultRegularSpaceBetweenItems;
Published property DrawFocusedBorder: boolean read FDrawFocusedBorder write FDrawFocusedBorder default true;
Published property CaptureAllEvents: boolean read FCaptureAllEvents write FCaptureAllEvents default false;
Published property CurrentItemBorderColor1Persistent: TCastleColorPersistent read FCurrentItemBorderColor1Persistent ;
Published property CurrentItemBorderColor2Persistent: TCastleColorPersistent read FCurrentItemBorderColor2Persistent ;
Published property CurrentItemColorPersistent: TCastleColorPersistent read FCurrentItemColorPersistent ;
Published property NonCurrentItemColorPersistent: TCastleColorPersistent read FNonCurrentItemColorPersistent ;
Published property NonFocusableItemColorPersistent: TCastleColorPersistent read FNonFocusableItemColorPersistent ;

Description

Fields

Public nested const DefaultMenuKeyNextItem = K_Down;
 
Public nested const DefaultMenuKeyPreviousItem = K_Up;
 
Public nested const DefaultMenuKeySelectItem = K_Enter;
 
Public nested const DefaultCurrentItemBorderColor1: TCastleColor = (Data: (1.0, 1.0, 1.0, 1.0)) ;
 
Public nested const DefaultCurrentItemBorderColor2: TCastleColor = (Data: (0.5, 0.5, 0.5, 1.0)) ;
 
Public nested const DefaultCurrentItemColor : TCastleColor = (Data: (1.0, 1.0, 0.0, 1.0)) ;
 
Public nested const DefaultNonCurrentItemColor : TCastleColor = (Data: (1.0, 1.0, 1.0, 1.0)) ;
 
Public nested const DefaultNonFocusableItemColor : TCastleColor = (Data: (0.75, 0.75, 0.75, 1.0)) ;
 
Public nested const DefaultRegularSpaceBetweenItems = 10;
 
Public nested const DefaultBackgroundOpacityNotFocused = 0.4;
 
Public nested const DefaultBackgroundOpacityFocused = 0.7;
 

Methods

Protected procedure BeforeSizing; override;
 
Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure Add(const S: string);
 
Public procedure Add(const S: string; const Accessory: TCastleUserInterface);
 
Public procedure Add(const S: string; const ItemOnClick: TNotifyEvent);
 
Public procedure Add(const NewItem: TCastleUserInterface);
 
Public procedure NextItem;

Change CurrentItem to next or previous. Usually you will just let this class call it internally (from Motion, KeyDown etc.) and will not need to call it yourself.

Parameters
UserAction
Determines should we play a sound when user changes menu items.
Public procedure PreviousItem;
 
Public function CapturesEventsAtPosition(const Position: TVector2): boolean; override;
 
Public procedure Render; override;
 
Public function Press(const Event: TInputPressRelease): boolean; override;
 
Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;
 
Public function AllowSuspendForInput: boolean; override;
 
Public procedure Click; virtual; deprecated 'use TCastleMenuButton and it''s OnClick event';

Warning: this symbol is deprecated: use TCastleMenuButton and it's OnClick event

Called when user will select CurrentItem, either with mouse or with keyboard.

Public procedure CurrentItemSelected; virtual; deprecated 'use TCastleMenuButton and it''s OnClick event';

Warning: this symbol is deprecated: use TCastleMenuButton and it's OnClick event

Deprecated name for Click.

Public procedure CurrentItemChanged; virtual;

Called when CurrentItem changed. But *not* when CurrentItem changed because of ControlsCount changes. If you want to only get notified when the CurrentItem changed because of user actions, better override CurrentItemChangedByUser.

Public procedure CurrentItemChangedByUser; virtual;

Called when CurrentItem changed by a user action (keyboard press, mouse move or click or something like that).

Public function SpaceBetweenItems(const NextItemIndex: Cardinal): Single; virtual; deprecated 'ignored now; if you want to add extra space, add TCastleUserInterface with explicit Height to MenuItems';

Warning: this symbol is deprecated: ignored now; if you want to add extra space, add TCastleUserInterface with explicit Height to MenuItems

Return the space needed before NextItemIndex. This will be a space between NextItemIndex - 1 and NextItemIndex (this method will not be called for NextItemIndex = 0).

Default implementation in this class simply returns RegularSpaceBetweenItems always.

Note that this is used only at RecalculateSize call. So when some variable affecting the implementation of this changes, you should call RecalculateSize again.

Properties

Public property CurrentItem: Integer read GetCurrentItem write SetCurrentItem;

Currently selected child index. This is always some number between 0 and MenuItems.ControlsCount - 1. It can also be -1 to indicate "no child is selected". When MenuItems is empty (MenuItems.ControlsCount = 0) it is always -1.

You can change it by code. Assigning here an invalid value (e.g. larger then MenuItems.ControlsCount - 1) will be automatically fixed. Also when the children change (and so ControlsCount changes), this is automatically fixed if necessary.

Changing this calls CurrentItemChanged automatically, but not CurrentItemChangedByUser.

Public property KeyNextItem: TKey read FKeyNextItem write FKeyNextItem default DefaultMenuKeyNextItem;
 
Public property KeyPreviousItem: TKey read FKeyPreviousItem write FKeyPreviousItem default DefaultMenuKeyPreviousItem;
 
Public property KeySelectItem: TKey read FKeySelectItem write FKeySelectItem default DefaultMenuKeySelectItem;
 
Public property CurrentItemBorderColor1: TCastleColor read FCurrentItemBorderColor1 write FCurrentItemBorderColor1;

1st color of the border to display around focused child. Default value is DefaultCurrentItemBorderColor1

Public property CurrentItemBorderColor2: TCastleColor read FCurrentItemBorderColor2 write FCurrentItemBorderColor2;

2nd color of the border to display around focused child. Default value is DefaultCurrentItemBorderColor2

Public property CurrentItemColor: TCastleColor read FCurrentItemColor write FCurrentItemColor;

Label color for the focused child. Default value is DefaultCurrentItemColor

Public property NonCurrentItemColor: TCastleColor read FNonCurrentItemColor write FNonCurrentItemColor;

Label color for the non-focused but focusable child. Default value is DefaultNonCurrentItemColor

Public property NonFocusableItemColor: TCastleColor read FNonFocusableItemColor write FNonFocusableItemColor;

Label color for the non-focusable child. Default value is DefaultNonFocusableItemColor

Public property OnClick: TNotifyEvent read FOnClick write FOnClick; deprecated 'use Add method to add a particular menu item with it''s own click callback; or just add TCastleMenuButton and handle it''s OnClick event';

Warning: this symbol is deprecated: use Add method to add a particular menu item with it's own click callback; or just add TCastleMenuButton and handle it's OnClick event

Called when user will select CurrentItem.

See also
Click
Called when user will select CurrentItem, either with mouse or with keyboard.
Published property AutoSizeToChildren default true;
 
Published property MenuItems: TCastleVerticalGroup read FMenuItems;

Menu items, and things between menu items, should be added here.

Published property BackgroundOpacityFocused: Single read FBackgroundOpacityFocused write FBackgroundOpacityFocused default DefaultBackgroundOpacityFocused;

Opacity of the background rectangle (displayed when DrawBackgroundRectangle).

Published property BackgroundOpacityNotFocused: Single read FBackgroundOpacityNotFocused write FBackgroundOpacityNotFocused default DefaultBackgroundOpacityNotFocused;
 
Published property DrawBackgroundRectangle: boolean read FDrawBackgroundRectangle write FDrawBackgroundRectangle default true;
 
Published property RegularSpaceBetweenItems: Single read FRegularSpaceBetweenItems write SetRegularSpaceBetweenItems default DefaultRegularSpaceBetweenItems;

Additional vertical space, in pixels, between menu items.

If you want more control over it (if you want to add more/less space between some menu items), override SpaceBetweenItems method.

Published property DrawFocusedBorder: boolean read FDrawFocusedBorder write FDrawFocusedBorder default true;

Draw a flashing border around the menu when we are focused.

Published property CaptureAllEvents: boolean read FCaptureAllEvents write FCaptureAllEvents default false;

Should menu intercept all key/mouse input, regardless if mouse position is over our rectangle. This affects key/mouse processing (menu processes input before all controls underneath), but not drawing (controls underneath are still visible as usual).

Published property CurrentItemBorderColor1Persistent: TCastleColorPersistent read FCurrentItemBorderColor1Persistent ;

CurrentItemBorderColor1 that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write CurrentItemBorderColor1 directly.

See also
CurrentItemBorderColor1
1st color of the border to display around focused child.
Published property CurrentItemBorderColor2Persistent: TCastleColorPersistent read FCurrentItemBorderColor2Persistent ;

CurrentItemBorderColor2 that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write CurrentItemBorderColor2 directly.

See also
CurrentItemBorderColor2
2nd color of the border to display around focused child.
Published property CurrentItemColorPersistent: TCastleColorPersistent read FCurrentItemColorPersistent ;

CurrentItemColor that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write CurrentItemColor directly.

See also
CurrentItemColor
Label color for the focused child.
Published property NonCurrentItemColorPersistent: TCastleColorPersistent read FNonCurrentItemColorPersistent ;

NonCurrentItemColor that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write NonCurrentItemColor directly.

See also
NonCurrentItemColor
Label color for the non-focused but focusable child.
Published property NonFocusableItemColorPersistent: TCastleColorPersistent read FNonFocusableItemColorPersistent ;

NonFocusableItemColor that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write NonFocusableItemColor directly.

See also
NonFocusableItemColor
Label color for the non-focusable child.

Generated by PasDoc 0.15.0.