Class TCastleWindow
Unit
Declaration
type TCastleWindow = class(TComponent)
Description
Window to render everything (3D or 2D) with Castle Game Engine.
You should use this with TUIState, following https://castle-engine.io/manual_state_events.php and the rest of CGE manual. All user interface creation and event handling should be inside some state.
Deprecated: You can also add any user-interface controls to the Controls property. User-interface controls are any TCastleUserInterface descendants, like TCastleImageControl or TCastleButton or TCastleViewport. Use events like OnPress to react to events. Use event OnUpdate to do something continuously.
By default, the window is filled with simple color from Container.BackgroundColor.
If you're looking for an analogous Lazarus component (that can be placed on a Lazarus form) see TCastleControl component. Note that you cannot use both TCastleControl and TCastleWindow
within the same application. See https://castle-engine.io/control_on_form .
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleWindow
Overview
Methods
function CreateContainer: TWindowContainer; virtual; deprecated 'instead of custom TWindowContainer descendants, use custom TUIState descendants'; |
|
procedure DoUpdate; virtual; |
|
function AllowSuspendForInput: boolean; virtual; |
|
function Rect: TRectangle; |
|
procedure SwapFullScreen; deprecated 'use "FullScreen := not FullScreen"'; |
|
function TouchesCount: Integer; |
|
function MousePressed: TCastleMouseButtons; |
|
function Controls: TInternalChildrenControls; |
|
function GLInitialized: boolean; |
|
procedure Open; overload; |
|
procedure Open(const Retry: TGLContextRetryOpenFunc); overload; |
|
procedure Close(const QuitWhenLastWindowClosed: boolean = true); |
|
procedure PostRedisplay; deprecated; |
|
procedure Invalidate; |
|
procedure MakeCurrent; |
|
procedure SaveScreen(const URL: string); overload; |
|
function SaveScreen: TRGBImage; overload; |
|
function SaveScreen(const SaveRect: TRectangle): TRGBImage; overload; |
|
function SaveScreenToGL(const SmoothScaling: boolean = false): TDrawableImage; overload; |
|
function SaveScreenToGL(const SaveRect: TRectangle; const SmoothScaling: boolean = false): TDrawableImage; overload; |
|
function SaveScreenBuffer: TColorBuffer; |
|
procedure SaveScreenDialog(ProposedURL: string); |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
function Pressed: TKeysPressed; |
|
function Fps: TFramesPerSecond; |
|
procedure OpenAndRun; overload; |
|
procedure OpenAndRun(const ACaption: string; AOnRender: TContainerEvent); overload; deprecated; |
|
procedure ParseParameters( const AllowedOptions: TWindowParseOptions = StandardParseOptions); overload; |
|
procedure ParseParameters( const AllowedOptions: TWindowParseOptions; out SpecifiedOptions: TWindowParseOptions); overload; |
|
class function ParseParametersHelp( const AllowedOptions: TWindowParseOptions; AddHeader: boolean): string; |
|
function FileDialog(const Title: string; var URL: string; OpenDialog: boolean; FileFilters: TFileFilterList = nil): boolean; overload; |
|
function FileDialog(const Title: string; var URL: string; OpenDialog: boolean; const FileFilters: string): boolean; overload; |
|
function ColorDialog(var Color: TCastleColor): Boolean; overload; |
|
function ColorDialog(var Color: TCastleColorRGB): Boolean; overload; |
|
function ColorDialog(var Color: TVector3Byte): Boolean; overload; |
|
procedure MessageOK(const S: string; const MessageType: TWindowMessageType); |
|
function MessageYesNo(const S: string; const MessageType: TWindowMessageType = mtQuestion): boolean; |
|
procedure SetDemoOptions(const ASwapFullScreen_Key: TKey; AClose_KeyString: String; const AFpsShowOnCaption: boolean); |
Properties
property BorderWidth: Cardinal
read FBorderWidth write FBorderWidth default 0; |
|
property Container: TWindowContainer read FContainer; |
|
property Width: integer read FWidth write SetWidth default WindowDefaultSize; |
|
property Height: integer read FHeight write SetHeight default WindowDefaultSize; |
|
property Dpi: Single read FDpi write FDpi default DefaultDpi; |
|
property Left: integer read FLeft write SetLeft default WindowPositionCenter; |
|
property Top : integer read FTop write SetTop default WindowPositionCenter; |
|
property FullScreen: boolean
read FFullScreenWanted write SetFullScreenWanted default false; |
|
property DoubleBuffer: boolean read FDoubleBuffer write FDoubleBuffer default true; |
|
property RedBits: Cardinal read FRedBits write FRedBits default 0; |
|
property GreenBits: Cardinal read FGreenBits write FGreenBits default 0; |
|
property BlueBits: Cardinal read FBlueBits write FBlueBits default 0; |
|
property ColorBits: Cardinal read GetColorBits write SetColorBits stored false default 0; |
|
property MousePosition: TVector2
read FMousePosition write SetMousePosition; |
|
property Touches[constIndex:Integer]: TTouch read GetTouches; |
|
property ResizeAllowed: TResizeAllowed
read FResizeAllowed write FResizeAllowed default raAllowed; |
|
property OnOpen: TContainerEvent read GetOnOpen write SetOnOpen; |
|
property OnOpenObject: TContainerObjectEvent read GetOnOpenObject write SetOnOpenObject; |
|
property MinWidth: Integer read FMinWidth write FMinWidth default 100; |
|
property MinHeight: Integer read FMinHeight write FMinHeight default 100; |
|
property MaxWidth: Integer read FMaxWidth write FMaxWidth default 4000; |
|
property MaxHeight: Integer read FMaxHeight write FMaxHeight default 4000; |
|
property DepthBits: Cardinal
read FDepthBits write FDepthBits default DefaultDepthBits; |
|
property StencilBits: Cardinal
read FStencilBits write FStencilBits default 0; |
|
property MultiSampling: Cardinal
read FMultiSampling write FMultiSampling default 1; |
|
property AntiAliasing: TAntiAliasing
read FAntiAliasing write SetAntiAliasing default DefaultAntiAliasing; |
|
property AlphaBits: Cardinal
read FAlphaBits write FAlphaBits default 0; |
|
property AccumBits: TVector4Cardinal read FAccumBits write FAccumBits; deprecated; |
|
property GtkIconName: string read FGtkIconName write FGtkIconName; |
|
property Visible: boolean read FVisible write FVisible default true; |
|
property Caption: string read GetPublicCaption write SetPublicCaption; |
|
property OnRender: TContainerEvent read GetOnRender write SetOnRender; |
|
property OnDraw: TContainerEvent read GetOnRender write SetOnRender; deprecated; |
|
property OnBeforeRender: TContainerEvent read GetOnBeforeRender write SetOnBeforeRender; |
|
property OnResize: TContainerEvent read GetOnResize write SetOnResize; |
|
property OnClose: TContainerEvent read GetOnClose write SetOnClose; |
|
property OnCloseObject: TContainerObjectEvent read GetOnCloseObject write SetOnCloseObject; |
|
property OnPress: TInputPressReleaseEvent read GetOnPress write SetOnPress; |
|
property OnRelease: TInputPressReleaseEvent read GetOnRelease write SetOnRelease; |
|
property OnCloseQuery: TContainerEvent read FOnCloseQuery write FOnCloseQuery; |
|
property OnMotion: TInputMotionEvent read GetOnMotion write SetOnMotion; |
|
property OnUpdate: TContainerEvent read GetOnUpdate write SetOnUpdate; |
|
property OnIdle: TContainerEvent read GetOnUpdate write SetOnUpdate; deprecated; |
|
property OnTimer: TContainerEvent read FOnTimer write FOnTimer; deprecated 'use TCastleTimer to perform periodic operations, or track time delay in OnUpdate'; |
|
property OnDropFiles: TDropFilesFunc read FOnDropFiles write FOnDropFiles; |
|
property AutoRedisplay: boolean read FAutoRedisplay write SetAutoRedisplay
default true; |
|
property MainMenu: TMenu read FMainMenu write SetMainMenu; |
|
property MainMenuVisible: boolean
read FMainMenuVisible write FMainMenuVisible default true; |
|
property OwnsMainMenu: boolean read FOwnsMainMenu write FOwnsMainMenu default true; |
|
property OnMenuClick: TMenuClickFunc read FOnMenuClick write FOnMenuClick; |
|
property OnMenuCommand: TMenuClickFunc read FOnMenuClick write FOnMenuClick; deprecated; |
|
property Focused: boolean read FFocused; |
|
property UserData: Pointer read FUserData write FUserData; |
|
property Closed: boolean read FClosed default true; |
|
property Cursor: TMouseCursor read FCursor write SetCursor default mcDefault; deprecated 'do not set this, engine will override this. Set TCastleUserInterface.Cursor of your UI controls to control the Cursor.'; |
|
property InternalCursor: TMouseCursor read FCursor write SetCursor default mcDefault; |
|
property NamedParameters: TCastleStringList read FNamedParameters; |
|
property FpsShowOnCaption: boolean
read FFpsShowOnCaption write FFpsShowOnCaption default false; |
|
property SwapFullScreen_Key: TKey
read FSwapFullScreen_Key write FSwapFullScreen_Key default keyNone; |
|
property Close_KeyString: String
read FClose_KeyString write FClose_KeyString; |
|
property FpsCaptionUpdateDelay: Single
read FFpsCaptionUpdateDelay write FFpsCaptionUpdateDelay
default DefaultFpsCaptionUpdateDelay; |
Description
Methods
function CreateContainer: TWindowContainer; virtual; deprecated 'instead of custom TWindowContainer descendants, use custom TUIState descendants'; |
|
Warning: this symbol is deprecated: instead of custom TWindowContainer descendants, use custom TUIState descendants Create a container class for this window. Override this to use a custom container class, e.g. to override some container methods. |
procedure DoUpdate; virtual; |
|
function AllowSuspendForInput: boolean; virtual; |
|
Is it allowed to suspend (for an indefinite amount of time) waiting for user input. Allowing this is a good thing, as it means our process doesn't eat your CPU when it simply waits, doing nothing, for user input. On the other hand, you cannot allow this if you want to do some things continuously, regardless of user input. The default implementation plays it safe, and does not allow suspending if we have OnUpdate, OnTimer or such callback defined. |
function Rect: TRectangle; |
|
Rectangle representing the inside of this container. Always (Left,Bottom) are zero, and (Width,Height) correspond to window sizes. |
function TouchesCount: Integer; |
|
Count of currently active touches (mouse or fingers pressed) on the screen. See also
|
function MousePressed: TCastleMouseButtons; |
|
Mouse buttons currently pressed. See TCastleContainer.MousePressed for details. |
function Controls: TInternalChildrenControls; |
|
List of user-interface controls currently active. See TCastleContainer.Controls for details. |
function GLInitialized: boolean; |
|
Is the OpenGL context initialized. This is equivalent to |
procedure Open; overload; |
|
Create the window with associated rendering context and show it.
Call to this method is ignored if the window is already open (if Closed = Exceptions raised
|
procedure Open(const Retry: TGLContextRetryOpenFunc); overload; |
|
Open the window with OpenGL context, allowing you to lower the OpenGL context requirements and retry. If the OpenGL context cannot be initialized, then
Note that the parameterless version of Open method actually calls this version, with a default retry callback that turns off AntiAliasing and MultiSampling, and then StencilBits (since all our engine code should be ready that multi-sampling or stencil buffers may not be available). Using your own Retry callback, with this version, allows you to decide which context parameters may be lowered to allow creating a window. Exceptions raised
|
procedure Close(const QuitWhenLastWindowClosed: boolean = true); |
|
Close window.
Note that often there's no need to call Close explicitly in your program, because in destructor of this object we call Close, to be sure that window is closed. TODO: zrobic param boolean CloseFromDestroyQuitWhenLastWindowClosed? As for now Close from destructor is called always with QuitWhenLastWindowClosed = true. Call to Close is ignored if window is already Closed. |
procedure PostRedisplay; deprecated; |
|
Warning: this symbol is deprecated. Deprecated name for Invalidate. |
procedure Invalidate; |
|
procedure MakeCurrent; |
|
Make the OpenGL context of this window current. Following OpenGL commands will apply to this context, and the RenderContext will also refer to this. When the window is opened, and right before calling any window callback, we always automatically call this, so you should not need to call this method yourself in normal circumstances. |
function SaveScreen: TRGBImage; overload; |
|
function SaveScreen(const SaveRect: TRectangle): TRGBImage; overload; |
|
function SaveScreenToGL(const SmoothScaling: boolean = false): TDrawableImage; overload; |
|
function SaveScreenToGL(const SaveRect: TRectangle; const SmoothScaling: boolean = false): TDrawableImage; overload; |
|
function SaveScreenBuffer: TColorBuffer; |
|
Color buffer where we draw, and from which it makes sense to grab pixels. Use only if you save the screen using low-level SaveScreen_NoFlush function. Usually, you should save the screen using the simpler SaveScreen method, and then the |
procedure SaveScreenDialog(ProposedURL: string); |
|
Asks and saves current screenshot. Asks user where to save the file (using FileDialog, as default URL taking ProposedURL). If user accepts calls Window.SaveScreen. In case of problems with saving, shows a dialog (doesn't raise exception). |
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
function Pressed: TKeysPressed; |
|
Keys currently pressed. |
function Fps: TFramesPerSecond; |
|
Measures application speed. |
procedure OpenAndRun; overload; |
|
Shortcut for Open (create and show the window with GL contex) and Application.Run (run the event loop). |
procedure OpenAndRun(const ACaption: string; AOnRender: TContainerEvent); overload; deprecated; |
|
Warning: this symbol is deprecated. Shortcut for setting Caption, OnRender, then calling Open (create and show the window with GL contex) and Application.Run (run the event loop). Deprecated, it is cleaner to just set Caption and OnRender as properties, and then use parameterless |
procedure ParseParameters( const AllowedOptions: TWindowParseOptions = StandardParseOptions); overload; |
|
Parse some command-line options and remove them from Parameters list. AllowedOptions specify which command-line options are handled. See [https://castle-engine.io/opengl_options.php] for documentaion what these options actually do from user's point of view.
Multiple options of the same kind are allowed, for example two options Overloaded version with SpecifiedOptions says which command-line options were found and handled. For example, if poGeometry, then you know that user requested some window size. Exceptions raised
|
procedure ParseParameters( const AllowedOptions: TWindowParseOptions; out SpecifiedOptions: TWindowParseOptions); overload; |
|
class function ParseParametersHelp( const AllowedOptions: TWindowParseOptions; AddHeader: boolean): string; |
|
Help text for options in AllowedOptions. The idea is that if you call Returned string may be multiline, but it does not contain the trailing newline (newline char after the last line). Returned help text conforms to rules in If AddHeader then it adds line saying |
function FileDialog(const Title: string; var URL: string; OpenDialog: boolean; FileFilters: TFileFilterList = nil): boolean; overload; |
|
Select a file to open or save, using native (looks familiar on a given system) dialog box. Accepts and returns argument as an URL. Passing a filename as an URL is also allowed (as everywhere), it may be changed into an URL on return. This dialog may also allow user for some typical file-management operations by the way (create some directories, rename some files etc.). Returns
As with all the model dialog methods here, like FileDialog, ColorDialog, MessageOK, MessageYesNo:
Parameters
|
function FileDialog(const Title: string; var URL: string; OpenDialog: boolean; const FileFilters: string): boolean; overload; |
|
function ColorDialog(var Color: TCastleColor): Boolean; overload; |
|
Choose a color, using native (looks familiar on a given system) dialog box. Initial value of Color specifies initial color proposed to the user. If user accepts, we return true and set Color accordingly, else we return false (and do not modify Color). Overloaded version with TCastleColor specifies a color with alpha. But note that only some backends actually allow user to adjust alpha (others leave alpha unchanged). Backends that allow alpha editing now are: Cocoa, Xlib. |
function ColorDialog(var Color: TCastleColorRGB): Boolean; overload; |
|
function ColorDialog(var Color: TVector3Byte): Boolean; overload; |
|
procedure MessageOK(const S: string; const MessageType: TWindowMessageType); |
|
Show some information and just ask to press "OK", using native (looks familiar on a given system) dialog box. |
function MessageYesNo(const S: string; const MessageType: TWindowMessageType = mtQuestion): boolean; |
|
Ask a yes/no question, using native (looks familiar on a given system) dialog box. |
procedure SetDemoOptions(const ASwapFullScreen_Key: TKey; AClose_KeyString: String; const AFpsShowOnCaption: boolean); |
|
Configure some options typically used by "demo" applications. |
Properties
property Container: TWindowContainer read FContainer; |
|
property Width: integer read FWidth write SetWidth default WindowDefaultSize; |
|
Size of the window OpenGL area. Together with frame and border sizes, and eventually menu bar size, this determines the final window size. When the window is open, these are read-only (may only change through internal methods, that is: we'll update Width, Height, Left, Top to reflect current size and position). MinWidth / MaxWidth / MinHeight / MaxHeight place constraints on these values (rigorously honored when window is open): always ResizeAllowed places constrains when window manager and user may change window size. In particular, when ResizeAllowed <> raAllowed then window sizes cannot change when window is open. Note that for some window managers, we cannot always reliably force the size constraints and block resizing on the desktop. If you set rigorous size constraints, or ResizeAllowed <> raAllowed, you may find that window manager still resizes the window. In such cases, we may fake our size a little — Width and Height values may not correspond to actual size as seen on the desktop. This is comfortable, as in such cases you usually want to just ignore window managers limits and just proceed as if your size requirements are satisfied. Special WindowDefaultSize value of these properties means: at Open, calculate and use some comfortable window size. TODO: Make it possible to set these properties while the window is open. |
property Height: integer read FHeight write SetHeight default WindowDefaultSize; |
|
property Dpi: Single read FDpi write FDpi default DefaultDpi; |
|
Dots (pixels) per inch. Describes how many pixels fit on a physical inch. So this is determined by the screen resolution in pixels, and by the physical size of the device. Some systems may expose a value that actually reflects user preference "how to scale the user-interface", where 96 (DefaultDpi) is default. So do not depend that it is actually related to the physical monitor size. See https://developer.gnome.org/gdk2/stable/GdkScreen.html#gdk-screen-set-resolution . |
property Left: integer read FLeft write SetLeft default WindowPositionCenter; |
|
Window position on the screen. If one (or both) of them is equal to WindowPositionCenter at the initialization (Open) time, then it will be set to position the window at the screen center. TODO: Make it possible to set these properties while the window is open. |
property Top : integer read FTop write SetTop default WindowPositionCenter; |
|
property FullScreen: boolean
read FFullScreenWanted write SetFullScreenWanted default false; |
|
Is the window fullscreen. A fullscreen window has Width, Height, Left, Top set to fill the whole screen. The window style is also, if possible, borderless. The window size constraints (like MinWidth, MaxWidth, MinHeight, MaxHeight and ResizeAllowed) are ignored, that is: we do not check whether screen size fits inside MinWidth and MaxWidth. If this is It is best to adjust this property before the window is open, this way window will be immediately open in the full-screen size. In the standard case (see https://castle-engine.io/manual_cross_platform.php about a typical initialization) you should place You can also change this property after the window is open. But note that:
|
property RedBits: Cardinal read FRedBits write FRedBits default 0; |
|
Required red / green / blue color buffer precision for this window. When 0, the default window system color precision will be used. You can either set them by separate red / green / blue properties. Or you can use ColorBits that reads / writes all three channels bits. Reading ColorBits simply returns the sum of Note that it's also possible to change color resolution by changing the whole screen settings. See TCastleApplication.VideoColorBits and TCastleApplication.VideoChange for this. These properties only request the color resolution for this window, which is less intrusive (you don't change the whole screen) but also may have a smaller chance of success. |
property GreenBits: Cardinal read FGreenBits write FGreenBits default 0; |
|
property BlueBits: Cardinal read FBlueBits write FBlueBits default 0; |
|
property ColorBits: Cardinal read GetColorBits write SetColorBits stored false default 0; |
|
property MousePosition: TVector2
read FMousePosition write SetMousePosition; |
|
Current mouse position. In case of touch devices, this reports the last known position for FingerIndex = 0, and setting this has no effect. See TTouch.Position for a documentaion how this is expressed. In all situations the About setting the mouse position:
|
property Touches[constIndex:Integer]: TTouch read GetTouches; |
|
Currently active Indexed from 0 to TouchesCount - 1. See also
|
property ResizeAllowed: TResizeAllowed
read FResizeAllowed write FResizeAllowed default raAllowed; |
|
When (if at all) window size may be changed.
|
property OnOpen: TContainerEvent read GetOnOpen write SetOnOpen; |
|
OpenGL context is created, initialize things that require OpenGL context. Often you do not need to use this callback (engine components will automatically create/release OpenGL resource when necessary). You usually will also want to implement Window.OnClose callback that should release stuff you create here. Often, instead of using this callback, it's cleaner to derive new classes from TCastleUserInterface class or it's descendants, and override their GLContextOpen / GLContextClose methods to react to context being open/closed. Using such TCastleUserInterface classes is usually easier, as you add/remove them from controls whenever you want (e.g. you add them in Application.OnInitialize), and underneath they create/release/create again the OpenGL resources when necessary.
It's guaranteed that every newly opened window will get EventOpen ( During EventOpen ( Be careful what you do in this callback if you want your game to work on Android or other non-standalone platforms. On Android, OpenGL context may be closed and opened at any time, as user can switch from/to your application at any time. You should use Application.OnInitialize for a one-time initialization (it is executed right before the very first |
property OnOpenObject: TContainerObjectEvent read GetOnOpenObject write SetOnOpenObject; |
|
property MinWidth: Integer read FMinWidth write FMinWidth default 100; |
|
Minimum and maximum window sizes. Always 0 < MinWidth <= MaxWidth and 0 < MinHeight <= MaxHeight
We do not allow user to resize the window outside of these constraints. We also fix window Width and Height to fit within these constraints when you Open the window. We do it regardless of ResizeAllowed (even when it's raNotAllowed). In other words, these constraints have a higher priority than ResizeAllowed and your desired Width and Height and even FullScreen (setting FullScreen property will stil change the visible sizes, but your perceived sizes will be constrained by this min/max). So you can be sure that (as long as window is open) Width / Height will always fit in these constraints. |
property MinHeight: Integer read FMinHeight write FMinHeight default 100; |
|
property MaxWidth: Integer read FMaxWidth write FMaxWidth default 4000; |
|
property MaxHeight: Integer read FMaxHeight write FMaxHeight default 4000; |
|
property DepthBits: Cardinal
read FDepthBits write FDepthBits default DefaultDepthBits; |
|
Required depth buffer precision. Zero means that we don't need depth buffer at all. We may get depth buffer with more precision than requested (we may even get depth buffer when we set Default value is DefaultDepthBits, which is non-zero and a reasonable default for 3D programs that want to work with depth test enabled. Note that we have a fallback mechanism in case DepthBits is too large: we fallback on DepthBitsFallback then. Design notes: One may ask why default value is not 0?
If you are writing a program that does not need depth buffer you should set Window.DepthBits := 0. The only advantage of having default |
property StencilBits: Cardinal
read FStencilBits write FStencilBits default 0; |
|
Required stencil buffer precision, zero means that stencil buffer is not needed. Just like with other XxxBits property, we may get more bits than we requested. But we will never get less — if window system will not be able to provide GL context with requested number of bits, Open will raise an error. Note that after initializing OpenGL context (when opening the window), |
property MultiSampling: Cardinal
read FMultiSampling write FMultiSampling default 1; |
|
How many samples are required for multi-sampling (anti-aliasing). Set AntiAliasing instead of this for more comfortable (higher-level) way to turn on multi-sampling (anti-aliasing). Setting AntiAliasing will also set this property. 1 means that no multi-sampling is required. Values larger than 1 mean that we require OpenGL context with multi-sampling capabilities. Various GPUs may support various values (it's a trade-off between quality and speed), try typical values 2 or 4. You can enable/disable anti-aliasing in your program by code like if GLFeatures.Multisample then glEnable(GL_MULTISAMPLE_ARB); if GLFeatures.Multisample then glDisable(GL_MULTISAMPLE_ARB);
But usually that's not needed, as it is "on" by default (GL_ARB_multisample spec says so) if you requested multi-sampling context (that is, if this property is > 1). See GL_ARB_multisample spec for details: [http://opengl.org/registry/specs/ARB/multisample.txt]. Just like with other XxxBits property, we may get more samples than we requested (e.g. if you request 3, you will most probably get 4). But we will never get less — if window system will not be able to provide GL context with requested number of bits, Open will raise an error. TODO: actually, this may change to be similar to Lazarus TOpenGLControl.MultiSampling, and also be more comfortable — to retry initialization with no multi-sampling. In this case this property will not be changed, to be nice. You can always read OpenGL GL_SAMPLE_BUFFERS_ARB and GL_SAMPLES_ARB values after initializing OpenGL context, to know exactly how many samples did you actually get, and did you get multi-sampling at all. Actually, we already initialize global CastleGLUtils.GLCurrentMultiSampling for you, you can use this. |
property AntiAliasing: TAntiAliasing
read FAntiAliasing write SetAntiAliasing default DefaultAntiAliasing; |
|
Comfortably turn on/off anti-aliasing. Setting this property automatically sets also the MultiSampling property. Although it's easy to request multi-sampling by using the MultiSampling property directly, using |
property AlphaBits: Cardinal
read FAlphaBits write FAlphaBits default 0; |
|
Required number of bits in alpha channel of color buffer. Zero means that alpha channel is not needed. Just like with other XxxBits property, we may get more bits than we requested. But we will never get less — if window system will not be able to provide GL context with requested number of bits, Open will raise an error. It's undefined how I'll treat this variable when indexed color mode will be possible in TCastleWindow. |
property AccumBits: TVector4Cardinal read FAccumBits write FAccumBits; deprecated; |
|
Warning: this symbol is deprecated. Required number of bits in color channels of accumulation buffer. Color channel is 0..3: red, green, blue, alpha. Zero means that given channel of accumulation buffer is not needed, so when the vector is all zeros (default value) this means that accumulation buffer is not needed at all. Just like with other XxxBits property, we may get more bits than we requested. But we will never get less — if window system will not be able to provide GL context with requested number of bits, Open will raise an error. This property is deprecated, since modern OpenGL deprecated accumulation buffer. It may not be supported by some backends (e.g. now LCL backend, the default backend on macOS, doesn't support it). |
property GtkIconName: string read FGtkIconName write FGtkIconName; |
|
Name of the icon for this window used by GTK 2 backend. This is simply passed to It's ignored on non-GTK 2 backends. |
property Visible: boolean read FVisible write FVisible default true; |
|
Should this window be actually displayed on the desktop. In all normal programs you want to leave this as Setting this to If you implement such thing, remember that you should not render and capture the normal front or back buffer contents. OpenGL makes no guarantee that a hidden window will have any allocated memory, so capturing hidden window contents isn't useful (you may get something valid, or you may get random / blank screen, depending on OS and GPU). However, you can create Framebuffer Object on modern GPUs, and capture it's contents. An example code snippet: { add CastleGLImages, CastleImages to your uses clause } var ScreenshotRender: TGLRenderToTexture; Image: TRGBImage; begin ScreenshotRender := TGLRenderToTexture.Create(Width, Height); try ScreenshotRender.Buffer := tbNone; ScreenshotRender.GLContextOpen; ScreenshotRender.RenderBegin; { render your stuff here } { capture the screen } Image := SaveScreen_NoFlush(Rectangle(0, 0, Width, Height), ScreenshotRender.ColorBuffer); try SaveImage(Image, 'aaa.png'); finally FreeAndNil(Image) end; ScreenshotRender.RenderEnd; finally FreeAndNil(ScreenshotRender) end; end; |
property OnRender: TContainerEvent read GetOnRender write SetOnRender; |
|
Render window contents here. Called when window contents must be redrawn, e.g. after creating a window, after resizing a window, after uncovering the window etc. You can also request yourself a redraw of the window by the Invalidate method, which will cause this event to be called at nearest good time. Note that calling Invalidate while in EventRender ( When you have some controls on the Controls list, the |
property OnDraw: TContainerEvent read GetOnRender write SetOnRender; deprecated; |
|
Warning: this symbol is deprecated. Deprecated name for OnRender. |
property OnBeforeRender: TContainerEvent read GetOnBeforeRender write SetOnBeforeRender; |
|
Always called right before EventRender (OnRender). These two events, EventBeforeRender ( The only difference between these two events is that time spent in EventBeforeRender ( |
property OnResize: TContainerEvent read GetOnResize write SetOnResize; |
|
Called when the window size (Width, Height) changes. It's also guaranteed to be called during Open, right after the EventOpen (OnOpen) event. See also
|
property OnClose: TContainerEvent read GetOnClose write SetOnClose; |
|
Called when the window is closed, right before the OpenGL context is destroyed. This is your last chance to release OpenGL resources, like textures, shaders, display lists etc. This is a counterpart to OnOpen event. |
property OnCloseObject: TContainerObjectEvent read GetOnCloseObject write SetOnCloseObject; |
|
property OnPress: TInputPressReleaseEvent read GetOnPress write SetOnPress; |
|
Called when user presses a key or mouse button or moves mouse wheel. |
property OnRelease: TInputPressReleaseEvent read GetOnRelease write SetOnRelease; |
|
Called when user releases a pressed key or mouse button. It's called right after The TInputPressRelease structure, passed as a parameter to this event, contains the exact information what was released. Note that reporting characters for "key release" messages is not perfect, as various key combinations (sometimes more than one?) may lead to generating given character. We have some intelligent algorithm for this, used to make Characters table and to detect this C for This solves in a determined way problems like "what happens if I press Shift, then X, then release Shift, then release X". (will "X" be correctly released as pressed and then released? yes. will small "x" be reported as released at the end? no, as it was never pressed.) |
property OnCloseQuery: TContainerEvent read FOnCloseQuery write FOnCloseQuery; |
|
Called when user tries to close the window. This is called when you use window manager features to close the window, like clicking on the "close" icon on the window frame or using Alt+F4 on most desktops. This is not called when you explicitly close the window by calling the Close method. When this callback is not assigned, we will just let the window be closed. When it's assigned, the window will not closed — you should call here Close explicitly if you want to (for example, after asking user for confirmation "do you really want to quit?"). When handling this event, you must remember that user may try to close our window at any time. E.g. if you're implementing here somehing like showing user text "You cannot quit now" or asking user "Do you really want to quit" remember that while you display such message to user and you're processing events (e.g. looking for keypress "Yes" or "No"), user may try to close your window again. CastleMessages unit offers some nice routines that you can safely use here, e.g. you can use it inside if MessageYesNo(Window, 'Are you sure you want to quit?') then Close; Inside MessageYesNo, when we're processing events, and waiting for user's answer (yes or no), futher This event is also useful if you want to call Close(false) on closing the window (i.e. QuitWhenLastWindowClosed = false). By default, if this event is undefined, we call Close(true) when user tries to close the window. |
property OnMotion: TInputMotionEvent read GetOnMotion write SetOnMotion; |
|
Mouse or a finger on touch device moved. For a mouse, remember you always have the currently pressed mouse buttons in MousePressed. When this is called, the MousePosition property records the previous mouse position, while callback parameter NewMousePosition gives the new mouse position. |
property OnUpdate: TContainerEvent read GetOnUpdate write SetOnUpdate; |
|
Continuously occuring event, called for all open windows. This event is called at least as regularly as redraw, so it is continuously called even when your game is overwhelmed by messages (like mouse moves) and redraws. Called at the same time when Application.OnUpdate is called. You should add code to this window's |
property OnIdle: TContainerEvent read GetOnUpdate write SetOnUpdate; deprecated; |
|
Warning: this symbol is deprecated. Deprecated name for OnUpdate. |
property OnTimer: TContainerEvent read FOnTimer write FOnTimer; deprecated 'use TCastleTimer to perform periodic operations, or track time delay in OnUpdate'; |
|
Warning: this symbol is deprecated: use TCastleTimer to perform periodic operations, or track time delay in OnUpdate Timer event is called approximately after each Application.TimerMilisec miliseconds passed. See also Application.OnTimer. This is a very simple timer mechanism, as all timers (timers for all windows and the global Application timer) use the same delay: Application.TimerMilisec. We consciously decided to not implement anything more involved here. If you need really flexible timer mechanism, do not use this. Instead use OnUpdate (or TCastleUserInterface.Update in your TCastleUserInterface descendant, or TCastleTransform.Update) and look at it's Under Lazarus, you can of course also use LCL timers. |
property OnDropFiles: TDropFilesFunc read FOnDropFiles write FOnDropFiles; |
|
Called when user drag and drops file(s) on the window. In case of macOS bundle, this is also called when user opens a document associated with our application by double-clicking. Note: this is currently supported only by LCL and Cocoa backends of TCastleWindow, see https://castle-engine.io/castlewindow_backends . |
property AutoRedisplay: boolean read FAutoRedisplay write SetAutoRedisplay
default true; |
|
Should we automatically redraw the window all the time, without the need for an Invalidate call. If If your game may have a still screen (nothing animates), then this approach is a little unoptimal, as we use CPU and GPU for drawing, when it's not needed. In such case, you can set this property to |
property MainMenu: TMenu read FMainMenu write SetMainMenu; |
|
Menu bar of this window. When not assigned, we have no menu bar. Note that MainMenu.Caption will be ignored. You can change this freely while Closed. You can change this almost freely while not Closed: you can use various properties of TMenuEntry descendants (adding, deleting items from TMenu, changing Caption, Key, KeyString, Checked properties – anything) and you can change value of Note that MainMenu.Enabled is honoured (as well as Enabled for all menu items inside, of course). You can use this to disallow user from clicking on the whole menu. When MainMenu.Enabled = Disabling |
property MainMenuVisible: boolean
read FMainMenuVisible write FMainMenuVisible default true; |
|
Is MainMenu visible. |
property OwnsMainMenu: boolean read FOwnsMainMenu write FOwnsMainMenu default true; |
|
If true then the MainMenu will automatically freed when this TCastleWindow instance is freed. |
property OnMenuClick: TMenuClickFunc read FOnMenuClick write FOnMenuClick; |
|
Called each time user chooses some menu item and it's not handled in TMenuItem.DoClick. By default, menu item handling is passed to TMenuItem.DoClick. Only when it return |
property OnMenuCommand: TMenuClickFunc read FOnMenuClick write FOnMenuClick; deprecated; |
|
Warning: this symbol is deprecated. Deprecated name for OnMenuClick. |
property Focused: boolean read FFocused; |
|
Is the window focused now, which means that keys/mouse events are directed to this window. |
property UserData: Pointer read FUserData write FUserData; |
|
Place for your pointer, for any purposes. No code in this unit touches the value of this field. This is similar to TComponent.Tag property. |
property Closed: boolean read FClosed default true; |
|
property Cursor: TMouseCursor read FCursor write SetCursor default mcDefault; deprecated 'do not set this, engine will override this. Set TCastleUserInterface.Cursor of your UI controls to control the Cursor.'; |
|
Warning: this symbol is deprecated: do not set this, engine will override this. Set TCastleUserInterface.Cursor of your UI controls to control the Cursor. |
property InternalCursor: TMouseCursor read FCursor write SetCursor default mcDefault; |
|
Mouse cursor appearance over this window. See TMouseCursor for a list of possible values and their meanings. Note that this is for internal usage in the engine. In your applications, you should set TCastleUserInterface.Cursor on any UI control (including on TUIState), never set this property directly. |
property NamedParameters: TCastleStringList read FNamedParameters; |
|
Named parameters used to initialize this window. Right now not used (were used by NPAPI plugin, may be useful to new web target). |
property FpsShowOnCaption: boolean
read FFpsShowOnCaption write FFpsShowOnCaption default false; |
|
Show current frames per second on window caption. You can modify this property only before calling Open. |
property SwapFullScreen_Key: TKey
read FSwapFullScreen_Key write FSwapFullScreen_Key default keyNone; |
|
Key to use to switch between FullScreen and not FullScreen. Set to keyNone (default) to disable this functionality. Suggested value to enable this functionality is keyF11, this is consistent will fullscreen key in other programs. You can freely modify it at any time, even after calling Open. The fullscreen is switched by closing it, changing FullScreen property and opening it again. So be sure to have good OnOpen / OnClose implementations: you have to be able to recreate in OnOpen everything that was released in OnClose. |
property Close_KeyString: String
read FClose_KeyString write FClose_KeyString; |
|
Key to use to close the window. Set to '' (default) to disable this functionality. Suggested value to enable this functionality is CharEscape. You can freely modify it at any time, even after calling Open. |
property FpsCaptionUpdateDelay: Single
read FFpsCaptionUpdateDelay write FFpsCaptionUpdateDelay
default DefaultFpsCaptionUpdateDelay; |
|
The amount of time (in seconds) between updating Caption with current FPS value. Used when FpsShowOnCaption. You probably don't want to change this – the default value is synchronized with how often the TFramesPerSecond actually change. So there's no point in making this smaller (you may cause slowdowns, and you will not see anything better). |
Generated by PasDoc 0.16.0.