| 1 |
{%MainUnit x3dnodes.pas} |
| 2 |
{ |
| 3 |
Copyright 2002-2018 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 |
TX3DNodeClassesList = class(TList) |
| 20 |
strict private |
| 21 |
function GetItems(Index: Integer): TX3DNodeClass; |
| 22 |
procedure SetItems(Index: Integer; Value: TX3DNodeClass); |
| 23 |
public |
| 24 |
property Items[Index: Integer]: TX3DNodeClass |
| 25 |
read GetItems write SetItems; default; |
| 26 |
procedure AssignArray( |
| 27 |
const AItemsArray: array of TX3DNodeClass); |
| 28 |
function IndexOf(NodeClass: TX3DNodeClass): Integer; overload; |
| 29 |
{ Equivalent to IndexOf(NodeClass.ClassType), |
| 30 |
taking care of necessary typecasts. } |
| 31 |
function IndexOf(Node: TX3DNode): Integer; overload; |
| 32 |
|
| 33 |
{ Looks for a node class that is ancestor of given Node, |
| 34 |
in other words that satisfies the @code(Node is Items[Result]) condition. |
| 35 |
Contrast this with IndexOf method, which looks only for an exact |
| 36 |
class match. |
| 37 |
|
| 38 |
Returns -1 if not found. } |
| 39 |
function IndexOfAnyAncestor(Node: TX3DNode): Integer; |
| 40 |
|
| 41 |
procedure Add(Value: TX3DNodeClass); |
| 42 |
end; |
| 43 |
|
| 44 |
{$endif read_interface} |
| 45 |
|
| 46 |
{$ifdef read_implementation} |
| 47 |
|
| 48 |
{ TX3DNodeClassesList ------------------------------------------------------- } |
| 49 |
|
| 50 |
function TX3DNodeClassesList.GetItems(Index: Integer): TX3DNodeClass; |
| 51 |
begin |
| 52 |
Result := TX3DNodeClass(inherited Items[Index]); |
| 53 |
end; |
| 54 |
|
| 55 |
procedure TX3DNodeClassesList.SetItems(Index: Integer; Value: TX3DNodeClass); |
| 56 |
begin |
| 57 |
inherited Items[Index] := Pointer(Value); |
| 58 |
end; |
| 59 |
|
| 60 |
procedure TX3DNodeClassesList.AssignArray( |
| 61 |
const AItemsArray: array of TX3DNodeClass); |
| 62 |
var |
| 63 |
I: Integer; |
| 64 |
begin |
| 65 |
Count := High(AItemsArray) + 1; |
| 66 |
for I := 0 to High(AItemsArray) do |
| 67 |
Items[I] := AItemsArray[I]; |
| 68 |
end; |
| 69 |
|
| 70 |
function TX3DNodeClassesList.IndexOf(NodeClass: TX3DNodeClass): Integer; |
| 71 |
begin |
| 72 |
for Result := 0 to Count - 1 do |
| 73 |
if Items[Result] = NodeClass then |
| 74 |
Exit; |
| 75 |
Result := -1; |
| 76 |
end; |
| 77 |
|
| 78 |
function TX3DNodeClassesList.IndexOf(Node: TX3DNode): Integer; |
| 79 |
begin |
| 80 |
Result := IndexOf(TX3DNodeClass(Node.ClassType)); |
| 81 |
end; |
| 82 |
|
| 83 |
function TX3DNodeClassesList.IndexOfAnyAncestor(Node: TX3DNode): Integer; |
| 84 |
begin |
| 85 |
for Result := 0 to Count - 1 do |
| 86 |
if Node is TX3DNodeClass(Items[Result]) then |
| 87 |
Exit; |
| 88 |
Result := -1; |
| 89 |
end; |
| 90 |
|
| 91 |
procedure TX3DNodeClassesList.Add(Value: TX3DNodeClass); |
| 92 |
begin |
| 93 |
inherited Add(Pointer(Value)); |
| 94 |
end; |
| 95 |
|
| 96 |
{$endif read_implementation} |