Castle Game Engine: CastleMessages

# Unit CastleMessages
Description | Uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables
## Description Dialog windows (asking user for confirmation, question, simple text input and such) displayed within an OpenGL context (TCastleWindow or TCastleControl). Features: All the MessageXxx routines display a modal dialog. They return only when the user accepted / answered the dialog box. This way they are comfortable to use anywhere in your program. MessageInputXxx family of functions ask user to enter some text. All the dialog boxes have vertical scroll bar, displayed when needed. So it's OK to use really long text. Scroll bar can be operated with keys (up/down, ctrl+up/down, page up/down, home/end) and mouse (drag the scroll bar, or click below/above it). Long text lines are automatically broken. So it's OK to use text with long lines. We will try to break text only at whitespace. If you pass a text as a single string parameter, then our "line breaking" works correctly even for text that already contains newline characters (they are correctly recognized as forcing line break). If you pass a text as an "array of string" or TStringList, it's expected that strings inside don't contain newline characters anymore. It's undefined what will happen (i.e. whether they will be correctly broken) otherwise. Of course, TStringList contents used to pass text to MessageXxx will never be modified in any way. User is allowed to resize the window while MessageXxx works. (As long as TCastleWindowCustom.ResizeAllowed = raAllowed, of course.) Long lines are automatically broken taking into account current window width. You can configure dialog boxes look using TCastleTheme. Various parts of the dialog use scaled images. This way you can change the border, background of the dialog, you can also make the dialog box partially transparent. Call MessageXxx functions only when Window.Closed = false. Note that MessageXxx will do Window.MakeCurrent (probably more than once). Calling MessageXxx requires one free place on OpenGL attrib stack. Notes about implementation: We temporary replace normal window callbacks and controls using TGLMode. This allows you to call MessageXxx procedures in any place of your program, and things will just work, the MessageXxx will return only once user answers the dialog box. Be careful if you use TCastleApplication.OnUpdate or TCastleApplication.OnTimer. As these events are not tied to a particular window, they continue to work even while we're inside MessageXxx procedure. Be sure to implement them such that they make sense also when we're inside a dialog box. In particular, remember that you cannot close the Window when the message box in running. So do not blindly call TCastleWindowCustom.Close from TCastleApplication callbacks. Since your normal callbacks and controls are not run when message box is running, you usually don't need to do anything special about it, unless you use TCastleApplication callbacks mentioned above. ## Uses Classes CastleWindow CastleGLUtils CastleUtils CastleStringUtils CastleVectors CastleKeysMouse CastleControls CastleRectangles ## Overview ### Functions and Procedures
`procedure MessageOK(Window: TCastleWindowCustom; const s: string; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`procedure MessageOK(Window: TCastleWindowCustom; const SArray: array of string; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`procedure MessageOK(Window: TCastleWindowCustom; TextList: TStringList; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`function MessageInput(Window: TCastleWindowCustom; const s: string; const answerDefault: string = ''; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): string; overload;`
`function MessageInput(Window: TCastleWindowCustom; TextList: TStringList; const answerDefault: string = ''; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): string; overload;`
`function MessageInputQuery(Window: TCastleWindowCustom; const s: string; var answer: string; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageInputQuery(Window: TCastleWindowCustom; TextList: TStringList; var answer: string; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageChoice(Window: TCastleWindowCustom; const s: string; const Buttons: array of string; const ButtonsChars: array of char; const TextAlign: THorizontalPosition = DefaultAlign): char; overload;`
`function MessageChoice(Window: TCastleWindowCustom; const SArray: array of string; const Buttons: array of string; const ButtonsChars: array of char; const TextAlign: THorizontalPosition = DefaultAlign): char; overload;`
`function MessageChoice(Window: TCastleWindowCustom; TextList: TStringList; const Buttons: array of string; const ButtonsChars: array of char; const TextAlign: THorizontalPosition = DefaultAlign): char; overload;`
`function MessageKey(Window: TCastleWindowCustom; const S: string; const TextAlign: THorizontalPosition = DefaultAlign): TKey; overload;`
`function MessageKey(Window: TCastleWindowCustom; const SArray: array of string; const TextAlign: THorizontalPosition = DefaultAlign): TKey; overload;`
`function MessageKey(Window: TCastleWindowCustom; TextList: TStringList; const TextAlign: THorizontalPosition = DefaultAlign): TKey; overload;`
`procedure MessageKeyMouse(Window: TCastleWindowCustom; const S: string; out Event: TInputPressRelease; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`procedure MessageKeyMouse(Window: TCastleWindowCustom; TextList: TStringList; out Event: TInputPressRelease; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`function MessageYesNo(Window: TCastleWindowCustom; const s: string; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageYesNo(Window: TCastleWindowCustom; const SArray: array of string; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageYesNo(Window: TCastleWindowCustom; TextList: TStringList; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageInputCardinal(Window: TCastleWindowCustom; const s: string; const AnswerDefault: string; const TextAlign: THorizontalPosition = DefaultAlign): Cardinal; overload;`
`function MessageInputCardinal(Window: TCastleWindowCustom; const s: string; const AnswerDefault: Cardinal; const TextAlign: THorizontalPosition = DefaultAlign): Cardinal; overload;`
`function MessageInputQueryCardinal(Window: TCastleWindowCustom; const Title: string; var Value: Cardinal; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQueryCardinalHex(Window: TCastleWindowCustom; const Title: string; var Value: Cardinal; const MaxWidth: Cardinal; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQuery(Window: TCastleWindowCustom; const Title: string; var Value: Extended; const ValueAsString: string = ''; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQuery(Window: TCastleWindowCustom; const Title: string; var Value: Single; const ValueAsString: string = ''; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQueryVector3Single( Window: TCastleWindowCustom; const Title: string; var Value: TVector3Single; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQueryVector4Single( Window: TCastleWindowCustom; const Title: string; var Value: TVector4Single; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
### Types
`TTextAlign = THorizontalPosition deprecated;`
### Constants
`DefaultAlign = hpLeft;`
`taRight = hpRight deprecated;`
`taMiddle = hpMiddle deprecated;`
`taLeft = hpLeft deprecated;`
## Description ### Functions and Procedures
`procedure MessageOK(Window: TCastleWindowCustom; const s: string; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
Ask user for simple confirmation. This is the simplest "OK" dialog box.
`procedure MessageOK(Window: TCastleWindowCustom; const SArray: array of string; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`procedure MessageOK(Window: TCastleWindowCustom; TextList: TStringList; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`function MessageInput(Window: TCastleWindowCustom; const s: string; const answerDefault: string = ''; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): string; overload;`
Ask user to input a string. User must give an answer (there is no "Cancel" button), use MessageInputQuery if you want a version with "Cancel" button. ###### Parameters AnswerMaxLen 0 (zero) means that there's no maximum answer length.
`function MessageInput(Window: TCastleWindowCustom; TextList: TStringList; const answerDefault: string = ''; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): string; overload;`
`function MessageInputQuery(Window: TCastleWindowCustom; const s: string; var answer: string; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
Ask user to input a string, or cancel. Returns `True` and sets Answer if user accepted some text. Note that initial Answer value is the answer proposed to the user. ###### Parameters AnswerMaxLen 0 (zero) means that there's no maximum answer length.
`function MessageInputQuery(Window: TCastleWindowCustom; TextList: TStringList; var answer: string; const answerMinLen: integer = 0; const answerMaxLen: integer = 0; const answerAllowedChars: TSetOfChars = AllChars; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageChoice(Window: TCastleWindowCustom; const s: string; const Buttons: array of string; const ButtonsChars: array of char; const TextAlign: THorizontalPosition = DefaultAlign): char; overload;`
Ask user to choose one option from many. Buttons contain a list of button captions. ButtonsChars (must have always the same length as Buttons) contains the chars that are returned for each corresponding button press. The user can also directly press the given key. ButtonsChars is not case sensitive, all letters on this list must be different (not only in case). We always return a lowercase letter corresponding to one of ButtonsChars letters. Example usage:
    case MessageChoice(Window, 'Which fruit to you want to eat?',
      ['Apple', 'Banana', 'Cancel'],
      ['a', 'b', CharEscape]) of
      'a': // ... user pressed "Apple" button or "A" key -> likes apples
      'b': // ... user pressed "Banana" button or "B" key -> likes bananas
      CharEscape: // ... user pressed "Cancel" button or "Escape" key -> cancelled
    end;
`function MessageChoice(Window: TCastleWindowCustom; const SArray: array of string; const Buttons: array of string; const ButtonsChars: array of char; const TextAlign: THorizontalPosition = DefaultAlign): char; overload;`
`function MessageChoice(Window: TCastleWindowCustom; TextList: TStringList; const Buttons: array of string; const ButtonsChars: array of char; const TextAlign: THorizontalPosition = DefaultAlign): char; overload;`
`function MessageKey(Window: TCastleWindowCustom; const S: string; const TextAlign: THorizontalPosition = DefaultAlign): TKey; overload;`
Ask user to press any key, return this key as Keys.TKey. Never returns K_None (which means that keys that cannot be interpreted as Keys.TKey will be ignored, and will not close the dialog box).
`function MessageKey(Window: TCastleWindowCustom; const SArray: array of string; const TextAlign: THorizontalPosition = DefaultAlign): TKey; overload;`
`function MessageKey(Window: TCastleWindowCustom; TextList: TStringList; const TextAlign: THorizontalPosition = DefaultAlign): TKey; overload;`
`procedure MessageKeyMouse(Window: TCastleWindowCustom; const S: string; out Event: TInputPressRelease; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
Ask user to press any key or mouse button or mouse wheel, and return it. The natural use for this is to allow user to configure keybindings of your program, like for TInputShortcut.
`procedure MessageKeyMouse(Window: TCastleWindowCustom; TextList: TStringList; out Event: TInputPressRelease; const TextAlign: THorizontalPosition = DefaultAlign); overload;`
`function MessageYesNo(Window: TCastleWindowCustom; const s: string; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageYesNo(Window: TCastleWindowCustom; const SArray: array of string; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageYesNo(Window: TCastleWindowCustom; TextList: TStringList; const TextAlign: THorizontalPosition = DefaultAlign): boolean; overload;`
`function MessageInputCardinal(Window: TCastleWindowCustom; const s: string; const AnswerDefault: string; const TextAlign: THorizontalPosition = DefaultAlign): Cardinal; overload;`
Ask user to input an unsigned integer. Note that AnswerDefault below may be given as Cardinal or as a string. The latter is useful if you want the default answer to be '', i.e. empty string — no default answer.
`function MessageInputCardinal(Window: TCastleWindowCustom; const s: string; const AnswerDefault: Cardinal; const TextAlign: THorizontalPosition = DefaultAlign): Cardinal; overload;`
`function MessageInputQueryCardinal(Window: TCastleWindowCustom; const Title: string; var Value: Cardinal; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQueryCardinalHex(Window: TCastleWindowCustom; const Title: string; var Value: Cardinal; const MaxWidth: Cardinal; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
Ask user to input a value in hexadecimal. Give MaxWidth = 0 to say that there is no maximum width.
`function MessageInputQuery(Window: TCastleWindowCustom; const Title: string; var Value: Extended; const ValueAsString: string = ''; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
Ask user to input a floating-point number. If you give non-empty ValueAsString, it will be used to show the initial value for the user. Otherwise, we will just show FloatToStr(Value), which sometimes may be too ugly. For example Value = 0.01 cannot be precisely represented as a floating point number, and FloatToStr shows that this is really something like 0.0099xxxxx.
`function MessageInputQuery(Window: TCastleWindowCustom; const Title: string; var Value: Single; const ValueAsString: string = ''; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQueryVector3Single( Window: TCastleWindowCustom; const Title: string; var Value: TVector3Single; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
`function MessageInputQueryVector4Single( Window: TCastleWindowCustom; const Title: string; var Value: TVector4Single; const TextAlign: THorizontalPosition = DefaultAlign): boolean;`
### Types
`TTextAlign = THorizontalPosition deprecated;`
Warning: this symbol is deprecated. Position of text in message dialogs. Deprecated, use THorizontalPosition instead.
### Constants
`DefaultAlign = hpLeft;`
`taRight = hpRight deprecated;`
Warning: this symbol is deprecated.
`taMiddle = hpMiddle deprecated;`
Warning: this symbol is deprecated.
`taLeft = hpLeft deprecated;`
Warning: this symbol is deprecated.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:10