On-screen menu displayed in OpenGL. All the menu items are simply displayed on the screen, one after the other. Typical for game menus. Normal user programs may prefer to use the menu bar instead of this (for example TCastleWindowCustom.Menu, or normal Lazarus menu). Although this still may be useful for displaying things like sliders.
You may be interested in DesignerMode for a possibility to set this property at run-time.
Expressed as a public field (instead of a read-write property) because assigning a field of record property is a risk in ObjectPascal (you may be modifying only a temporary copy of the record returned by property getter).
The accessory (like a slider) attached to currently selected menu item. Nil if none.
procedure NextItem;
These change CurrentItem as appropriate. Usually you will just let this class call it internally (from Motion, KeyDown etc.) and will not need to call it yourself.
procedure PreviousItem;
procedure GLContextClose; override;
procedure FixItemsRectangles;
Calculate final positions, sizes of menu items on the screen. You must call FixItemsRectangles between last modification of
You can call this only while OpenGL context is initialized.
ContainerResize already calls FixItemsRectangles, and window resize is already called automatically by window (at the addition to Controls list, or whenever window size changes). So in simplest cases (when you fill Items etc. properties before adding TCastleOnScreenMenu to Controls) you, in practice, do not have to call this explicitly.
Called when the value of current accessory (TMenuAccessory assigned to CurrentItem) changed its value. (Which may happen due to user clicking, or pressing some keys etc.)
Note that this will not be called when you just set Value of some property.
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).
Note that this is used only at FixItemsRectangles call. So when some variable affecting the implementation of this changes, you should call FixItemsRectangles again.
PositionAbsolute expresses the position of the menu rectangle independently from all PositionRelative* properties. You can think of it as "What value would Position have if all PositionRelative* were equal prLow".
An easy exercise for the reader is to check implementation that when all PositionRelative* are prLow, PositionAbsolute is indeed always equal to Position :)
This is read-only, is calculated by FixItemsRectangles. It's calculated anyway because our drawing code needs this. You may find it useful if you want to draw something relative to menu position.
Calculates menu items positions, sizes. These are initialized by FixItemsRectangles. They are absolutely read-only for the user of this class. You can use them to do some graphic effects, when you e.g. want to draw something on the screen that is somehow positioned relative to some menu item or to whole menu rectangle. Note that AllItemsRectangle includes also some outside margin.
"Designer mode" is useful for a developer to visually design some properties of TCastleOnScreenMenu.
Container of this control will be aumatically used, we will set mouse position when entering DesignerMode to match current menu position. This is usually desirable (otherwise slight mouse move will immediately change menu position). To make it work, make sure Container is assigned before setting DesignerMode to True — in other words, make sure you add this control to something like TCastleWindowCustom.Controls first, and only then set DesignedMode := True. This works assuming that you always call our Render with identity transform matrix (otherwise, this unit is not able to know how to calculate mouse position corresponding to given menu PositionAbsolute).
By default, we're not in designer mode, and user has no way to enter into designer mode. You have to actually add some code to your program to activate designer mode. E.g. in "The Rift" game I required that user passes --debug-menu-designer command-line option and then DesignerMode could be toggled by F12 key press.
Right now, features of designer mode:
Mouse move change Position to current mouse position.
Also, a white line is drawn in designer mode, to indicate the referenced screen and menu positions. A line connects the appropriate container position (from PositionRelativeScreen) to the appropriate control position (from PositionRelativeMenu).
Key CtrlD dumps current properties to StdOut. Basically, every property that can be changed from designer mode is dumped here. This is crucial function if you decide that you want to actually use the designed properties in your program, so you want to paste code setting such properties.
property BackgroundOpacityFocused: Single
read FBackgroundOpacityFocused
write FBackgroundOpacityFocused
default DefaultBackgroundOpacityFocused;
Note that Objects of this class have special meaning: they must be either nil or some TMenuAccessory instance (different TMenuAccessory instance for each item). When freeing this TCastleOnScreenMenu instance, note that we will also free all Items.Objects.
Should menu intercept all key/mouse input, that is behave like it was filling full container (window or lazarus component). This affects key/mouse processing (menu processes input before all controls underneath), but not drawing (controls underneath are still visible as usual).