Class TMenuAccessory

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TMenuAccessory = class(TObject)

Description

Attachment to a specific menu item of TCastleOnScreenMenu, for example may store a value associated with given menu option, and allow to change it by a slider.

Hierarchy

  • TObject
  • TMenuAccessory

Overview

Methods

Public constructor Create;
Public function GetWidth: Integer; virtual; abstract;
Public procedure Draw(const Rectangle: TRectangle); virtual; abstract;
Public function KeyDown(Key: TKey; C: char; ParentMenu: TCastleOnScreenMenu): boolean; virtual;
Public function MouseDown(const Event: TInputPressRelease; const Rectangle: TRectangle; ParentMenu: TCastleOnScreenMenu): boolean; virtual;
Public procedure Motion(const Event: TInputMotion; const Rectangle: TRectangle; ParentMenu: TCastleOnScreenMenu); virtual;

Properties

Public property OwnedByParent: boolean read FOwnedByParent write FOwnedByParent default true;

Description

Methods

Public constructor Create;
 
Public function GetWidth: Integer; virtual; abstract;

Return the width you will need to display yourself.

Note that this will be asked only from FixItemsRectangles from TCastleOnScreenMenu. So for example TMenuArgument is *not* supposed to return here something based on current TMenuArgument.Value, because we will not query GetWidth after every change of TMenuArgument.Value. Instead, TMenuArgument should return here the width of widest possible Value.

Public procedure Draw(const Rectangle: TRectangle); virtual; abstract;

Draw (2D) contents. Note that Rectangle.Width is for sure the same as you returned in GetWidth.

Public function KeyDown(Key: TKey; C: char; ParentMenu: TCastleOnScreenMenu): boolean; virtual;

This will be called if user will press a key when currently selected item has this TMenuAccessory.

You can use ParentMenu to call ParentMenu.AccessoryValueChanged.

Public function MouseDown(const Event: TInputPressRelease; const Rectangle: TRectangle; ParentMenu: TCastleOnScreenMenu): boolean; virtual;

Called when user clicks the mouse when currently selected item has this TMenuAccessory.

Called only if Event.MousePosition is within current Rectangle (place on screen) of this accessory. This Rectangle is also passed here, so you can e.g. calculate mouse position relative to current accessory as (Event.Position[0] - Rectangle.Left, Event.Position[1] - Rectangle.Bottom).

Note that while the user holds the mouse clicked (Event.Pressed <> []), the mouse is "grabbed" by this accessory, and even when the user will move the mouse over other items, they will not receive their MouseDown/Motion messages until user will let the mouse go. This prevents the bad situation when user does MouseDown e.g. on "Sound Volume" slider, slides it to the right and then accidentaly moves the mouse also a little down, and suddenly he's over "Music Volume" slider and he changed the position of "Music Volume" slider.

You can use ParentMenu to call ParentMenu.AccessoryValueChanged.

Public procedure Motion(const Event: TInputMotion; const Rectangle: TRectangle; ParentMenu: TCastleOnScreenMenu); virtual;

Called when user moves the mouse over the currently selected menu item and menu item has this accessory.

Just like with MouseDown: This will be called only if Event.Position is within appropriate Rectangle of accessory. You can use ParentMenu to call ParentMenu.AccessoryValueChanged.

Properties

Public property OwnedByParent: boolean read FOwnedByParent write FOwnedByParent default true;

Should this accessory be freed when TCastleOnScreenMenu using it is freed. Useful to set this to False when you want to share one TMenuAccessory across more than one TCastleOnScreenMenu.