| 1 |
{ |
| 2 |
Copyright 2010-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Property and component editors using LCL. |
| 17 |
These can be used when we're inside Lazarus IDE or inside CGE editor. |
| 18 |
|
| 19 |
For documentation how to create property editors, component editors etc. see |
| 20 |
- http://wiki.freepascal.org/How_To_Write_Lazarus_Component#Component_editors |
| 21 |
- comments of Lazarus ideintf/propedits.pp sources. } |
| 22 |
unit CastlePropEdits; |
| 23 |
|
| 24 |
{$I castleconf.inc} |
| 25 |
|
| 26 |
interface |
| 27 |
|
| 28 |
uses PropEdits; |
| 29 |
|
| 30 |
{ Some of the property editors are publicly exposed, |
| 31 |
to enable using them for your own properties in custom components too. |
| 32 |
See examples/advanced_editor/custom_component/code/gamecontrols.pas . } |
| 33 |
{$define read_interface} |
| 34 |
{$I castlepropedits_any_subproperties.inc} |
| 35 |
{$I castlepropedits_url.inc} |
| 36 |
{$undef read_interface} |
| 37 |
|
| 38 |
procedure Register; |
| 39 |
|
| 40 |
implementation |
| 41 |
|
| 42 |
uses // FPC and LCL units |
| 43 |
SysUtils, Classes, TypInfo, Forms, Math, |
| 44 |
LResources, Dialogs, Controls, LCLVersion, OpenGLContext, Graphics, ObjInspStrConsts, |
| 45 |
// Lazarus design-time (IDE) units |
| 46 |
ComponentEditors, |
| 47 |
// CGE units |
| 48 |
CastleSceneCore, CastleScene, CastleLCLUtils, X3DLoad, X3DNodes, CastleCameras, |
| 49 |
CastleUIControls, CastleControl, CastleControls, CastleImages, CastleTransform, |
| 50 |
CastleVectors, CastleRectangles, CastleUtils, CastleColors, CastleViewport, |
| 51 |
CastleDialogs, |
| 52 |
CastleTiledMap, CastleGLImages, CastleStringUtils, CastleFilesUtils, |
| 53 |
CastleInternalExposeTransformsDialog, CastleInternalTiledLayersDialog, |
| 54 |
CastleInternalRegionDialog, |
| 55 |
CastleSoundEngine, CastleFonts, |
| 56 |
CastleScriptParser, CastleInternalLclDesign, CastleTerrain, CastleLog, |
| 57 |
CastleEditorAccess, CastleRenderOptions, CastleThirdPersonNavigation; |
| 58 |
|
| 59 |
{ Wrap given floating-point expression in CastleScript in "deg(...)". |
| 60 |
If it's already wrapped, leave it as-is.} |
| 61 |
function WrapDegIfNeeded(const FloatExpression: String): String; |
| 62 |
begin |
| 63 |
if IsPrefix('deg', Trim(FloatExpression), true) then |
| 64 |
{ If user explicitly left "deg(" marker, that's OK, leave it. } |
| 65 |
Result := FloatExpression |
| 66 |
else |
| 67 |
{ If user deleted "deg(" marker, interpret result as degrees |
| 68 |
*anyway*. This is more user-friendly, Blender and Godot also do |
| 69 |
it like this. } |
| 70 |
Result := 'deg(' + FloatExpression + ')'; |
| 71 |
end; |
| 72 |
|
| 73 |
{$define read_implementation} |
| 74 |
{$I castlepropedits_url.inc} |
| 75 |
|
| 76 |
{ These include files are only used in the implementation, |
| 77 |
they don't look at read_interface/read_implementation symbols. } |
| 78 |
{$I castlepropedits_any_subproperties.inc} |
| 79 |
{$I castlepropedits_autoanimation.inc} |
| 80 |
{$I castlepropedits_meshcolliderscene.inc} |
| 81 |
{$I castlepropedits_vector.inc} |
| 82 |
{$I castlepropedits_image.inc} |
| 83 |
{$I castlepropedits_region.inc} |
| 84 |
{$I castlepropedits_number.inc} |
| 85 |
{$I castlepropedits_exposetransforms.inc} |
| 86 |
{$I castlepropedits_tiledlayers.inc} |
| 87 |
{$I castlepropedits_rangeset.inc} |
| 88 |
{$I castlepropedits_3dcoords.inc} |
| 89 |
{$I castlepropedits_colorchannels.inc} |
| 90 |
{$I castlepropedits_component_transform.inc} |
| 91 |
{$I castlepropedits_component_scene.inc} |
| 92 |
{$I castlepropedits_component_imagetransform.inc} |
| 93 |
{$I castlepropedits_component_imagecontrol.inc} |
| 94 |
{$I castlepropedits_component_transformdesign.inc} |
| 95 |
{$I castlepropedits_component_design.inc} |
| 96 |
{$I castlepropedits_component_joints.inc} |
| 97 |
{$I castlepropedits_abstracttwobodiesjoint.inc} |
| 98 |
|
| 99 |
procedure Register; |
| 100 |
begin |
| 101 |
{ URL properties } |
| 102 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleSceneCore, |
| 103 |
'URL', TSceneURLPropertyEditor); |
| 104 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleImageControl, |
| 105 |
'URL', TImageURLPropertyEditor); |
| 106 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleImagePersistent, |
| 107 |
'URL', TImageURLPropertyEditor); |
| 108 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleAbstractPrimitive, |
| 109 |
'Texture', TImageURLPropertyEditor); |
| 110 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleAbstractPrimitive, |
| 111 |
'TextureNormalMap', TImageURLPropertyEditor); |
| 112 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleBitmapFont, |
| 113 |
'ImageUrl', TImageURLPropertyEditor); |
| 114 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleImageTransform, |
| 115 |
'Url', TImageURLPropertyEditor); |
| 116 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleTerrainImage, |
| 117 |
'Url', TImageURLPropertyEditor); |
| 118 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleTerrainLayer, |
| 119 |
'Texture', TImageURLPropertyEditor); |
| 120 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleDesign, |
| 121 |
'URL', TDesignURLPropertyEditor); |
| 122 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleTransformDesign, |
| 123 |
'URL', TTransformDesignURLPropertyEditor); |
| 124 |
{$warnings off} // define to support deprecated, for now |
| 125 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleTiledMapControl, |
| 126 |
'URL', TTiledMapURLPropertyEditor); |
| 127 |
{$warnings on} |
| 128 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleTiledMap, |
| 129 |
'URL', TTiledMapURLPropertyEditor); |
| 130 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleSound, |
| 131 |
'URL', TSoundURLPropertyEditor); |
| 132 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleFont, |
| 133 |
'URL', TFontURLPropertyEditor); |
| 134 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleBackground, |
| 135 |
'TextureNegativeX', TImageURLPropertyEditor); |
| 136 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleBackground, |
| 137 |
'TextureNegativeY', TImageURLPropertyEditor); |
| 138 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleBackground, |
| 139 |
'TextureNegativeZ', TImageURLPropertyEditor); |
| 140 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleBackground, |
| 141 |
'TexturePositiveX', TImageURLPropertyEditor); |
| 142 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleBackground, |
| 143 |
'TexturePositiveY', TImageURLPropertyEditor); |
| 144 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleBackground, |
| 145 |
'TexturePositiveZ', TImageURLPropertyEditor); |
| 146 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleControl, |
| 147 |
'DesignUrl', TDesignURLPropertyEditor); |
| 148 |
|
| 149 |
{ Improved numeric properties } |
| 150 |
RegisterPropertyEditor(TypeInfo(Single), nil, '', TCastleFloatPropertyEditor); |
| 151 |
RegisterPropertyEditor(TypeInfo(Double), nil, '', TCastleFloatPropertyEditor); |
| 152 |
{$ifndef EXTENDED_EQUALS_DOUBLE} |
| 153 |
RegisterPropertyEditor(TypeInfo(Extended), nil, '', TCastleFloatPropertyEditor); |
| 154 |
{$endif} |
| 155 |
{$ifdef CPU64} |
| 156 |
RegisterPropertyEditor(TypeInfo(PtrInt), TComponent, 'Tag', TCastleTagPropertyEditor); |
| 157 |
{$endif} |
| 158 |
RegisterPropertyEditor(TypeInfo(Single), TCastleVector4RotationPersistent, 'W', |
| 159 |
TCastleFloatRotationPropertyEditor); |
| 160 |
RegisterPropertyEditor(TypeInfo(Single), TCastleImagePersistent, 'Rotation', |
| 161 |
TCastleFloatRotationPropertyEditor); |
| 162 |
RegisterPropertyEditor(TypeInfo(Single), TCastleImageControl, 'Rotation', |
| 163 |
TCastleFloatRotationPropertyEditor); |
| 164 |
RegisterPropertyEditor(TypeInfo(Single), TCastleSpotLight, 'BeamWidth', |
| 165 |
TCastleFloatRotationPropertyEditor); |
| 166 |
RegisterPropertyEditor(TypeInfo(Single), TCastleSpotLight, 'CutOffAngle', |
| 167 |
TCastleFloatRotationPropertyEditor); |
| 168 |
|
| 169 |
{ Handle using TCastleRegionEditor. |
| 170 |
Note: TBorder rule with 'ProtectedSides' name is registered |
| 171 |
before registering for TBorder with any name below. |
| 172 |
(Not tested if it's really necessary, but seems safer). } |
| 173 |
RegisterPropertyEditor(TypeInfo(TBorder), nil, 'ProtectedSides', |
| 174 |
TCastleRegionEditor); |
| 175 |
RegisterPropertyEditor(TypeInfo(TFloatRectanglePersistent), nil, 'RegionPersistent', |
| 176 |
TCastleRegionEditor); |
| 177 |
|
| 178 |
{ Properties that simply use TSubPropertiesEditor. |
| 179 |
Registering properties that use TSubPropertiesEditor |
| 180 |
(not any descendant of it) is still necessary to expand them |
| 181 |
in castle-editor and Lazarus design-time. } |
| 182 |
RegisterPropertyEditor(TypeInfo(TCastleRootTransform), TCastleViewport, 'Items', |
| 183 |
TSubPropertiesEditor); |
| 184 |
RegisterPropertyEditor(TypeInfo(TBorder), nil, '', |
| 185 |
TSubPropertiesEditor); |
| 186 |
|
| 187 |
{ Other properties } |
| 188 |
RegisterPropertyEditor(TypeInfo(TCastleImagePersistent), nil, '', |
| 189 |
TCastleImagePersistentEditor); |
| 190 |
RegisterPropertyEditor(TypeInfo(TCastleVector2Persistent), nil, '', |
| 191 |
TCastleVector2PropertyEditor); |
| 192 |
RegisterPropertyEditor(TypeInfo(TCastleVector3Persistent), TCastleTransform, 'ScalePersistent', |
| 193 |
TScalePropertyEditor); |
| 194 |
RegisterPropertyEditor(TypeInfo(TCastleVector3Persistent), TCastleBox, 'SizePersistent', |
| 195 |
TScalePropertyEditor); |
| 196 |
RegisterPropertyEditor(TypeInfo(TCastleVector3Persistent), TCastleBoxCollider, 'SizePersistent', |
| 197 |
TScalePropertyEditor); |
| 198 |
RegisterPropertyEditor(TypeInfo(TCastleVector2Persistent), TCastlePlane, 'SizePersistent', |
| 199 |
TSize2DPropertyEditor); |
| 200 |
RegisterPropertyEditor(TypeInfo(TCastleVector2Persistent), TCastleImageTransform, 'SizePersistent', |
| 201 |
TSize2DPropertyEditor); |
| 202 |
RegisterPropertyEditor(TypeInfo(TCastleVector3Persistent), nil, '', |
| 203 |
TCastleVector3PropertyEditor); |
| 204 |
RegisterPropertyEditor(TypeInfo(TCastleVector4Persistent), nil, '', |
| 205 |
TCastleVector4PropertyEditor); |
| 206 |
RegisterPropertyEditor(TypeInfo(TCastleVector4RotationPersistent), nil, '', |
| 207 |
TCastleVectorRotationPropertyEditor); |
| 208 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleSceneCore, 'AutoAnimation', |
| 209 |
TSceneAutoAnimationPropertyEditor); |
| 210 |
RegisterPropertyEditor(TypeInfo(TStrings), TCastleSceneCore, 'ExposeTransforms', |
| 211 |
TExposeTransformsPropertyEditor); |
| 212 |
RegisterPropertyEditor(TypeInfo(TCastleTiledMap.TLayers), TCastleTiledMap, 'Layers', |
| 213 |
TTiledLayersPropertyEditor); |
| 214 |
|
| 215 |
RegisterPropertyEditor(TypeInfo(TCastleTransform), TCastleMeshCollider, 'Mesh', |
| 216 |
TMeshColliderMeshPropertyEditor); |
| 217 |
|
| 218 |
RegisterPropertyEditor(TypeInfo(TCastleTransform), TCastleAbstractTwoBodiesJoint, 'Connected', |
| 219 |
TConnectedPropertyEditor); |
| 220 |
|
| 221 |
{ sets } |
| 222 |
RegisterPropertyEditor(TypeInfo(T3DCoords), nil, '', |
| 223 |
T3DCoordsRangeSetPropertyEditor); |
| 224 |
RegisterPropertyEditor(TypeInfo(TColorChannels), nil, '', |
| 225 |
TColorChannelsRangeSetPropertyEditor); |
| 226 |
|
| 227 |
{ animations on TCastleThirdPersonNavigation } |
| 228 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationIdle', |
| 229 |
TThirdPersonAnimationPropertyEditor); |
| 230 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationWalk', |
| 231 |
TThirdPersonAnimationPropertyEditor); |
| 232 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationRun', |
| 233 |
TThirdPersonAnimationPropertyEditor); |
| 234 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationJump', |
| 235 |
TThirdPersonAnimationPropertyEditor); |
| 236 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationRotate', |
| 237 |
TThirdPersonAnimationPropertyEditor); |
| 238 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationCrouch', |
| 239 |
TThirdPersonAnimationPropertyEditor); |
| 240 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationCrouchIdle', |
| 241 |
TThirdPersonAnimationPropertyEditor); |
| 242 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationCrouchRotate', |
| 243 |
TThirdPersonAnimationPropertyEditor); |
| 244 |
RegisterPropertyEditor(TypeInfo(AnsiString), TCastleThirdPersonNavigation, 'AnimationFall', |
| 245 |
TThirdPersonAnimationPropertyEditor); |
| 246 |
|
| 247 |
RegisterComponentEditor(TCastleTransform, TCastleTransformComponentEditor); |
| 248 |
RegisterComponentEditor(TCastleScene, TCastleSceneComponentEditor); |
| 249 |
RegisterComponentEditor(TCastleImageTransform, TCastleImageTransformComponentEditor); |
| 250 |
RegisterComponentEditor(TCastleImageControl, TCastleImageControlComponentEditor); |
| 251 |
RegisterComponentEditor(TCastleTransformDesign, TCastleTransformDesignComponentEditor); |
| 252 |
RegisterComponentEditor(TCastleDesign, TCastleDesignComponentEditor); |
| 253 |
RegisterComponentEditor(TCastleHingeJoint, TCastleJointsComponentEditor); |
| 254 |
RegisterComponentEditor(TCastleRopeJoint, TCastleJointsComponentEditor); |
| 255 |
RegisterComponentEditor(TCastleDistanceJoint, TCastleJointsComponentEditor); |
| 256 |
RegisterComponentEditor(TCastleBallJoint, TCastleJointsComponentEditor); |
| 257 |
RegisterComponentEditor(TCastleGrabJoint, TCastleJointsComponentEditor); |
| 258 |
{$ifdef CASTLE_EXPERIMENTAL_JOINTS} |
| 259 |
RegisterComponentEditor(TCastleFixedJoint, TCastleJointsComponentEditor); |
| 260 |
RegisterComponentEditor(TCastleWorldPlaneDistanceJoint, TCastleJointsComponentEditor); |
| 261 |
RegisterComponentEditor(TCastlePulleyJoint, TCastleJointsComponentEditor); |
| 262 |
RegisterComponentEditor(TCastleSliderJoint, TCastleJointsComponentEditor); |
| 263 |
{$endif CASTLE_EXPERIMENTAL_JOINTS} |
| 264 |
end; |
| 265 |
|
| 266 |
initialization |
| 267 |
{ Add lrs with icons, following |
| 268 |
http://wiki.lazarus.freepascal.org/Lazarus_Packages#Add_a_component_icon } |
| 269 |
{$I icons/castleicons.lrs} |
| 270 |
end. |