Class TCastleNotifications
Unit
Declaration
type TCastleNotifications = class(TCastleUserInterfaceFont)
Description
Notifications displayed on the screen. Each message disappears after a short time. Suitable for game messages like "Picked up 20 ammo". Call Show to display a message.
This is a TCastleUserInterface descendant, so to use it — just add it to TCastleWindow.Controls or TCastleControl.Controls. Use TCastleUserInterface anchors to automatically position it on the screen, for example:
Notifications := TCastleNotifications.Create(Owner);
Notifications.Anchor(hpMiddle);
Notifications.Anchor(vpMiddle);
Notifications.TextAlignment := hpMiddle; // looks best, when anchor is also in the middle
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleUserInterface
- TCastleUserInterfaceFont
- TCastleNotifications
Overview
Fields
nested const DefaultMaxMessages = 4; |
|
nested const DefaultTimeout = 5.0; |
|
nested const DefaultFade = 1.0; |
Methods
procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
procedure Show(const s: string); overload; |
|
procedure Show(s: TStringList); overload; |
|
procedure Clear; |
|
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; |
|
procedure Render; override; |
|
function PropertySections(const PropertyName: String): TPropertySections; override; |
Properties
property Color: TCastleColor read FColor write FColor; |
|
property History: TCastleStringList read FHistory; |
|
property MaxMessages: integer
read FMaxMessages write FMaxMessages default DefaultMaxMessages; |
|
property Timeout: Single
read FTimeout write FTimeout default DefaultTimeout; |
|
property Fade: Single read FFade write FFade default DefaultFade; |
|
property CollectHistory: boolean read FCollectHistory write FCollectHistory
default false; |
|
property TextAlignment: THorizontalPosition
read FTextAlignment write FTextAlignment default hpLeft; |
|
property DesignTestMessagesInterval: Single
read FDesignTestMessagesInterval write FDesignTestMessagesInterval
default 1; |
|
property Wrap: Boolean read FWrap write FWrap default true; |
|
property ColorPersistent: TCastleColorPersistent read FColorPersistent ; |
Description
Fields
nested const DefaultMaxMessages = 4; |
|
This item has no description. |
nested const DefaultTimeout = 5.0; |
|
This item has no description. |
nested const DefaultFade = 1.0; |
|
This item has no description. |
Methods
procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override; |
|
This item has no description. Showing description inherited from TCastleUserInterface.PreferredSize. Controls that have a preferred size should override this. By default this contains values derived from Width, WidthFraction, Height, HeightFraction, with Border subtracted. Note that the arguments should be already scaled, i.e. multiplied by UIScale, i.e. expressed in final device pixels. Note that the returned PreferredWidth and PreferredHeight must not include the space for Border. Border size will be added later. |
constructor Create(AOwner: TComponent); override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
procedure Show(s: TStringList); overload; |
|
This item has no description. |
procedure Clear; |
|
Clear all messages. |
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; |
|
This item has no description. Showing description inherited from TCastleUserInterface.Update. Control may do here anything that must be continuously repeated. E.g. camera handles here falling down due to gravity, rotating model in Examine mode, and many more.
This method may be used, among many other things, to continuously react to the fact that user pressed some key (or mouse button). For example, if holding some key should move some 3D object, you should do something like: if HandleInput then begin if Container.Pressed[keyArrowRight] then begin Transform.Position := Transform.Position + Vector3(SecondsPassed * 10, 0, 0); HandleInput := false; end; end;
Instead of directly using a key code, consider also using TInputShortcut that makes the input key nicely configurable. See engine tutorial about handling inputs. Multiplying movement by SecondsPassed makes your operation frame-rate independent. Object will move by 10 units in a second, regardless of how many FPS your game has. The code related to HandleInput is important if you write a generally-useful control that should nicely cooperate with all other controls, even when placed on top of them or under them. The correct approach is to only look at pressed keys/mouse buttons if HandleInput is Note that to handle a single press / release (like "switch light on when pressing a key") you should rather use Press and Release methods. Use this method only for continuous handling (like "holding this key makes the light brighter and brighter"). To understand why such HandleInput approach is needed, realize that the "Update" events are called differently than simple mouse and key events like "Press" and "Release". "Press" and "Release" events return whether the event was somehow "handled", and the container passes them only to the controls under the mouse (decided by TCastleUserInterface.CapturesEventsAtPosition). And as soon as some control says it "handled" the event, other controls (even if under the mouse) will not receive the event. This approach is not suitable for Update events. Some controls need to do the Update job all the time, regardless of whether the control is under the mouse and regardless of what other controls already did. So all controls (well, all controls that exist, in case of TCastleUserInterface, see TCastleUserInterface.Exists) receive Update calls. So the "handled" status is passed through HandleInput. If a control is not under the mouse, it will receive HandleInput = |
procedure Render; override; |
|
This item has no description. Showing description inherited from TCastleUserInterface.Render. Render a control. Called only when Exists and render context is initialized. Do not call this method. It will be automatically called by the engine when needed. It will be called when UI is part of TCastleContainer.Controls list or rendered (e.g. for off-screen rendering) by TCastleContainer.RenderControl. You should only override this method. See https://castle-engine.io/manual_2d_ui_custom_drawn.php for examples what you can put here. You can depend on some OpenGL state being set before calling this method. You can depend on it being set, and you can carelessly change it. This state we set:
Beware that GLSL RenderContext.CurrentProgram has undefined value when this is called. You should always set it, before making direct OpenGL drawing calls (all the engine drawing routines do it already, this is only a concern if you make direct OpenGL / OpenGLES calls). |
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
This item has no description. Showing description inherited from TCastleComponent.PropertySections. Section where to show property in the editor. |
Properties
property Color: TCastleColor read FColor write FColor; |
|
Color used to draw subsequent messages. Default value is white. |
property History: TCastleStringList read FHistory; |
|
All the messages passed to Show, collected only if CollectHistory. May be |
property MaxMessages: integer
read FMaxMessages write FMaxMessages default DefaultMaxMessages; |
|
How many message lines should be visible on the screen, at maximum. |
property Timeout: Single
read FTimeout write FTimeout default DefaultTimeout; |
|
How long a given message should be visible on the screen, in seconds. Message stops being visible when this timeout passed, or when we need more space for new messages (see MaxMessages). Note that the Fade time is already included in this value, so a message is normally visible only for the |
property Fade: Single read FFade write FFade default DefaultFade; |
|
This item has no description. |
property CollectHistory: boolean read FCollectHistory write FCollectHistory
default false; |
|
Turn this on to have all the messages you pass to Show be collected inside History string list. History is expanded by Show, it is cleared by Clear, just like the notifications on screen. However, unlike the visible messages, it has unlimited size (messages there are not removed when MaxMessages or Timeout take action), and messages inside are not broken to honour screen width. This is useful if you want to show the player a history of messages (in case they missed the message in game). |
property TextAlignment: THorizontalPosition
read FTextAlignment write FTextAlignment default hpLeft; |
|
Alignment of the text inside. |
property Wrap: Boolean read FWrap write FWrap default true; |
|
Wrap messages to fit in parent width. This is usually nice for display, but it may cause problems when parent size depends on child (e.g. because parent uses TCastleUserInterface.AutoSizeToChildren), because then child size also depends on parent, and parent would never grow. |
property ColorPersistent: TCastleColorPersistent read FColorPersistent ; |
|
Color 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 Color directly. See also
|
Generated by PasDoc 0.16.0-snapshot.