| 1 |
{ |
| 2 |
Copyright 2022-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 |
{ Lazarus IDE integration with Castle Game Engine. |
| 17 |
|
| 18 |
It's actually compiled-in with castle_components now always, |
| 19 |
though in principle we only need this when we're inside Lazarus IDE |
| 20 |
(at design-time for Lazarus IDE). |
| 21 |
|
| 22 |
This does: |
| 23 |
- make castle-data: work in Lazarus IDE, |
| 24 |
- send CGE warnings to LCL messages window. |
| 25 |
} |
| 26 |
unit CastleInternalLclDesign; |
| 27 |
|
| 28 |
interface |
| 29 |
|
| 30 |
procedure Register; |
| 31 |
|
| 32 |
{ At design-time (when running in Lazarus IDE) make sure to adjust |
| 33 |
ApplicationDataOverride. } |
| 34 |
procedure FixApplicationDataInIDE; |
| 35 |
|
| 36 |
implementation |
| 37 |
|
| 38 |
uses // FPC and LCL units |
| 39 |
SysUtils, Classes, Forms, |
| 40 |
// Lazarus design-time (IDE) units |
| 41 |
LazIDEIntf, IDEMsgIntf, IDEExternToolIntf, |
| 42 |
// CGE units |
| 43 |
CastleUtils, CastleFilesUtils, CastleLclUtils, CastleApplicationProperties; |
| 44 |
|
| 45 |
procedure FixApplicationDataInIDE; |
| 46 |
begin |
| 47 |
{ TODO: This should be somehow registered (in Register) to listen to IDE project change, |
| 48 |
and adjust ApplicationDataOverride at project change. |
| 49 |
|
| 50 |
Doing it now, when DesignUrl seems needed ( |
| 51 |
by dialog box that sets DesignUrl, |
| 52 |
by setting TCastleControl.DesignUrl in deserialization) |
| 53 |
is not a clean way to do this (because we may miss some situations). |
| 54 |
|
| 55 |
Note: We don't check "CastleDesignMode and ..." here now. |
| 56 |
This was preventing FixApplicationDataInIDE from setting path |
| 57 |
when we open the dialog to load DesignUrl for the first time in project |
| 58 |
in Lazarus IDE |
| 59 |
(testcase: open in Lazarus examples/lazarus/multiple_views/ , open form, |
| 60 |
try to set DesignUrl by clicking on "..." near it). |
| 61 |
Our InternalCastleApplicationMode is not yet set at this point. |
| 62 |
} |
| 63 |
if (LazarusIDE <> nil) and |
| 64 |
(LazarusIDE.ActiveProject <> nil) then |
| 65 |
begin |
| 66 |
{ Override ApplicationData interpretation, and castle-data:/xxx URL meaning. } |
| 67 |
ApplicationDataOverride := FilenameToUriSafeUTF8( |
| 68 |
InclPathDelim(LazarusIDE.ActiveProject.Directory) + 'data' + PathDelim); |
| 69 |
end; |
| 70 |
end; |
| 71 |
|
| 72 |
type |
| 73 |
{ Provides integration between Lazarus IDE and CGE that is nice to wrap |
| 74 |
in a class. } |
| 75 |
TCastleLazarusIDEIntegration = class(TComponent) |
| 76 |
strict private |
| 77 |
procedure WarningToLazarusMessages(const Category, S: string); |
| 78 |
public |
| 79 |
constructor Create(AOwner: TComponent); override; |
| 80 |
end; |
| 81 |
|
| 82 |
constructor TCastleLazarusIDEIntegration.Create(AOwner: TComponent); |
| 83 |
begin |
| 84 |
inherited; |
| 85 |
ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}WarningToLazarusMessages); |
| 86 |
end; |
| 87 |
|
| 88 |
procedure TCastleLazarusIDEIntegration.WarningToLazarusMessages(const Category, S: string); |
| 89 |
var |
| 90 |
MessageContent: String; |
| 91 |
begin |
| 92 |
MessageContent := 'Castle Game Engine: '; |
| 93 |
if Category <> '' then |
| 94 |
MessageContent += Category + ': '; |
| 95 |
MessageContent += S; |
| 96 |
AddIDEMessage(mluWarning, MessageContent); |
| 97 |
end; |
| 98 |
|
| 99 |
procedure Register; |
| 100 |
//var |
| 101 |
// LazarusIDEIntegration: TCastleLazarusIDEIntegration; |
| 102 |
begin |
| 103 |
{ If running in Lazarus IDE, show CGE warnings on Lazarus messages list. } |
| 104 |
{LazarusIDEIntegration := }TCastleLazarusIDEIntegration.Create(Application); |
| 105 |
end; |
| 106 |
|
| 107 |
end. |