| 1 |
{ |
| 2 |
Copyright 2022-2022 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 |
{ Show system information - OpenGL, audio, other reports. } |
| 17 |
unit FormSystemInformation; |
| 18 |
|
| 19 |
{$mode ObjFPC}{$H+} |
| 20 |
|
| 21 |
interface |
| 22 |
|
| 23 |
uses |
| 24 |
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel, ExtCtrls, |
| 25 |
StdCtrls, CastleControl; |
| 26 |
|
| 27 |
type |
| 28 |
TSystemInformationForm = class(TForm) |
| 29 |
ButtonPanel1: TButtonPanel; |
| 30 |
CastleControl1: TCastleControl; |
| 31 |
ListSections: TListBox; |
| 32 |
MemoSysInfo: TMemo; |
| 33 |
Panel1: TPanel; |
| 34 |
Panel2: TPanel; |
| 35 |
SaveDialogText: TSaveDialog; |
| 36 |
procedure CastleControl1Open(Sender: TObject); |
| 37 |
procedure FormHide(Sender: TObject); |
| 38 |
procedure FormShow(Sender: TObject); |
| 39 |
procedure HelpButtonClick(Sender: TObject); |
| 40 |
procedure ListSectionsClick(Sender: TObject); |
| 41 |
private |
| 42 |
type |
| 43 |
TInfoType = (itRendering, itAudio, itOther); |
| 44 |
var |
| 45 |
Info: array [TInfoType] of String; |
| 46 |
procedure SoundEngineOpenClose(Sender: TObject); |
| 47 |
public |
| 48 |
|
| 49 |
end; |
| 50 |
|
| 51 |
var |
| 52 |
SystemInformationForm: TSystemInformationForm; |
| 53 |
|
| 54 |
implementation |
| 55 |
|
| 56 |
{$R *.lfm} |
| 57 |
|
| 58 |
uses CastleGLUtils, CastleSoundEngine, CastleUtils, CastleFilesUtils, |
| 59 |
CastleUriUtils, |
| 60 |
ProjectUtils; |
| 61 |
|
| 62 |
procedure TSystemInformationForm.ListSectionsClick(Sender: TObject); |
| 63 |
var |
| 64 |
Selected: TInfoType; |
| 65 |
begin |
| 66 |
if Between(ListSections.ItemIndex, Ord(Low(TInfoType)), Ord(High(TInfoType))) then |
| 67 |
Selected := TInfoType(ListSections.ItemIndex) |
| 68 |
else |
| 69 |
{ on macOS (Cocoa) user can click anywhere in list to deselect it, |
| 70 |
setting ItemIndex = -1, tolerate it. } |
| 71 |
Selected := Low(TInfoType); |
| 72 |
|
| 73 |
MemoSysInfo.Lines.Text := Info[Selected]; |
| 74 |
end; |
| 75 |
|
| 76 |
procedure TSystemInformationForm.SoundEngineOpenClose(Sender: TObject); |
| 77 |
begin |
| 78 |
{ Update Info[itAudio] when sound engine initializes / deinitializes. } |
| 79 |
Info[itAudio] := SoundEngine.Information; |
| 80 |
end; |
| 81 |
|
| 82 |
procedure TSystemInformationForm.FormShow(Sender: TObject); |
| 83 |
const |
| 84 |
{ Return current widgetset as a string. |
| 85 |
Esp. useful to detect when someone uses non-standard widgetsets that don't support |
| 86 |
OpenGL context sharing. |
| 87 |
See https://wiki.lazarus.freepascal.org/LCL_Defines#General_LCL_defines |
| 88 |
https://wiki.freepascal.org/Widgetset |
| 89 |
} |
| 90 |
SCurrentWidgetset = |
| 91 |
{$if defined(LCLCocoa)} 'Cocoa' |
| 92 |
{$elseif defined(LCLCarbon)} 'Carbon' |
| 93 |
{$elseif defined(LCLGtk2)} 'GTK 2' |
| 94 |
{$elseif defined(LCLGtk3)} 'GTK 3' |
| 95 |
{$elseif defined(LCLQt)} 'Qt 4' |
| 96 |
{$elseif defined(LCLQt5)} 'Qt 5' |
| 97 |
{$elseif defined(LCLWin32)} 'Win32' |
| 98 |
{$else} 'Unknown' |
| 99 |
{$endif}; |
| 100 |
var |
| 101 |
OldApplicationDataOverride: String; |
| 102 |
begin |
| 103 |
OldApplicationDataOverride := ApplicationDataOverride; |
| 104 |
UseEditorApplicationData; |
| 105 |
CastleControl1.Container.DesignUrl := 'castle-data:/demo_animation/view_demo_animation.castle-user-interface'; |
| 106 |
ApplicationDataOverride := OldApplicationDataOverride; |
| 107 |
|
| 108 |
{ Info[itRendering] will be initialized in CastleControl1Open. |
| 109 |
We do not even reset it here, as CastleControl1 may have been already opened |
| 110 |
(when this form was shown previous time) |
| 111 |
so we just may have valid Info[itRendering] already. } |
| 112 |
|
| 113 |
Info[itAudio] := SoundEngine.Information; |
| 114 |
Info[itOther] := |
| 115 |
'Castle Game Engine version: ' + CastleEngineVersion + '.' + NL + |
| 116 |
'Editor compiled with ' + SCompilerDescription + '.' + NL + |
| 117 |
'Editor platform: ' + SPlatformDescription + '.' + NL + |
| 118 |
'Editor widgetset: ' + SCurrentWidgetset + '.' + NL; |
| 119 |
|
| 120 |
SoundEngine.OnOpenClose.Add(@SoundEngineOpenClose); |
| 121 |
|
| 122 |
ListSections.ItemIndex := 0; |
| 123 |
MemoSysInfo.Lines.Text := Info[TInfoType(ListSections.ItemIndex)]; |
| 124 |
end; |
| 125 |
|
| 126 |
procedure TSystemInformationForm.CastleControl1Open(Sender: TObject); |
| 127 |
begin |
| 128 |
// use GLInformationString only once rendering context initialized |
| 129 |
Info[itRendering] := GLInformationString; |
| 130 |
|
| 131 |
if ListSections.ItemIndex = Ord(itRendering) then |
| 132 |
MemoSysInfo.Lines.Text := Info[itRendering]; |
| 133 |
end; |
| 134 |
|
| 135 |
procedure TSystemInformationForm.FormHide(Sender: TObject); |
| 136 |
begin |
| 137 |
CastleControl1.Container.DesignUrl := ''; // unload to stop sound |
| 138 |
|
| 139 |
SoundEngine.OnOpenClose.Remove(@SoundEngineOpenClose); |
| 140 |
end; |
| 141 |
|
| 142 |
procedure TSystemInformationForm.HelpButtonClick(Sender: TObject); |
| 143 |
begin |
| 144 |
if SaveDialogText.Execute then |
| 145 |
begin |
| 146 |
StringToFile(FilenameToUriSafe(SaveDialogText.FileName), |
| 147 |
'Rendering:' + NL + Info[itRendering] + NL + NL + |
| 148 |
'Audio:' + NL + Info[itAudio] + NL + NL + |
| 149 |
'Other:' + NL + Info[itOther]// + NL + NL + |
| 150 |
); |
| 151 |
end; |
| 152 |
end; |
| 153 |
|
| 154 |
end. |
| 155 |
|