Castle Game Engine: CastleWindowModes: Class TGLMode

# Class TGLMode
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleWindowModes ## Declaration `type TGLMode = class(TObject)` ## Description Enter / exit modal state on a TCastleWindowCustom. Saves/restores the state of TCastleWindowCustom. ## Hierarchy TObject TGLMode ## Overview ### Methods
| `constructor Create(AWindow: TCastleWindowCustom);`
| `constructor CreateReset(AWindow: TCastleWindowCustom; NewRender, NewResize, NewCloseQuery: TContainerEvent);`
| `destructor Destroy; override;`
### Properties
| `property FakeMouseDown: boolean read FFakeMouseDown write FFakeMouseDown default false;`
## Description ### Methods
| `constructor Create(AWindow: TCastleWindowCustom);`
Constructor saves open TCastleWindowCustom and OpenGL state. Destructor will restore them. Some gory details (that you will usually not care about... the point is: everything works sensibly of the box) : We save/restore window state. OpenGL context connected to this window is also made current during constructor and destructor. Also, TCastleWindowCustom.Invalidate is called (since new callbacks, as well as original callbacks, probably want to redraw window contents.) All pressed keys and mouse butons are saved and faked to be released, by calling TCastleWindowCustom.EventRelease with original callbacks. This way, if user releases some keys/mouse inside modal box, your original TCastleWindowCustom callbacks will not miss this fact. This way e.g. user scripts in VRML/X3D worlds that observe keys work fine. If FakeMouseDown then at destruction (after restoring original callbacks) we will also notify your original callbacks that user pressed these buttons (by sending TCastleWindowCustom.EventMouseDown). Note that FakeMouseDown feature turned out to be usually more troublesome than usefull — too often some unwanted MouseDown event was caused by this mechanism. That's because if original callbacks do something in MouseDown (like e.g. activate some click) then you don't want to generate fake MouseDown by TGLMode.Destroy. So the default value of FakeMouseDown is `False`. But this means that original callbacks have to be careful and never assume that when some button is pressed (because it's included in MousePressed, or has EventRelease generated for it) then for sure there occurred some MouseDown for it. At destructor, we notify original callbacks about size changes by sending TCastleWindowCustom.EventResize. This way your original callbacks know about size changes, and can set OpenGL projection etc. We call ZeroNextSecondsPassed at the end, when closing our mode, see TFramesPerSecond.ZeroNextSecondsPassed for comments why this is needed. This also performs important optimization to avoid closing / reinitializing window TCastleWindowCustom.Controls OpenGL resources, see TUIControl.DisableContextOpenClose.
| `constructor CreateReset(AWindow: TCastleWindowCustom; NewRender, NewResize, NewCloseQuery: TContainerEvent);`
Save TCastleWindowCustom state, and then change it to a standard state. Destructor will restore saved state. For most properties, we simply reset them to some sensible default values. For some important properties, we take their value explicitly by parameter. Window properties resetted: All callbacks (OnXxx) are set to `Nil`. Except the open/close callbacks (OnOpen and OnClose, OnOpenObject and OnCloseObject). Actually, OnOpenObject and OnCloseObject are changed for internal purposes, but, assuming you use SetStandardState, the orignal ones will still happen. Global CastleUIControls.OnGLContextOpen, CastleUIControls.OnGLContextClose are also untouched. On standalone, we can expect that the window (and OpenGL context) will stay open during the lifetime of a single TGLMode. So it doesn't really matter what we do with callbacks OnOpen / OnClose. On mobiles (Android) this is not necessarily true. Window may get closed at any time. So be extra careful when implementing OnOpen / OnClose callbacks, remember that they may happen when we're inside a mode (for example inside a modal message in CastleMessages or a progress bar). TCastleWindowCustom.Caption and TCastleWindowCustom.MainMenu are left as they were. TCastleWindowCustom.Cursor is reset to mcDefault. TCastleWindowCustom.UserData is reset to `Nil`. TCastleWindowCustom.AutoRedisplay is reset to `False`. TCastleWindowCustom.RenderStyle is reset to rs2D. TCastleWindowCustom.MainMenu.Enabled will be reset to `False` (only if MainMenu <> nil). TCastleWindowDemo.SwapFullScreen_Key will be reset to K_None. TCastleWindowDemo.Close_charkey will be reset to #0. TCastleWindowDemo.FpsShowOnCaption will be reset to false. Existing TCastleWindowCustom.Controls are set to non-existing. That is, their TUIControl.Exists is adjusted. If you're looking for a suitable callback to pass as NewCloseQuery (new TCastleWindowCustom.OnCloseQuery), @NoClose may be suitable: it's an empty callback, thus using it disables the possibility to close the window by window manager (usually using "close" button in some window corner or Alt+F4).
| `destructor Destroy; override;`
### Properties
| `property FakeMouseDown: boolean read FFakeMouseDown write FFakeMouseDown default false;`
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:13