| 1 |
{%MainUnit castlecontrols.pas} |
| 2 |
{ |
| 3 |
Copyright 2010-2023 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{$ifdef read_interface} |
| 18 |
|
| 19 |
{ Fill a rectangle on screen with given color or theme image. } |
| 20 |
TCastleRectangleControl = class(TCastleUserInterface) |
| 21 |
strict private |
| 22 |
FColor: TCastleColor; |
| 23 |
FThemeImage: TThemeImage; |
| 24 |
FUseThemeImage: boolean; |
| 25 |
FInterceptInput: boolean; |
| 26 |
procedure SetColor(const Value: TCastleColor); |
| 27 |
procedure SetThemeImage(const Value: TThemeImage); |
| 28 |
procedure SetUseThemeImage(const Value: boolean); |
| 29 |
public |
| 30 |
constructor Create(AOwner: TComponent); override; |
| 31 |
destructor Destroy; override; |
| 32 |
procedure Render; override; |
| 33 |
function Press(const Event: TInputPressRelease): boolean; override; |
| 34 |
function Release(const Event: TInputPressRelease): boolean; override; |
| 35 |
function Motion(const Event: TInputMotion): boolean; override; |
| 36 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 37 |
|
| 38 |
{ Rectangle color. By default, opaque white. } |
| 39 |
property Color: TCastleColor read FColor write SetColor; |
| 40 |
|
| 41 |
{ Fill rectangle with theme image. You have to set @link(UseThemeImage) to true to take effect. } |
| 42 |
property ThemeImage: TThemeImage read FThemeImage write SetThemeImage; |
| 43 |
{$ifdef FPC}deprecated 'use TCastleImageControl to display images';{$endif} |
| 44 |
|
| 45 |
{ Use theme image for drawing instead of color. } |
| 46 |
property UseThemeImage: boolean read FUseThemeImage write SetUseThemeImage default false; |
| 47 |
{$ifdef FPC}deprecated 'use TCastleImageControl to display images';{$endif} |
| 48 |
|
| 49 |
{ Prevents passing mouse/keyboard events to the controls underneath. |
| 50 |
More precisely, when this property is @true, then the |
| 51 |
@link(Press), @link(Release) and @link(Motion) events are marked as |
| 52 |
"handled" by this control. } |
| 53 |
property InterceptInput: boolean read FInterceptInput write FInterceptInput |
| 54 |
default false; |
| 55 |
{$ifdef FPC}deprecated 'in each case, there should be a cleaner way to disable something from processing the input';{$endif} |
| 56 |
|
| 57 |
{$define read_interface_class} |
| 58 |
{$I auto_generated_persistent_vectors/tcastlerectanglecontrol_persistent_vectors.inc} |
| 59 |
{$undef read_interface_class} |
| 60 |
end; |
| 61 |
|
| 62 |
{$endif read_interface} |
| 63 |
|
| 64 |
{$ifdef read_implementation} |
| 65 |
|
| 66 |
{ TCastleRectangleControl ---------------------------------------------------- } |
| 67 |
|
| 68 |
constructor TCastleRectangleControl.Create(AOwner: TComponent); |
| 69 |
begin |
| 70 |
inherited; |
| 71 |
FColor := White; |
| 72 |
FThemeImage := tiWindow; |
| 73 |
FUseThemeImage := false; |
| 74 |
|
| 75 |
{$define read_implementation_constructor} |
| 76 |
{$I auto_generated_persistent_vectors/tcastlerectanglecontrol_persistent_vectors.inc} |
| 77 |
{$undef read_implementation_constructor} |
| 78 |
end; |
| 79 |
|
| 80 |
destructor TCastleRectangleControl.Destroy; |
| 81 |
begin |
| 82 |
{$define read_implementation_destructor} |
| 83 |
{$I auto_generated_persistent_vectors/tcastlerectanglecontrol_persistent_vectors.inc} |
| 84 |
{$undef read_implementation_destructor} |
| 85 |
inherited; |
| 86 |
end; |
| 87 |
|
| 88 |
procedure TCastleRectangleControl.SetColor(const Value: TCastleColor); |
| 89 |
begin |
| 90 |
if not TCastleColor.PerfectlyEquals(FColor, Value) then |
| 91 |
begin |
| 92 |
FColor := Value; |
| 93 |
VisibleChange([chRender]); |
| 94 |
end; |
| 95 |
end; |
| 96 |
|
| 97 |
procedure TCastleRectangleControl.SetThemeImage(const Value: TThemeImage); |
| 98 |
begin |
| 99 |
if FThemeImage <> Value then |
| 100 |
begin |
| 101 |
FThemeImage := Value; |
| 102 |
VisibleChange([chRender]); |
| 103 |
end; |
| 104 |
end; |
| 105 |
|
| 106 |
procedure TCastleRectangleControl.SetUseThemeImage(const Value: boolean); |
| 107 |
begin |
| 108 |
if FUseThemeImage <> Value then |
| 109 |
begin |
| 110 |
FUseThemeImage := Value; |
| 111 |
VisibleChange([chRender]); |
| 112 |
end; |
| 113 |
end; |
| 114 |
|
| 115 |
procedure TCastleRectangleControl.Render; |
| 116 |
begin |
| 117 |
inherited; |
| 118 |
{$warnings off} // using deprecated just to keep it working |
| 119 |
if FUseThemeImage then |
| 120 |
Theme.Draw(RenderRect, ThemeImage, UIScale, Color) |
| 121 |
else |
| 122 |
{$warnings on} |
| 123 |
DrawRectangle(RenderRect, Color); |
| 124 |
end; |
| 125 |
|
| 126 |
function TCastleRectangleControl.Press(const Event: TInputPressRelease): boolean; |
| 127 |
begin |
| 128 |
Result := inherited; |
| 129 |
{$warnings off} // using deprecated just to keep it working |
| 130 |
Result := Result or InterceptInput; |
| 131 |
{$warnings on} |
| 132 |
end; |
| 133 |
|
| 134 |
function TCastleRectangleControl.Release(const Event: TInputPressRelease): boolean; |
| 135 |
begin |
| 136 |
Result := inherited; |
| 137 |
{$warnings off} // using deprecated just to keep it working |
| 138 |
Result := Result or InterceptInput; |
| 139 |
{$warnings on} |
| 140 |
end; |
| 141 |
|
| 142 |
function TCastleRectangleControl.Motion(const Event: TInputMotion): boolean; |
| 143 |
begin |
| 144 |
Result := inherited; |
| 145 |
{$warnings off} // using deprecated just to keep it working |
| 146 |
Result := Result or InterceptInput; |
| 147 |
{$warnings on} |
| 148 |
end; |
| 149 |
|
| 150 |
function TCastleRectangleControl.PropertySections( |
| 151 |
const PropertyName: String): TPropertySections; |
| 152 |
begin |
| 153 |
if (PropertyName = 'ColorPersistent') then |
| 154 |
Result := [psBasic] |
| 155 |
else |
| 156 |
Result := inherited PropertySections(PropertyName); |
| 157 |
end; |
| 158 |
|
| 159 |
{$define read_implementation_methods} |
| 160 |
{$I auto_generated_persistent_vectors/tcastlerectanglecontrol_persistent_vectors.inc} |
| 161 |
{$undef read_implementation_methods} |
| 162 |
|
| 163 |
{$endif read_implementation} |