Castle Game Engine: CastleControls: Class TCastleButton

# Class TCastleButton
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleControls ## Declaration `type TCastleButton = class(TUIControlFont)` ## Description Button inside OpenGL context. This is TUIControl descendant, so to use it just add it to the TCastleWindowCustom.Controls or TCastleControlCustom.Controls list. You will also usually want to adjust position (TCastleButton.Left, TCastleButton.Bottom), TCastleButton.Caption, and assign TCastleButton.OnClick (or ovevrride TCastleButton.DoClick). ## Hierarchy TComponent TInputListener TUIControl TUIControlPos TUIControlFont TCastleButton ## Overview ### Methods
| `constructor Create(AOwner: TComponent); override;`
| `destructor Destroy; override;`
| `function DrawStyle: TUIControlDrawStyle; override;`
| `procedure Draw; override;`
| `function PositionInside(const X, Y: Integer): boolean; override;`
| `procedure GLContextOpen; override;`
| `procedure GLContextClose; override;`
| `function Press(const Event: TInputPressRelease): boolean; override;`
| `function Release(const Event: TInputPressRelease): boolean; override;`
| `procedure DoClick; virtual;`
| `procedure SetFocused(const Value: boolean); override;`
### Properties
| `property Image: TCastleImage read FImage write SetImage;`
| `property OwnsImage: boolean read FOwnsImage write FOwnsImage default false;`
| `property MinImageWidth: Cardinal read FMinImageWidth write FMinImageWidth default 0;`
| `property MinImageHeight: Cardinal read FMinImageHeight write FMinImageHeight default 0;`
| `property Width: Cardinal read FWidth write SetWidth default 0;`
| `property Height: Cardinal read FHeight write SetHeight default 0;`
| `property AutoSize: boolean read FAutoSize write SetAutoSize default true;`
| `property AutoSizeWidth: boolean read FAutoSizeWidth write SetAutoSizeWidth default true;`
| `property AutoSizeHeight: boolean read FAutoSizeHeight write SetAutoSizeHeight default true;`
| `property OnClick: TNotifyEvent read FOnClick write FOnClick;`
| `property Caption: string read FCaption write SetCaption;`
| `property Toggle: boolean read FToggle write FToggle default false;`
| `property Pressed: boolean read FPressed write SetPressed default false;`
| `property Opacity: Single read FOpacity write FOpacity default 1.0;`
| `property ImageLayout: TCastleButtonImageLayout read FImageLayout write SetImageLayout default ilLeft;`
| `property ImageAlphaTest: boolean read FImageAlphaTest write FImageAlphaTest default false;`
## Description ### Methods
| `constructor Create(AOwner: TComponent); override;`
| `destructor Destroy; override;`
| `function DrawStyle: TUIControlDrawStyle; override;`
| `procedure Draw; override;`
| `function PositionInside(const X, Y: Integer): boolean; override;`
| `procedure GLContextOpen; override;`
| `procedure GLContextClose; override;`
| `function Press(const Event: TInputPressRelease): boolean; override;`
| `function Release(const Event: TInputPressRelease): boolean; override;`
| `procedure DoClick; virtual;`
Called when user clicks the button. In this class, simply calls OnClick callback.
| `procedure SetFocused(const Value: boolean); override;`
### Properties
| `property Image: TCastleImage read FImage write SetImage;`
Set this to non-nil to display an image on the button.
| `property OwnsImage: boolean read FOwnsImage write FOwnsImage default false;`
Should we free the Image when you set another one or at destructor.
| `property MinImageWidth: Cardinal read FMinImageWidth write FMinImageWidth default 0;`
Auto-size routines (see AutoSize) may treat the image like always having at least these minimal sizes. Even if the Image is empty (`Nil`). This is useful when you have a row of buttons (typical for toolbar), and you want them to have the same height, and their captions to be displayed at the same level, regardless of their images sizes.
| `property MinImageHeight: Cardinal read FMinImageHeight write FMinImageHeight default 0;`
| `property Width: Cardinal read FWidth write SetWidth default 0;`
| `property Height: Cardinal read FHeight write SetHeight default 0;`
| `property AutoSize: boolean read FAutoSize write SetAutoSize default true;`
When `AutoSize` is `True` (the default) then Width/Height are automatically adjusted when you change the Caption and Image. They take into account Caption width/height with current font, Image width/height, and add some margin to make it look good. To be more precise, Width is adjusted only when `AutoSize` and AutoSizeWidth. And Height is adjusted only when `AutoSize` and AutoSizeHeight. This way you can turn off auto-sizing in only one dimension if you want (and when you don't need such flexibility, leave AutoSizeWidth = AutoSizeHeight = `True` and control both by simple `AutoSize`). Note that this adjustment happens only when OpenGL context is initialized (because only then we actually know the font used). So don't depend on Width/Height values calculated correctly before OpenGL context is ready.
| `property AutoSizeWidth: boolean read FAutoSizeWidth write SetAutoSizeWidth default true;`
| `property AutoSizeHeight: boolean read FAutoSizeHeight write SetAutoSizeHeight default true;`
| `property OnClick: TNotifyEvent read FOnClick write FOnClick;`
| `property Caption: string read FCaption write SetCaption;`
| `property Toggle: boolean read FToggle write FToggle default false;`
Can the button be permanently pressed. Good for making a button behave like a checkbox, that is indicate a boolean state. When Toggle is `True`, you can set the Pressed property, and the clicks are visualized a little differently.
| `property Pressed: boolean read FPressed write SetPressed default false;`
Is the button pressed down. If Toggle is `True`, you can read and write this property to set the pressed state. When not Toggle, this property isn't really useful to you. The pressed state is automatically managed then to visualize user clicks. In this case, you can read this property, but you cannot reliably set it.
| `property Opacity: Single read FOpacity write FOpacity default 1.0;`
Opacity (1 - transparency) with which control is drawn. When this is < 1, we draw control with nice blending. Make sure you have some background control underneath in this case.
| `property ImageLayout: TCastleButtonImageLayout read FImageLayout write SetImageLayout default ilLeft;`
Where the Image is drawn on a button.
| `property ImageAlphaTest: boolean read FImageAlphaTest write FImageAlphaTest default false;`
If the image has alpha channel, should we render with alpha test (simple yes/no transparency) or alpha blending (smootly mix with background using full transparency).
Generated by PasDoc 0.13.0 on 2013-08-17 21:27:12