Class TViewDialog

Unit

Declaration

type TViewDialog = class abstract(TCastleView)

Description

Abstract class for a modal dialog user-interface view. See unit CastleDialogViews documentation for example usage.

Hierarchy

Overview

Nested Types

Protected TButtonArray = array of TCastleButton;

Fields

Public nested const DefaultAlignment = hpLeft;

Methods

Protected procedure InitializeButtons(var Buttons: TButtonArray); virtual;
Protected function DrawInputText: boolean; virtual;
Protected procedure DoAnswered;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Start; override;
Public procedure Stop; override;
Public procedure SaveScreenIfNecessary(const AContainer: TCastleContainer);

Properties

Protected property InputText: String read GetInputText write SetInputText;
Public property InterceptInput default true;
Public property Answered: boolean read FAnswered;
Public property Text: TStrings read FText;
Public property Caption: String read GetCaption write SetCaption stored false;
Public property Alignment: THorizontalPosition read FAlignment write FAlignment default DefaultAlignment;
Public property Html: boolean read FHtml write FHtml default false;
Public property Background: boolean read FBackground write FBackground default false;
Public property BackgroundColor: TCastleColor read FBackgroundColor write FBackgroundColor;
Public property BackgroundScreenshot: boolean read FBackgroundScreenshot write FBackgroundScreenshot default false;
Public property PopOnAnswered: boolean read FPopOnAnswered write FPopOnAnswered default true;
Published property BackgroundColorPersistent: TCastleColorPersistent read FBackgroundColorPersistent ;

Description

Nested Types

Protected TButtonArray = array of TCastleButton;

This item has no description.

Fields

Public nested const DefaultAlignment = hpLeft;

This item has no description.

Methods

Protected procedure InitializeButtons(var Buttons: TButtonArray); virtual;

This item has no description.

Protected function DrawInputText: boolean; virtual;

This item has no description.

Protected procedure DoAnswered;

This item has no description.

Public constructor Create(AOwner: TComponent); override;

This item has no description. Showing description inherited from TCastleView.Create.

Create an instance of the view. You willl typically create one instance of each view class (like TViewMain, TViewPlay) at the application initialization (e.g. in Application.OnInitialize callback), like

ViewMainMenu := TViewMainMenu.Create(Application);
ViewPlay := TViewPlay.Create(Application);

Later you switch between views using TCastleContainer.View or TCastleContainer.PushView or TCastleContainer.PopView, like this:

Container.View := ViewMain;

See https://castle-engine.io/views and numerous engine examples.

Public destructor Destroy; override;

This item has no description.

Public procedure Start; override;

This item has no description. Showing description inherited from TCastleView.Start.

Executed when view becomes active, it's now part of the view stack.

Started view is part of the ViewStack, and will soon become running (top-most on the stack). When the view is set to be current, by Container.View := MyView, this happens:

  1. MyView is pushed as the top-most view on view stack.

  2. MyView.Start is called.

  3. MyView is added to the TCastleContainer.Controls list (using the container where you set TCastleContainer.PushView, TCastleContainer.View). This also means that the view methods GLContextOpen and Resize are called (as for all normal TCastleUserInterface instances).

  4. MyStar.Resume is called.

Public procedure Stop; override;

This item has no description. Showing description inherited from TCastleView.Stop.

Executed when view is no longer active, no longer part of view stack.

When the view stops becoming active, this happens:

  1. MyView.Pause is called.

  2. MyView is removed from the TCastleContainer.Controls list (using the container to which we were added). So the view method GLContextClose is called (as for all normal TCastleUserInterface instances).

  3. MyView.Stop is called.

  4. MyView is removed from the on view stack.

This is always called to finalize the started view. When the view is destroyed, it's Pause and Stop are called too, so you can use this method to reliably finalize whatever you initialized in Start.

Public procedure SaveScreenIfNecessary(const AContainer: TCastleContainer);

Save screen now to be used by subsequent Start. Does a screenshot only if our current properties (Background, BackgroundScreenshot, BackgroundColor) indicate screenshot is needed. It allows to make a screenshot earlier than at Start call.

Properties

Protected property InputText: String read GetInputText write SetInputText;

This item has no description.

Public property InterceptInput default true;

This item has no description. Showing description inherited from TCastleView.InterceptInput.

Prevents passing mouse/keyboard events to the UI views underneath.

More precisely, when this property is True, then the Press, Release and Motion events are marked as "handled" in this UI view. This means that they will not be processed further, by UI controls under this view, in particular by UI views that are underneath this view in view stack (created by Push method). They will also not be passed to final container (TCastleWindow, TCastleControl) callbacks like TCastleWindow.OnPress (as these callbacks are always used at the end, when nothing else handled the event).

Note that setting this to True means that calling inherited from your Press overridden implementation will always return True, as if the ancestor handled all the items. For this reason, in such case you should not immediately Exit when inherited is True. You should just ignore the ancestor result, like this:

function TMyView.Press(const Event: TInputPressRelease): Boolean;
begin
  Result := inherited;
  // ignore the ancestor result, as we use InterceptInput, so ancestor always returns true
  // if Result the Exit;

  if Event.IsMouseButton(buttonLeft) then
  begin
    ...
    Exit(true);
  end;
end;

Public property Answered: boolean read FAnswered;

When user answers the dialog, this is set to True. The view also normally does TCastleContainer.PopView, so there's no need to check this property, unless you set PopOnAnswered to False.

Public property Text: TStrings read FText;

Caption displayed in the dialog.

Public property Caption: String read GetCaption write SetCaption stored false;

Caption displayed in the dialog, as a simple string. This is just a shortcut to get/set Text as a single string.

Use LineEnding or NL constant when setting this to indicate a newline. The two examples below are equivalent:

// one way
ViewDialogOK.Text.Clear;
ViewDialogOK.Text.Add('First line');
ViewDialogOK.Text.Add('Second line');

// alternative way to do the same
ViewDialogOK.Caption := 'First line' + LineEnding + 'Second line';

Public property Alignment: THorizontalPosition read FAlignment write FAlignment default DefaultAlignment;

Horizontal alignment of the text.

Public property Html: boolean read FHtml write FHtml default false;

Enable a subset of HTML to mark font changes inside the text. See the TCastleAbstractFont.PrintStrings for a description of supported HTML constructs.

Public property Background: boolean read FBackground write FBackground default false;

Obscure the view underneath with our own background (using a color or screenshot).

The obscuring background is defined by BackgroundColor. It may be just a solid opaque color. Or it may be a partially-transparent or even completely transparent color, showing the view underneath (or showing the screenshot of the view underneath, if BackgroundScreenshot).

Public property BackgroundColor: TCastleColor read FBackgroundColor write FBackgroundColor;

Color of the background obscuring the view underneath, if Background is True. This color may be partially-transparent (e.g. to visually "dim" the view underneath) or even completely transparent (alpha 0).

Default is Theme.BackgroundColor, which is dark with alpha = 0.5, so it will dim the view underneath. Sometimes (under exception handler) it's Theme.BackgroundOpaqueColor.

Public property BackgroundScreenshot: boolean read FBackgroundScreenshot write FBackgroundScreenshot default false;

Initialize the background by taking a screenshot of the current screen when the view was started. This screenshot is shown, instead of actually rendering the view underneath, under the BackgroundColor, when Background is True.

This is less functional (when the user scales the window, the screenshot is stretched too), but is safer: it means that the view underneath does not need to be "renderable" anymore.

Public property PopOnAnswered: boolean read FPopOnAnswered write FPopOnAnswered default true;

Should the view do TCastleContainer.PopView when answered. This is usually most natural.

Published property BackgroundColorPersistent: TCastleColorPersistent read FBackgroundColorPersistent ;

BackgroundColor 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 BackgroundColor directly.

See also
BackgroundColor
Color of the background obscuring the view underneath, if Background is True.

Generated by PasDoc 0.16.0-snapshot.