Class TCastleOnScreenMenu

Unit

Declaration

type TCastleOnScreenMenu = class(TUIControlFont)

Description

On-screen menu, with all menu items displayed on the screen, one under the other. Typical for game menus. Normal tools may prefer to use the menu bar instead of this (for example TCastleWindowCustom.Menu, or normal Lazarus menu).

Each menu item can have an "accessory", for example an associated slider (from TCastleFloatSlider, any TUIControl is OK). This allows to use this menu also for settings.

Hierarchy

Overview

Fields

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

Methods

Protected procedure UIScaleChanged; override;
Protected function ControlFocusable(const C: TUIControl): boolean; virtual;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Add(const S: string);
Public procedure Add(const S: string; const Accessory: TUIControl);
Public procedure Add(const S: string; const ItemOnClick: TNotifyEvent);
Public procedure Add(const NewItem: TUIControl);
Public procedure NextItem;
Public procedure PreviousItem;
Public procedure RecalculateSize;
Public procedure Resize; override;
Public function Rect: TRectangle; override;
Public function CapturesEventsAtPosition(const Position: TVector2): boolean; override;
Public procedure Render; override;
Public function Press(const Event: TInputPressRelease): boolean; override;
Public function Release(const Event: TInputPressRelease): boolean; override;
Public function Motion(const Event: TInputMotion): 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): Cardinal; virtual;

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 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: Cardinal 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;

Description

Fields

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

Methods

Protected procedure UIScaleChanged; override;
 
Protected function ControlFocusable(const C: TUIControl): boolean; virtual;

Decide whether a children control is focusable or not. This is used to decide should we show an "active frame" around this item in the menu. It does not determine whether the mouse events actually reach the child control.

By default, a single TCastleLabel (without children) is considered "not focusable". Everything else is focusable.

Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure Add(const S: string);
 
Public procedure Add(const S: string; const Accessory: TUIControl);
 
Public procedure Add(const S: string; const ItemOnClick: TNotifyEvent);
 
Public procedure Add(const NewItem: TUIControl);
 
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 procedure RecalculateSize;

Calculate final positions, sizes of menu items on the screen. Usually this is called automatically when necessary.

Public procedure Resize; override;
 
Public function Rect: TRectangle; override;
 
Public function CapturesEventsAtPosition(const Position: TVector2): boolean; override;
 
Public procedure Render; override;
 
Public function Press(const Event: TInputPressRelease): boolean; override;
 
Public function Release(const Event: TInputPressRelease): boolean; override;
 
Public function Motion(const Event: TInputMotion): 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): Cardinal; virtual;

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 ControlsCount - 1. It can also be -1 to indicate "no child is selected". When there are no controls (ControlsCount = 0) it is always -1.

You can change it by code. Assigning here an invalid value (e.g. larger then 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 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: Cardinal 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).


Generated by PasDoc 0.15.0.