| 1 |
{ |
| 2 |
Copyright 2020-2020 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 |
{ Dialog for editing TCastleTranform.ExposeTransforms, used by CastlePropEdits. } |
| 17 |
unit CastleInternalExposeTransformsDialog; |
| 18 |
|
| 19 |
{$I castleconf.inc} |
| 20 |
|
| 21 |
interface |
| 22 |
|
| 23 |
uses |
| 24 |
Generics.Collections, Contnrs, |
| 25 |
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, |
| 26 |
ButtonPanel, StdCtrls, ExtCtrls; |
| 27 |
|
| 28 |
type |
| 29 |
TExposeTransformSelectionItem = class |
| 30 |
Name: String; |
| 31 |
Selected: Boolean; |
| 32 |
ExistsInScene: Boolean; |
| 33 |
end; |
| 34 |
|
| 35 |
TExposeTransformSelection = class(specialize TObjectList<TExposeTransformSelectionItem>) |
| 36 |
{ Find TExposeTransformSelectionItem with given Name, or @nil if not found. } |
| 37 |
function FindName(const S: String): TExposeTransformSelectionItem; |
| 38 |
{ Convert to TStrings. Called is responsible for freeing it. } |
| 39 |
function ToList: TStrings; |
| 40 |
end; |
| 41 |
|
| 42 |
TExposeTransformsDialog = class(TForm) |
| 43 |
ButtonPanel1: TButtonPanel; |
| 44 |
CheckTransforms: TScrollBox; |
| 45 |
Label1: TLabel; |
| 46 |
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); |
| 47 |
private |
| 48 |
Checkboxes: TObjectList; |
| 49 |
public |
| 50 |
Selection: TExposeTransformSelection; |
| 51 |
constructor Create(AOwner: TComponent); override; |
| 52 |
destructor Destroy; override; |
| 53 |
procedure UpdateSelectionUi; |
| 54 |
end; |
| 55 |
|
| 56 |
implementation |
| 57 |
|
| 58 |
uses CastleLclUtils; |
| 59 |
|
| 60 |
{$R *.lfm} |
| 61 |
|
| 62 |
{ TExposeTransformSelection -------------------------------------------------- } |
| 63 |
|
| 64 |
function TExposeTransformSelection.FindName(const S: String): TExposeTransformSelectionItem; |
| 65 |
begin |
| 66 |
for Result in Self do |
| 67 |
if Result.Name = S then |
| 68 |
Exit; |
| 69 |
Result := nil; |
| 70 |
end; |
| 71 |
|
| 72 |
function TExposeTransformSelection.ToList: TStrings; |
| 73 |
var |
| 74 |
I: TExposeTransformSelectionItem; |
| 75 |
begin |
| 76 |
Result := TStringList.Create; |
| 77 |
for I in Self do |
| 78 |
if I.Selected then |
| 79 |
Result.Add(I.Name); |
| 80 |
end; |
| 81 |
|
| 82 |
{ TExposeTransformsDialog ---------------------------------------------------- } |
| 83 |
|
| 84 |
constructor TExposeTransformsDialog.Create(AOwner: TComponent); |
| 85 |
begin |
| 86 |
inherited; |
| 87 |
Selection := TExposeTransformSelection.Create(true); |
| 88 |
Checkboxes := TObjectList.Create(false); |
| 89 |
end; |
| 90 |
|
| 91 |
destructor TExposeTransformsDialog.Destroy; |
| 92 |
begin |
| 93 |
FreeAndNil(Selection); |
| 94 |
FreeAndNil(Checkboxes); |
| 95 |
inherited; |
| 96 |
end; |
| 97 |
|
| 98 |
procedure TExposeTransformsDialog.FormCloseQuery(Sender: TObject; |
| 99 |
var CanClose: boolean); |
| 100 |
var |
| 101 |
I: Integer; |
| 102 |
begin |
| 103 |
if ModalResult = mrOK then |
| 104 |
begin |
| 105 |
Assert(Selection.Count = Checkboxes.Count); |
| 106 |
for I := 0 to Selection.Count - 1 do |
| 107 |
begin |
| 108 |
Selection[I].Selected := TCheckbox(Checkboxes[I]).Checked; |
| 109 |
end; |
| 110 |
end; |
| 111 |
end; |
| 112 |
|
| 113 |
procedure TExposeTransformsDialog.UpdateSelectionUi; |
| 114 |
var |
| 115 |
SelItem: TExposeTransformSelectionItem; |
| 116 |
S: String; |
| 117 |
Checkbox: TCheckBox; |
| 118 |
begin |
| 119 |
Checkboxes.Clear; |
| 120 |
for SelItem in Selection do |
| 121 |
begin |
| 122 |
S := SelItem.Name; |
| 123 |
if not SelItem.ExistsInScene then |
| 124 |
S += ' (not detected in current scene)'; |
| 125 |
Checkbox := TCheckBox.Create(Self); |
| 126 |
Checkbox.Caption := S; |
| 127 |
Checkbox.Checked := SelItem.Selected; |
| 128 |
Checkbox.Parent := CheckTransforms; |
| 129 |
Checkboxes.Add(Checkbox); |
| 130 |
end; |
| 131 |
end; |
| 132 |
|
| 133 |
end. |
| 134 |
|